示例#1
0
 def testEndPoints(self):
   batch_size = 5
   height, width = 224, 224
   num_classes = 1000
   with self.test_session():
     inputs = tf.random_uniform((batch_size, height, width, 3))
     _, end_points = vgg.vgg_16(inputs, num_classes)
     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))
 def construct_graph_for_teacher(self):
     with tf.device(self.device):
         inputs = tf.placeholder(tf.float32, shape=(None, 224, 224, 3))
         _, end_points = slim_vgg.vgg_16(inputs)
         # heatmap tensors
         hm1 = end_points['hm1']
         hm2 = end_points['hm2']
         hm3 = end_points['hm3']
     return inputs, hm1, hm2, hm3
示例#3
0
 def testForward(self):
   batch_size = 1
   height, width = 224, 224
   with self.test_session() as sess:
     inputs = tf.random_uniform((batch_size, height, width, 3))
     logits, _ = vgg.vgg_16(inputs)
     sess.run(tf.global_variables_initializer())
     output = sess.run(logits)
     self.assertTrue(output.any())
示例#4
0
 def testFullyConvolutional(self):
   batch_size = 1
   height, width = 256, 256
   num_classes = 1000
   with self.test_session():
     inputs = tf.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])
示例#5
0
 def testBuild(self):
   batch_size = 5
   height, width = 224, 224
   num_classes = 1000
   with self.test_session():
     inputs = tf.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])
示例#6
0
 def testModelVariables(self):
   batch_size = 5
   height, width = 224, 224
   num_classes = 1000
   with self.test_session():
     inputs = tf.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 slim.get_model_variables()]
     self.assertSetEqual(set(model_variables), set(expected_names))
示例#7
0
 def testEvaluation(self):
   batch_size = 2
   height, width = 224, 224
   num_classes = 1000
   with self.test_session():
     eval_inputs = tf.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 = tf.argmax(logits, 1)
     self.assertListEqual(predictions.get_shape().as_list(), [batch_size])
示例#8
0
 def testTrainEvalWithReuse(self):
   train_batch_size = 2
   eval_batch_size = 1
   train_height, train_width = 224, 224
   eval_height, eval_width = 256, 256
   num_classes = 1000
   with self.test_session():
     train_inputs = tf.random_uniform(
         (train_batch_size, train_height, train_width, 3))
     logits, _ = vgg.vgg_16(train_inputs)
     self.assertListEqual(logits.get_shape().as_list(),
                          [train_batch_size, num_classes])
     tf.get_variable_scope().reuse_variables()
     eval_inputs = tf.random_uniform(
         (eval_batch_size, eval_height, eval_width, 3))
     logits, _ = vgg.vgg_16(eval_inputs, is_training=False,
                            spatial_squeeze=False)
     self.assertListEqual(logits.get_shape().as_list(),
                          [eval_batch_size, 2, 2, num_classes])
     logits = tf.reduce_mean(logits, [1, 2])
     predictions = tf.argmax(logits, 1)
     self.assertEquals(predictions.get_shape().as_list(), [eval_batch_size])
示例#9
0
import numpy as np
import slim_vgg

import resize

#demo input pic
folder = "ImageNet_results/"
output_folder = "ImageNet_results/"
img = "gray_rsz_n01532829_1503.JPEG"
heatmap = 3
sizes = [56, 28, 7]
pic = cv2.imread(folder + img)
print(pic.shape)
# pic = cv2.resize(pic, (224, 224))
inputs = tf.placeholder(tf.float32, shape=(None, 224, 224, 3))
model, end_points = slim_vgg.vgg_16(inputs)
hm = end_points['hm' + str(heatmap)]  # heatmap tensor

saver = tf.train.Saver()

#tf global session
sess = tf.Session()

### TF resize not running GPU, too slow compared to the CPU Pool version
## imgs_224 = tf.image.resize_images(imgs, (224, 224, 3))
#print(imgs_224)

## Original code

res_pic = cv2.resize(pic, (224, 224), interpolation=cv2.INTER_AREA)