本文整理汇总了Python中tensorflow.contrib.slim.python.slim.nets.inception.inception_v3_arg_scope方法的典型用法代码示例。如果您正苦于以下问题:Python inception.inception_v3_arg_scope方法的具体用法?Python inception.inception_v3_arg_scope怎么用?Python inception.inception_v3_arg_scope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.contrib.slim.python.slim.nets.inception
的用法示例。
在下文中一共展示了inception.inception_v3_arg_scope方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_inceptionv3_graph
# 需要导入模块: from tensorflow.contrib.slim.python.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.python.slim.nets.inception import inception_v3_arg_scope [as 别名]
def build_inceptionv3_graph(images, endpoint, is_training, checkpoint,
reuse=False):
"""Builds an InceptionV3 model graph.
Args:
images: A 4-D float32 `Tensor` of batch images.
endpoint: String, name of the InceptionV3 endpoint.
is_training: Boolean, whether or not to build a training or inference graph.
checkpoint: String, path to the pretrained model checkpoint.
reuse: Boolean, whether or not we are reusing the embedder.
Returns:
inception_output: `Tensor` holding the InceptionV3 output.
inception_variables: List of inception variables.
init_fn: Function to initialize the weights (if not reusing, then None).
"""
with slim.arg_scope(inception.inception_v3_arg_scope()):
_, endpoints = inception.inception_v3(
images, num_classes=1001, is_training=is_training)
inception_output = endpoints[endpoint]
inception_variables = slim.get_variables_to_restore()
inception_variables = [
i for i in inception_variables if 'global_step' not in i.name]
if is_training and not reuse:
init_saver = tf.train.Saver(inception_variables)
def init_fn(scaffold, sess):
del scaffold
init_saver.restore(sess, checkpoint)
else:
init_fn = None
return inception_output, inception_variables, init_fn
示例2: main
# 需要导入模块: from tensorflow.contrib.slim.python.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.python.slim.nets.inception import inception_v3_arg_scope [as 别名]
def main(args):
if not os.path.exists(FLAGS.checkpoint):
tf.logging.fatal(
'Checkpoint %s does not exist. Have you download it? See tools/download_data.sh',
FLAGS.checkpoint)
g = tf.Graph()
with g.as_default():
input_image = tf.placeholder(tf.string)
processed_image = PreprocessImage(input_image)
with slim.arg_scope(inception.inception_v3_arg_scope()):
logits, end_points = inception.inception_v3(
processed_image, num_classes=FLAGS.num_classes, is_training=False)
predictions = end_points['multi_predictions'] = tf.nn.sigmoid(
logits, name='multi_predictions')
saver = tf_saver.Saver()
sess = tf.Session()
saver.restore(sess, FLAGS.checkpoint)
# Run the evaluation on the images
for image_path in FLAGS.image_path:
if not os.path.exists(image_path):
tf.logging.fatal('Input image does not exist %s', FLAGS.image_path[0])
img_data = tf.gfile.FastGFile(image_path, "rb").read()
print(image_path)
predictions_eval = np.squeeze(sess.run(predictions,
{input_image: img_data}))
# Print top(n) results
labelmap, label_dict = LoadLabelMaps(FLAGS.num_classes, FLAGS.labelmap, FLAGS.dict)
top_k = predictions_eval.argsort()[-FLAGS.n:][::-1]
for idx in top_k:
mid = labelmap[idx]
display_name = label_dict.get(mid, 'unknown')
score = predictions_eval[idx]
print('{}: {} - {} (score = {:.2f})'.format(idx, mid, display_name, score))
print()
示例3: main
# 需要导入模块: from tensorflow.contrib.slim.python.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.python.slim.nets.inception import inception_v3_arg_scope [as 别名]
def main(args):
if not os.path.exists(FLAGS.checkpoint):
tf.logging.fatal(
'Checkpoint %s does not exist. Have you download it? See tools/download_data.sh',
FLAGS.checkpoint)
g = tf.Graph()
with g.as_default():
input_image = PreprocessImage(FLAGS.image_path[0])
with slim.arg_scope(inception.inception_v3_arg_scope()):
logits, end_points = inception.inception_v3(
input_image, num_classes=FLAGS.num_classes, is_training=False)
bottleneck = end_points['PreLogits']
init_op = tf.group(tf.global_variables_initializer(),
tf.local_variables_initializer(),
tf.tables_initializer())
saver = tf_saver.Saver()
sess = tf.Session()
saver.restore(sess, FLAGS.checkpoint)
# Run the evaluation on the image
bottleneck_eval = np.squeeze(sess.run(bottleneck))
first = True
for val in bottleneck_eval:
if not first:
sys.stdout.write(",")
first = False
sys.stdout.write('{:.3f}'.format(val))
sys.stdout.write('\n')