本文整理汇总了Python中tensorflow.slim方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.slim方法的具体用法?Python tensorflow.slim怎么用?Python tensorflow.slim使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow
的用法示例。
在下文中一共展示了tensorflow.slim方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _checkpoint_var_search
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import slim [as 别名]
def _checkpoint_var_search(self, checkpoint_path):
reader = tf.train.NewCheckpointReader(checkpoint_path)
saved_shapes = reader.get_variable_to_shape_map()
model_names = tf.model_variables() # Used by tf.slim layers
if not len(tf.model_variables()):
model_names = tf.global_variables() # Fallback when slim is not used
model_names = set([v.name.split(':')[0] for v in model_names])
checkpoint_names = set(saved_shapes.keys())
found_names = model_names & checkpoint_names
missing_names = model_names - checkpoint_names
shape_conflicts = set()
restored = []
with tf.variable_scope('', reuse=True):
for name in found_names:
# print(tf.global_variables())
# print(name, name in model_names, name in checkpoint_names)
var = tf.get_variable(name)
var_shape = var.get_shape().as_list()
if var_shape == saved_shapes[name]:
restored.append(var)
else:
shape_conflicts.add(name)
found_names -= shape_conflicts
return (restored, sorted(found_names),
sorted(missing_names), sorted(shape_conflicts))
示例2: main
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import slim [as 别名]
def main(_):
util.check_tensorflow_version()
dataset = ImagenetData(subset=FLAGS.subset)
processor = ProcessorImagenet()
processor.label_offset = FLAGS.label_offset
feed = FeedImagesWithLabels(dataset=dataset, processor=processor)
model_params = {
'num_classes': feed.num_classes_for_network(),
'network': FLAGS.network,
}
if FLAGS.my:
# My variants of Resnet, Inception, and VGG networks
model = ModelMySlim(params=model_params)
else:
# Google's tf.slim models
model = ModelGoogleSlim(params=model_params)
model.check_norm(processor.normalize)
exec_train.train(feed=feed, model=model)
示例3: main
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import slim [as 别名]
def main(_):
util.check_tensorflow_version()
dataset = ImagenetData(subset=FLAGS.subset)
processor = ProcessorImagenet()
processor.label_offset = FLAGS.label_offset
feed = FeedImagesWithLabels(dataset=dataset, processor=processor)
model_params = {
'num_classes': feed.num_classes_for_network(),
'network': FLAGS.network,
}
if FLAGS.my:
# My variants of Resnet, Inception, and VGG networks
model = ModelMySlim(params=model_params)
else:
# Google's tf.slim models
model = ModelGoogleSlim(params=model_params)
model.check_norm(processor.normalize)
exec_eval.evaluate(feed=feed, model=model)
示例4: eval_stitch
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import slim [as 别名]
def eval_stitch(gitapp: controller.GetInputTargetAndPredictedParameters):
g = tf.Graph()
with g.as_default():
controller.setup_stitch(gitapp)
summary_ops = tf.get_collection(tf.GraphKeys.SUMMARIES)
input_summary_op = next(
x for x in summary_ops if 'input_error_panel' in x.name)
target_summary_op = next(
x for x in summary_ops if 'target_error_panel' in x.name)
log_entry_points(g)
slim.evaluation.evaluation_loop(
master=FLAGS.master,
num_evals=0,
checkpoint_dir=train_directory(),
logdir=output_directory(),
# Merge the summaries to keep the graph state in sync.
summary_op=tf.summary.merge([input_summary_op, target_summary_op]),
eval_interval_secs=FLAGS.eval_interval_secs)
示例5: export
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import slim [as 别名]
def export(gitapp: controller.GetInputTargetAndPredictedParameters):
g = tf.Graph()
with g.as_default():
assert FLAGS.metric == METRIC_STITCH
controller.setup_stitch(gitapp)
log_entry_points(g)
signature_map = dict(
[(o.name, o) for o in g.get_operations() if 'entry_point' in o.name])
logging.info('Exporting checkpoint at %s to %s', FLAGS.restore_directory,
FLAGS.export_directory)
slim.export_for_serving(
g,
checkpoint_dir=FLAGS.restore_directory,
export_dir=FLAGS.export_directory,
generic_signature_tensor_map=signature_map)
示例6: test_slim_stacked_conv2d
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import slim [as 别名]
def test_slim_stacked_conv2d(self):
graph = tf.Graph()
with graph.as_default() as g:
inputs = tf.placeholder(tf.float32, shape=[None,16,16,3],
name='test_slim_stacked_conv2d/input')
with slim.arg_scope([slim.conv2d], padding='SAME',
weights_initializer=tf.truncated_normal_initializer(stddev=0.3),
weights_regularizer=slim.l2_regularizer(0.0005)):
net = slim.conv2d(inputs, 2, [5, 5], scope='conv1')
net = slim.conv2d(net, 4, [3, 3], padding='VALID', scope='conv2')
net = slim.conv2d(net, 8, [3, 3], scope='conv3')
output_name = [net.op.name]
self._test_tf_model(graph,
{"test_slim_stacked_conv2d/input:0":[1,16,16,3]},
output_name, delta=1e-2)
示例7: test_slim_convnet
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import slim [as 别名]
def test_slim_convnet(self):
graph = tf.Graph()
with graph.as_default() as g:
inputs = tf.placeholder(tf.float32, shape=[None,8,8,3],
name='test_slim_convnet/input')
with slim.arg_scope([slim.conv2d, slim.fully_connected],
weights_initializer=tf.truncated_normal_initializer(0.0, 0.2),
weights_regularizer=slim.l2_regularizer(0.0005)):
net = slim.conv2d(inputs, 2, [3, 3], scope='conv1')
net = slim.flatten(net, scope='flatten3')
net = slim.fully_connected(net, 6, scope='fc6')
output_name = [net.op.name]
self._test_tf_model(graph,
{"test_slim_convnet/input:0":[1,8,8,3]},
output_name, delta=1e-2)
示例8: test_slim_lenet
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import slim [as 别名]
def test_slim_lenet(self):
graph = tf.Graph()
with graph.as_default() as g:
inputs = tf.placeholder(tf.float32, shape=[None,28,28,1],
name='test_slim_lenet/input')
net = slim.conv2d(inputs, 4, [5,5], scope='conv1')
net = slim.avg_pool2d(net, [2,2], scope='pool1')
net = slim.conv2d(net, 6, [5,5], scope='conv2')
net = slim.max_pool2d(net, [2,2], scope='pool2')
net = slim.flatten(net, scope='flatten3')
net = slim.fully_connected(net, 10, scope='fc4')
net = slim.fully_connected(net, 10, activation_fn=None, scope='fc5')
output_name = [net.op.name]
self._test_tf_model(graph,
{"test_slim_lenet/input:0":[1,28,28,1]},
output_name, delta=1e-2)
示例9: test_slim_dilated_depthwise_conv
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import slim [as 别名]
def test_slim_dilated_depthwise_conv(self):
graph = tf.Graph()
with graph.as_default() as g:
inputs = tf.placeholder(tf.float32, shape=[None,16,16,3],
name='test_slim_separable_conv2d/input')
with slim.arg_scope([slim.separable_conv2d], padding='SAME',
weights_initializer=tf.truncated_normal_initializer(stddev=0.3)):
net = slim.separable_conv2d(inputs,
num_outputs=None,
stride=1,
depth_multiplier=1,
kernel_size=[3, 3],
rate=2,
scope='conv1')
output_name = [net.op.name]
self._test_tf_model(graph,
{"test_slim_separable_conv2d/input:0":[1,16,16,3]},
output_name, delta=1e-2)
示例10: test_custom_tile
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import slim [as 别名]
def test_custom_tile(self):
graph = tf.Graph()
with graph.as_default() as g:
inputs = tf.placeholder(tf.float32, shape=[None, 8], name='input')
with slim.arg_scope([slim.fully_connected],
weights_initializer=tf.truncated_normal_initializer(0.0, 0.2),
weights_regularizer=slim.l2_regularizer(0.0005)):
y = slim.fully_connected(inputs, 10, scope='fc')
y = slim.unit_norm(y, dim=1)
output_name = [y.op.name]
coreml_model = self._test_tf_model(graph,
{"input:0": [1, 8]},
output_name,
check_numerical_accuracy=False,
add_custom_layers=True)
spec = coreml_model.get_spec()
layers = spec.neuralNetwork.layers
self.assertIsNotNone(layers[9].custom)
self.assertEqual('Tile', layers[9].custom.className)
示例11: _checkpoint_var_search
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import slim [as 别名]
def _checkpoint_var_search(self, checkpoint_path):
reader = tf.train.NewCheckpointReader(checkpoint_path)
saved_shapes = reader.get_variable_to_shape_map()
model_names = tf.model_variables() # Used by tf.slim layers
if not len(tf.model_variables()):
model_names = tf.global_variables() # Fallback when slim is not used
model_names = set([v.name.split(':')[0] for v in model_names])
checkpoint_names = set(saved_shapes.keys())
found_names = model_names & checkpoint_names
missing_names = model_names - checkpoint_names
shape_conflicts = set()
restored = []
with tf.variable_scope('', reuse=True):
for name in found_names:
var = tf.get_variable(name)
var_shape = var.get_shape().as_list()
if var_shape == saved_shapes[name]:
restored.append(var)
else:
shape_conflicts.add(name)
found_names -= shape_conflicts
return (restored, sorted(found_names),
sorted(missing_names), sorted(shape_conflicts))
示例12: main
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import slim [as 别名]
def main(_):
util.check_tensorflow_version()
dataset = ExampleData(subset='')
processor = ProcessorImagenet()
processor.output_offset = FLAGS.output_offset
feed = FeedImagesWithLabels(dataset=dataset, processor=processor)
model_params = {
'num_classes': feed.num_classes_for_network(),
'network': FLAGS.network,
}
if FLAGS.my:
# My variants of Resnet, Inception, and VGG networks
model = ModelMySlim(params=model_params)
else:
# Google's tf.slim models
model = ModelGoogleSlim(params=model_params)
model.check_norm(processor.normalize)
output, num_entries = exec_predict.predict(feed, model)
output_columns = ['Img']
if FLAGS.output_prob:
# Dump class probabilities to CSV file.
class_labels = []
for c in range(dataset.num_classes()):
class_labels.append("c%s" % c)
output_columns += class_labels
output = np.vstack([np.column_stack([o[1], o[0]]) for o in output])
else:
# Dump class index to CSV file
output_columns += ['Class']
output = np.vstack([np.column_stack([o[1], np.argmax(o[0], axis=1)]) for o in output])
df = pd.DataFrame(output, columns=output_columns)
df.Img = df.Img.apply(lambda x: os.path.basename(x.decode()))
df.to_csv('./output.csv', index=False)
示例13: _build
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import slim [as 别名]
def _build(self, inputs, is_training=False):
inputs = self.preprocess(inputs)
with slim.arg_scope(self.arg_scope):
net, end_points = self.network(is_training=is_training)(inputs)
return {
'net': net,
'end_points': end_points,
}
示例14: setup_metrics
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import slim [as 别名]
def setup_metrics( inputs, model, cfg ):
# predictions = model[ 'model' ].
# Choose the metrics to compute:
# names_to_values, names_to_updates = slim.metrics.aggregate_metric_map( {} )
return {}, {}
示例15: eval_loss
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import slim [as 别名]
def eval_loss(gitapp: controller.GetInputTargetAndPredictedParameters):
g = tf.Graph()
with g.as_default():
total_loss_op, input_loss_lts, target_loss_lts = total_loss(gitapp)
metric_names = ['total_loss']
metric_values = [total_loss_op]
for name, loss_lt in dict(input_loss_lts, **target_loss_lts).items():
metric_names.append(name)
metric_values.append(loss_lt.tensor)
metric_names = ['metric/' + n for n in metric_names]
metric_values = [metrics.streaming_mean(v) for v in metric_values]
names_to_values, names_to_updates = metrics.aggregate_metric_map(
dict(zip(metric_names, metric_values)))
for name, value in names_to_values.iteritems():
slim.summaries.add_scalar_summary(value, name, print_summary=True)
log_entry_points(g)
num_batches = FLAGS.metric_num_examples // gitapp.bp.size
slim.evaluation.evaluation_loop(
master=FLAGS.master,
checkpoint_dir=train_directory(),
logdir=output_directory(),
num_evals=num_batches,
eval_op=names_to_updates.values(),
eval_interval_secs=FLAGS.eval_interval_secs)