本文整理汇总了Python中tensorflow.contrib.slim.python.slim.nets.vgg.vgg_16方法的典型用法代码示例。如果您正苦于以下问题:Python vgg.vgg_16方法的具体用法?Python vgg.vgg_16怎么用?Python vgg.vgg_16使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.contrib.slim.python.slim.nets.vgg
的用法示例。
在下文中一共展示了vgg.vgg_16方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testEndPoints
# 需要导入模块: from tensorflow.contrib.slim.python.slim.nets import vgg [as 别名]
# 或者: from tensorflow.contrib.slim.python.slim.nets.vgg import vgg_16 [as 别名]
def testEndPoints(self):
batch_size = 5
height, width = 224, 224
num_classes = 1000
for is_training in [True, False]:
with ops.Graph().as_default():
inputs = random_ops.random_uniform((batch_size, height, width, 3))
_, end_points = vgg.vgg_16(inputs, num_classes, is_training=is_training)
expected_names = [
'vgg_16/conv1/conv1_1', 'vgg_16/conv1/conv1_2', 'vgg_16/pool1',
'vgg_16/conv2/conv2_1', 'vgg_16/conv2/conv2_2', 'vgg_16/pool2',
'vgg_16/conv3/conv3_1', 'vgg_16/conv3/conv3_2',
'vgg_16/conv3/conv3_3', 'vgg_16/pool3', 'vgg_16/conv4/conv4_1',
'vgg_16/conv4/conv4_2', 'vgg_16/conv4/conv4_3', 'vgg_16/pool4',
'vgg_16/conv5/conv5_1', 'vgg_16/conv5/conv5_2',
'vgg_16/conv5/conv5_3', 'vgg_16/pool5', 'vgg_16/fc6', 'vgg_16/fc7',
'vgg_16/fc8'
]
self.assertSetEqual(set(end_points.keys()), set(expected_names))
示例2: testBuild
# 需要导入模块: from tensorflow.contrib.slim.python.slim.nets import vgg [as 别名]
# 或者: from tensorflow.contrib.slim.python.slim.nets.vgg import vgg_16 [as 别名]
def testBuild(self):
batch_size = 5
height, width = 224, 224
num_classes = 1000
with self.test_session():
inputs = random_ops.random_uniform((batch_size, height, width, 3))
logits, _ = vgg.vgg_16(inputs, num_classes)
self.assertEquals(logits.op.name, 'vgg_16/fc8/squeezed')
self.assertListEqual(logits.get_shape().as_list(),
[batch_size, num_classes])
示例3: testFullyConvolutional
# 需要导入模块: from tensorflow.contrib.slim.python.slim.nets import vgg [as 别名]
# 或者: from tensorflow.contrib.slim.python.slim.nets.vgg import vgg_16 [as 别名]
def testFullyConvolutional(self):
batch_size = 1
height, width = 256, 256
num_classes = 1000
with self.test_session():
inputs = random_ops.random_uniform((batch_size, height, width, 3))
logits, _ = vgg.vgg_16(inputs, num_classes, spatial_squeeze=False)
self.assertEquals(logits.op.name, 'vgg_16/fc8/BiasAdd')
self.assertListEqual(logits.get_shape().as_list(),
[batch_size, 2, 2, num_classes])
示例4: testEvaluation
# 需要导入模块: from tensorflow.contrib.slim.python.slim.nets import vgg [as 别名]
# 或者: from tensorflow.contrib.slim.python.slim.nets.vgg import vgg_16 [as 别名]
def testEvaluation(self):
batch_size = 2
height, width = 224, 224
num_classes = 1000
with self.test_session():
eval_inputs = random_ops.random_uniform((batch_size, height, width, 3))
logits, _ = vgg.vgg_16(eval_inputs, is_training=False)
self.assertListEqual(logits.get_shape().as_list(),
[batch_size, num_classes])
predictions = math_ops.argmax(logits, 1)
self.assertListEqual(predictions.get_shape().as_list(), [batch_size])
示例5: testForward
# 需要导入模块: from tensorflow.contrib.slim.python.slim.nets import vgg [as 别名]
# 或者: from tensorflow.contrib.slim.python.slim.nets.vgg import vgg_16 [as 别名]
def testForward(self):
batch_size = 1
height, width = 224, 224
with self.test_session() as sess:
inputs = random_ops.random_uniform((batch_size, height, width, 3))
logits, _ = vgg.vgg_16(inputs)
sess.run(variables.global_variables_initializer())
output = sess.run(logits)
self.assertTrue(output.any())
示例6: network_vgg_16
# 需要导入模块: from tensorflow.contrib.slim.python.slim.nets import vgg [as 别名]
# 或者: from tensorflow.contrib.slim.python.slim.nets.vgg import vgg_16 [as 别名]
def network_vgg_16():
input_shape = [1, 224, 224, 3]
input_ = tf.placeholder(dtype=tf.float32, name='input', shape=input_shape)
net, _end_points = vgg_16(input_, num_classes=1000, is_training=False)
return net
示例7: testModelVariables
# 需要导入模块: from tensorflow.contrib.slim.python.slim.nets import vgg [as 别名]
# 或者: from tensorflow.contrib.slim.python.slim.nets.vgg import vgg_16 [as 别名]
def testModelVariables(self):
batch_size = 5
height, width = 224, 224
num_classes = 1000
with self.test_session():
inputs = random_ops.random_uniform((batch_size, height, width, 3))
vgg.vgg_16(inputs, num_classes)
expected_names = [
'vgg_16/conv1/conv1_1/weights',
'vgg_16/conv1/conv1_1/biases',
'vgg_16/conv1/conv1_2/weights',
'vgg_16/conv1/conv1_2/biases',
'vgg_16/conv2/conv2_1/weights',
'vgg_16/conv2/conv2_1/biases',
'vgg_16/conv2/conv2_2/weights',
'vgg_16/conv2/conv2_2/biases',
'vgg_16/conv3/conv3_1/weights',
'vgg_16/conv3/conv3_1/biases',
'vgg_16/conv3/conv3_2/weights',
'vgg_16/conv3/conv3_2/biases',
'vgg_16/conv3/conv3_3/weights',
'vgg_16/conv3/conv3_3/biases',
'vgg_16/conv4/conv4_1/weights',
'vgg_16/conv4/conv4_1/biases',
'vgg_16/conv4/conv4_2/weights',
'vgg_16/conv4/conv4_2/biases',
'vgg_16/conv4/conv4_3/weights',
'vgg_16/conv4/conv4_3/biases',
'vgg_16/conv5/conv5_1/weights',
'vgg_16/conv5/conv5_1/biases',
'vgg_16/conv5/conv5_2/weights',
'vgg_16/conv5/conv5_2/biases',
'vgg_16/conv5/conv5_3/weights',
'vgg_16/conv5/conv5_3/biases',
'vgg_16/fc6/weights',
'vgg_16/fc6/biases',
'vgg_16/fc7/weights',
'vgg_16/fc7/biases',
'vgg_16/fc8/weights',
'vgg_16/fc8/biases',
]
model_variables = [v.op.name for v in variables_lib.get_model_variables()]
self.assertSetEqual(set(model_variables), set(expected_names))
示例8: encoder_vgg
# 需要导入模块: from tensorflow.contrib.slim.python.slim.nets import vgg [as 别名]
# 或者: from tensorflow.contrib.slim.python.slim.nets.vgg import vgg_16 [as 别名]
def encoder_vgg(x, enc_final_size, reuse=False, scope_prefix='', hparams=None,
is_training=True):
"""VGG network to use as encoder without the top few layers.
Can be pretrained.
Args:
x: The image to encode. In the range 0 to 1.
enc_final_size: The desired size of the encoding.
reuse: To reuse in variable scope or not.
scope_prefix: The prefix before the scope name.
hparams: The python hparams.
is_training: boolean value indicating if training is happening.
Returns:
The generated image.
"""
with tf.variable_scope(scope_prefix + 'encoder', reuse=reuse):
# Preprocess input
x *= 256
x = x - COLOR_NORMALIZATION_VECTOR
with arg_scope(vgg.vgg_arg_scope()):
# Padding because vgg_16 accepts images of size at least VGG_IMAGE_SIZE.
x = tf.pad(x, [[0, 0], [0, VGG_IMAGE_SIZE - IMG_WIDTH],
[0, VGG_IMAGE_SIZE - IMG_HEIGHT], [0, 0]])
_, end_points = vgg.vgg_16(
x,
num_classes=enc_final_size,
is_training=is_training)
pool5_key = [key for key in end_points.keys() if 'pool5' in key]
assert len(pool5_key) == 1
enc = end_points[pool5_key[0]]
# Undoing padding.
enc = tf.slice(enc, [0, 0, 0, 0], [-1, 2, 2, -1])
enc_shape = enc.get_shape().as_list()
enc_shape[0] = -1
enc_size = enc_shape[1] * enc_shape[2] * enc_shape[3]
enc_flat = tf.reshape(enc, (-1, enc_size))
enc_flat = tf.nn.dropout(enc_flat, hparams.enc_keep_prob)
enc_flat = tf.layers.dense(
enc_flat,
enc_final_size,
kernel_initializer=tf.truncated_normal_initializer(stddev=1e-4,))
if hparams.enc_pred_use_l2norm:
enc_flat = tf.nn.l2_normalize(enc_flat, 1)
return enc_flat