本文整理汇总了Python中tensorflow.contrib.slim.nets.inception.inception_v3方法的典型用法代码示例。如果您正苦于以下问题:Python inception.inception_v3方法的具体用法?Python inception.inception_v3怎么用?Python inception.inception_v3使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.contrib.slim.nets.inception
的用法示例。
在下文中一共展示了inception.inception_v3方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [as 别名]
def __call__(self, x_input, return_logits=False):
"""Constructs model and return probabilities for given input."""
reuse = True if self.built else None
with slim.arg_scope(inception.inception_v3_arg_scope()):
# Inception preprocessing uses [-1, 1]-scaled input.
x_input = x_input * 2.0 - 1.0
_, end_points = inception.inception_v3(
x_input, num_classes=self.nb_classes, is_training=False,
reuse=reuse)
self.built = True
self.logits = end_points['Logits']
# Strip off the extra reshape op at the output
self.probs = end_points['Predictions'].op.inputs[0]
if return_logits:
return self.logits
else:
return self.probs
示例2: create_model
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [as 别名]
def create_model(x, reuse=None):
"""Create model graph.
Args:
x: input images
reuse: reuse parameter which will be passed to underlying variable scopes.
Should be None first call and True every subsequent call.
Returns:
(logits, end_points) - tuple of model logits and enpoints
Raises:
ValueError: if model type specified by --model_name flag is invalid.
"""
if FLAGS.model_name == 'inception_v3':
with slim.arg_scope(inception.inception_v3_arg_scope()):
return inception.inception_v3(
x, num_classes=NUM_CLASSES, is_training=False, reuse=reuse)
elif FLAGS.model_name == 'inception_resnet_v2':
with slim.arg_scope(inception_resnet_v2.inception_resnet_v2_arg_scope()):
return inception_resnet_v2.inception_resnet_v2(
x, num_classes=NUM_CLASSES, is_training=False, reuse=reuse)
else:
raise ValueError('Invalid model name: %s' % (FLAGS.model_name))
示例3: testBuildEndPoints
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [as 别名]
def testBuildEndPoints(self):
batch_size = 5
height, width = 299, 299
num_classes = 1000
inputs = tf.random_uniform((batch_size, height, width, 3))
_, end_points = inception.inception_v3(inputs, num_classes)
self.assertTrue('Logits' in end_points)
logits = end_points['Logits']
self.assertListEqual(logits.get_shape().as_list(),
[batch_size, num_classes])
self.assertTrue('AuxLogits' in end_points)
aux_logits = end_points['AuxLogits']
self.assertListEqual(aux_logits.get_shape().as_list(),
[batch_size, num_classes])
self.assertTrue('Mixed_7c' in end_points)
pre_pool = end_points['Mixed_7c']
self.assertListEqual(pre_pool.get_shape().as_list(),
[batch_size, 8, 8, 2048])
self.assertTrue('PreLogits' in end_points)
pre_logits = end_points['PreLogits']
self.assertListEqual(pre_logits.get_shape().as_list(),
[batch_size, 1, 1, 2048])
示例4: testBuildEndPointsWithDepthMultiplierLessThanOne
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [as 别名]
def testBuildEndPointsWithDepthMultiplierLessThanOne(self):
batch_size = 5
height, width = 299, 299
num_classes = 1000
inputs = tf.random_uniform((batch_size, height, width, 3))
_, end_points = inception.inception_v3(inputs, num_classes)
endpoint_keys = [key for key in end_points.keys()
if key.startswith('Mixed') or key.startswith('Conv')]
_, end_points_with_multiplier = inception.inception_v3(
inputs, num_classes, scope='depth_multiplied_net',
depth_multiplier=0.5)
for key in endpoint_keys:
original_depth = end_points[key].get_shape().as_list()[3]
new_depth = end_points_with_multiplier[key].get_shape().as_list()[3]
self.assertEqual(0.5 * original_depth, new_depth)
示例5: testBuildEndPointsWithDepthMultiplierGreaterThanOne
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [as 别名]
def testBuildEndPointsWithDepthMultiplierGreaterThanOne(self):
batch_size = 5
height, width = 299, 299
num_classes = 1000
inputs = tf.random_uniform((batch_size, height, width, 3))
_, end_points = inception.inception_v3(inputs, num_classes)
endpoint_keys = [key for key in end_points.keys()
if key.startswith('Mixed') or key.startswith('Conv')]
_, end_points_with_multiplier = inception.inception_v3(
inputs, num_classes, scope='depth_multiplied_net',
depth_multiplier=2.0)
for key in endpoint_keys:
original_depth = end_points[key].get_shape().as_list()[3]
new_depth = end_points_with_multiplier[key].get_shape().as_list()[3]
self.assertEqual(2.0 * original_depth, new_depth)
示例6: testUnknownImageShape
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [as 别名]
def testUnknownImageShape(self):
tf.reset_default_graph()
batch_size = 2
height, width = 299, 299
num_classes = 1000
input_np = np.random.uniform(0, 1, (batch_size, height, width, 3))
with self.test_session() as sess:
inputs = tf.placeholder(tf.float32, shape=(batch_size, None, None, 3))
logits, end_points = inception.inception_v3(inputs, num_classes)
self.assertListEqual(logits.get_shape().as_list(),
[batch_size, num_classes])
pre_pool = end_points['Mixed_7c']
feed_dict = {inputs: input_np}
tf.global_variables_initializer().run()
pre_pool_out = sess.run(pre_pool, feed_dict=feed_dict)
self.assertListEqual(list(pre_pool_out.shape), [batch_size, 8, 8, 2048])
示例7: testUnknownBatchSize
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [as 别名]
def testUnknownBatchSize(self):
batch_size = 1
height, width = 299, 299
num_classes = 1000
inputs = tf.placeholder(tf.float32, (None, height, width, 3))
logits, _ = inception.inception_v3(inputs, num_classes)
self.assertTrue(logits.op.name.startswith('InceptionV3/Logits'))
self.assertListEqual(logits.get_shape().as_list(),
[None, num_classes])
images = tf.random_uniform((batch_size, height, width, 3))
with self.test_session() as sess:
sess.run(tf.global_variables_initializer())
output = sess.run(logits, {inputs: images.eval()})
self.assertEquals(output.shape, (batch_size, num_classes))
示例8: testTrainEvalWithReuse
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [as 别名]
def testTrainEvalWithReuse(self):
train_batch_size = 5
eval_batch_size = 2
height, width = 150, 150
num_classes = 1000
train_inputs = tf.random_uniform((train_batch_size, height, width, 3))
inception.inception_v3(train_inputs, num_classes)
eval_inputs = tf.random_uniform((eval_batch_size, height, width, 3))
logits, _ = inception.inception_v3(eval_inputs, num_classes,
is_training=False, reuse=True)
predictions = tf.argmax(logits, 1)
with self.test_session() as sess:
sess.run(tf.global_variables_initializer())
output = sess.run(predictions)
self.assertEquals(output.shape, (eval_batch_size,))
示例9: __call__
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [as 别名]
def __call__(self, x_input):
"""Constructs model and return probabilities for given input."""
reuse = True if self.built else None
with slim.arg_scope(inception.inception_v3_arg_scope()):
_, end_points = inception.inception_v3(
x_input, num_classes=self.num_classes, is_training=False,
reuse=reuse)
self.built = True
output = end_points['Predictions']
# Strip off the extra reshape op at the output
probs = output.op.inputs[0]
return probs
示例10: main
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [as 别名]
def main(_):
batch_shape = [FLAGS.batch_size, FLAGS.image_height, FLAGS.image_width, 3]
num_classes = 1001
tf.logging.set_verbosity(tf.logging.INFO)
with tf.Graph().as_default():
# Prepare graph
x_input = tf.placeholder(tf.float32, shape=batch_shape)
with slim.arg_scope(inception.inception_v3_arg_scope()):
_, end_points = inception.inception_v3(
x_input, num_classes=num_classes, is_training=False)
predicted_labels = tf.argmax(end_points['Predictions'], 1)
# Run computation
saver = tf.train.Saver(slim.get_model_variables())
session_creator = tf.train.ChiefSessionCreator(
scaffold=tf.train.Scaffold(saver=saver),
checkpoint_filename_with_path=FLAGS.checkpoint_path,
master=FLAGS.master)
with tf.train.MonitoredSession(session_creator=session_creator) as sess:
with tf.gfile.Open(FLAGS.output_file, 'w') as out_file:
for filenames, images in load_images(FLAGS.input_dir, batch_shape):
labels = sess.run(predicted_labels, feed_dict={x_input: images})
for filename, label in zip(filenames, labels):
out_file.write('{0},{1}\n'.format(filename, label))
示例11: inception
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [as 别名]
def inception(x_input):
'''
Builds the inception network model,
loads its weights from FLAGS.checkpoint_path,
and returns the softmax activations tensor.
'''
from tensorflow.contrib.slim.nets import inception as inception_tf
slim = tf.contrib.slim
with slim.arg_scope(inception_tf.inception_v3_arg_scope()):
_, end_points = inception_tf.inception_v3(x_input, \
num_classes=FLAGS.num_classes, \
is_training=False)
return end_points['Logits']
示例12: testBuildClassificationNetwork
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [as 别名]
def testBuildClassificationNetwork(self):
batch_size = 5
height, width = 299, 299
num_classes = 1000
inputs = tf.random_uniform((batch_size, height, width, 3))
logits, end_points = inception.inception_v3(inputs, num_classes)
self.assertTrue(logits.op.name.startswith('InceptionV3/Logits'))
self.assertListEqual(logits.get_shape().as_list(),
[batch_size, num_classes])
self.assertTrue('Predictions' in end_points)
self.assertListEqual(end_points['Predictions'].get_shape().as_list(),
[batch_size, num_classes])
示例13: testRaiseValueErrorWithInvalidDepthMultiplier
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [as 别名]
def testRaiseValueErrorWithInvalidDepthMultiplier(self):
batch_size = 5
height, width = 299, 299
num_classes = 1000
inputs = tf.random_uniform((batch_size, height, width, 3))
with self.assertRaises(ValueError):
_ = inception.inception_v3(inputs, num_classes, depth_multiplier=-0.1)
with self.assertRaises(ValueError):
_ = inception.inception_v3(inputs, num_classes, depth_multiplier=0.0)
示例14: testEvaluation
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [as 别名]
def testEvaluation(self):
batch_size = 2
height, width = 299, 299
num_classes = 1000
eval_inputs = tf.random_uniform((batch_size, height, width, 3))
logits, _ = inception.inception_v3(eval_inputs, num_classes,
is_training=False)
predictions = tf.argmax(logits, 1)
with self.test_session() as sess:
sess.run(tf.global_variables_initializer())
output = sess.run(predictions)
self.assertEquals(output.shape, (batch_size,))
示例15: testLogitsNotSqueezed
# 需要导入模块: from tensorflow.contrib.slim.nets import inception [as 别名]
# 或者: from tensorflow.contrib.slim.nets.inception import inception_v3 [as 别名]
def testLogitsNotSqueezed(self):
num_classes = 25
images = tf.random_uniform([1, 299, 299, 3])
logits, _ = inception.inception_v3(images,
num_classes=num_classes,
spatial_squeeze=False)
with self.test_session() as sess:
tf.global_variables_initializer().run()
logits_out = sess.run(logits)
self.assertListEqual(list(logits_out.shape), [1, 1, 1, num_classes])