def testModelVariables(self):
   batch_size = 5
   height, width = 231, 231
   num_classes = 1000
   with self.test_session():
     inputs = tf.random_uniform((batch_size, height, width, 3))
     overfeat.overfeat(inputs, num_classes)
     expected_names = ['overfeat/conv1/weights',
                       'overfeat/conv1/biases',
                       'overfeat/conv2/weights',
                       'overfeat/conv2/biases',
                       'overfeat/conv3/weights',
                       'overfeat/conv3/biases',
                       'overfeat/conv4/weights',
                       'overfeat/conv4/biases',
                       'overfeat/conv5/weights',
                       'overfeat/conv5/biases',
                       'overfeat/fc6/weights',
                       'overfeat/fc6/biases',
                       'overfeat/fc7/weights',
                       'overfeat/fc7/biases',
                       'overfeat/fc8/weights',
                       'overfeat/fc8/biases',
                      ]
     model_variables = [v.op.name for v in slim.get_model_variables()]
     self.assertSetEqual(set(model_variables), set(expected_names))
Ejemplo n.º 2
0
 def testModelVariables(self):
   batch_size = 5
   height, width = 231, 231
   num_classes = 1000
   with self.test_session():
     inputs = tf.random.uniform((batch_size, height, width, 3))
     overfeat.overfeat(inputs, num_classes)
     expected_names = ['overfeat/conv1/weights',
                       'overfeat/conv1/biases',
                       'overfeat/conv2/weights',
                       'overfeat/conv2/biases',
                       'overfeat/conv3/weights',
                       'overfeat/conv3/biases',
                       'overfeat/conv4/weights',
                       'overfeat/conv4/biases',
                       'overfeat/conv5/weights',
                       'overfeat/conv5/biases',
                       'overfeat/fc6/weights',
                       'overfeat/fc6/biases',
                       'overfeat/fc7/weights',
                       'overfeat/fc7/biases',
                       'overfeat/fc8/weights',
                       'overfeat/fc8/biases',
                      ]
     model_variables = [v.op.name for v in slim.get_model_variables()]
     self.assertSetEqual(set(model_variables), set(expected_names))
 def testForward(self):
   batch_size = 1
   height, width = 231, 231
   with self.test_session() as sess:
     inputs = tf.random_uniform((batch_size, height, width, 3))
     logits, _ = overfeat.overfeat(inputs)
     sess.run(tf.global_variables_initializer())
     output = sess.run(logits)
     self.assertTrue(output.any())
Ejemplo n.º 4
0
 def testForward(self):
   batch_size = 1
   height, width = 231, 231
   with self.test_session() as sess:
     inputs = tf.random.uniform((batch_size, height, width, 3))
     logits, _ = overfeat.overfeat(inputs)
     sess.run(tf.global_variables_initializer())
     output = sess.run(logits)
     self.assertTrue(output.any())
Ejemplo n.º 5
0
 def testFullyConvolutional(self):
   batch_size = 1
   height, width = 281, 281
   num_classes = 1000
   with self.test_session():
     inputs = tf.random.uniform((batch_size, height, width, 3))
     logits, _ = overfeat.overfeat(inputs, num_classes, spatial_squeeze=False)
     self.assertEquals(logits.op.name, 'overfeat/fc8/BiasAdd')
     self.assertListEqual(logits.get_shape().as_list(),
                          [batch_size, 2, 2, num_classes])
 def testBuild(self):
   batch_size = 5
   height, width = 231, 231
   num_classes = 1000
   with self.test_session():
     inputs = tf.random_uniform((batch_size, height, width, 3))
     logits, _ = overfeat.overfeat(inputs, num_classes)
     self.assertEquals(logits.op.name, 'overfeat/fc8/squeezed')
     self.assertListEqual(logits.get_shape().as_list(),
                          [batch_size, num_classes])
 def testFullyConvolutional(self):
   batch_size = 1
   height, width = 281, 281
   num_classes = 1000
   with self.test_session():
     inputs = tf.random_uniform((batch_size, height, width, 3))
     logits, _ = overfeat.overfeat(inputs, num_classes, spatial_squeeze=False)
     self.assertEquals(logits.op.name, 'overfeat/fc8/BiasAdd')
     self.assertListEqual(logits.get_shape().as_list(),
                          [batch_size, 2, 2, num_classes])
Ejemplo n.º 8
0
 def testBuild(self):
   batch_size = 5
   height, width = 231, 231
   num_classes = 1000
   with self.test_session():
     inputs = tf.random.uniform((batch_size, height, width, 3))
     logits, _ = overfeat.overfeat(inputs, num_classes)
     self.assertEquals(logits.op.name, 'overfeat/fc8/squeezed')
     self.assertListEqual(logits.get_shape().as_list(),
                          [batch_size, num_classes])
Ejemplo n.º 9
0
 def testEvaluation(self):
   batch_size = 2
   height, width = 231, 231
   num_classes = 1000
   with self.test_session():
     eval_inputs = tf.random.uniform((batch_size, height, width, 3))
     logits, _ = overfeat.overfeat(eval_inputs, is_training=False)
     self.assertListEqual(logits.get_shape().as_list(),
                          [batch_size, num_classes])
     predictions = tf.argmax(input=logits, axis=1)
     self.assertListEqual(predictions.get_shape().as_list(), [batch_size])
 def testEvaluation(self):
   batch_size = 2
   height, width = 231, 231
   num_classes = 1000
   with self.test_session():
     eval_inputs = tf.random_uniform((batch_size, height, width, 3))
     logits, _ = overfeat.overfeat(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])
 def testTrainEvalWithReuse(self):
   train_batch_size = 2
   eval_batch_size = 1
   train_height, train_width = 231, 231
   eval_height, eval_width = 281, 281
   num_classes = 1000
   with self.test_session():
     train_inputs = tf.random_uniform(
         (train_batch_size, train_height, train_width, 3))
     logits, _ = overfeat.overfeat(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, _ = overfeat.overfeat(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])
Ejemplo n.º 12
0
 def testGlobalPool(self):
     batch_size = 1
     height, width = 281, 281
     num_classes = 1000
     with self.test_session():
         inputs = tf.random_uniform((batch_size, height, width, 3))
         logits, _ = overfeat.overfeat(inputs,
                                       num_classes,
                                       spatial_squeeze=False,
                                       global_pool=True)
         self.assertEqual(logits.op.name, 'overfeat/fc8/BiasAdd')
         self.assertListEqual(logits.get_shape().as_list(),
                              [batch_size, 1, 1, num_classes])
Ejemplo n.º 13
0
 def testTrainEvalWithReuse(self):
   train_batch_size = 2
   eval_batch_size = 1
   train_height, train_width = 231, 231
   eval_height, eval_width = 281, 281
   num_classes = 1000
   with self.test_session():
     train_inputs = tf.random.uniform(
         (train_batch_size, train_height, train_width, 3))
     logits, _ = overfeat.overfeat(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, _ = overfeat.overfeat(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(input_tensor=logits, axis=[1, 2])
     predictions = tf.argmax(input=logits, axis=1)
     self.assertEquals(predictions.get_shape().as_list(), [eval_batch_size])
Ejemplo n.º 14
0
 def testEndPoints(self):
     batch_size = 5
     height, width = 231, 231
     num_classes = 1000
     with self.test_session():
         inputs = tf.random_uniform((batch_size, height, width, 3))
         _, end_points = overfeat.overfeat(inputs, num_classes)
         expected_names = [
             'overfeat/conv1', 'overfeat/pool1', 'overfeat/conv2',
             'overfeat/pool2', 'overfeat/conv3', 'overfeat/conv4',
             'overfeat/conv5', 'overfeat/pool5', 'overfeat/fc6',
             'overfeat/fc7', 'overfeat/fc8'
         ]
         self.assertSetEqual(set(end_points.keys()), set(expected_names))
Ejemplo n.º 15
0
 def testNoClasses(self):
     batch_size = 5
     height, width = 231, 231
     num_classes = None
     with self.test_session():
         inputs = tf.random_uniform((batch_size, height, width, 3))
         net, end_points = overfeat.overfeat(inputs, num_classes)
         expected_names = [
             'overfeat/conv1', 'overfeat/pool1', 'overfeat/conv2',
             'overfeat/pool2', 'overfeat/conv3', 'overfeat/conv4',
             'overfeat/conv5', 'overfeat/pool5', 'overfeat/fc6',
             'overfeat/fc7'
         ]
         self.assertSetEqual(set(end_points.keys()), set(expected_names))
         self.assertTrue(net.op.name.startswith('overfeat/fc7'))
Ejemplo n.º 16
0
def main():
    """
    You can also run these commands manually to generate the pb file
    1. git clone https://github.com/tensorflow/models.git
    2. export PYTHONPATH=Path_to_your_model_folder
    3. python alexnet.py
    """
    height, width = 231, 231
    inputs = tf.Variable(tf.random_uniform((1, height, width, 3)), name='input')
    with slim.arg_scope(overfeat.overfeat_arg_scope()):
        net, end_points = overfeat.overfeat(inputs, is_training = False)
    print("nodes in the graph")
    for n in end_points:
        print(n + " => " + str(end_points[n]))
    net_outputs = map(lambda x: tf.get_default_graph().get_tensor_by_name(x), argv[2].split(','))
    run_model(net_outputs, argv[1], 'overfeat', argv[3] == 'True')
Ejemplo n.º 17
0
def main():
    """
    You can also run these commands manually to generate the pb file
    1. git clone https://github.com/tensorflow/models.git
    2. export PYTHONPATH=Path_to_your_model_folder
    3. python alexnet.py
    """
    height, width = 231, 231
    inputs = tf.Variable(tf.random_uniform((1, height, width, 3)), name='input')
    inputs = tf.identity(inputs, "input_node")
    with slim.arg_scope(overfeat.overfeat_arg_scope()):
        net, end_points = overfeat.overfeat(inputs, is_training = False)
    print("nodes in the graph")
    for n in end_points:
        print(n + " => " + str(end_points[n]))
    net_outputs = map(lambda x: tf.get_default_graph().get_tensor_by_name(x), argv[2].split(','))
    run_model(net_outputs, argv[1], 'overfeat', argv[3] == 'True')
 def testEndPoints(self):
   batch_size = 5
   height, width = 231, 231
   num_classes = 1000
   with self.test_session():
     inputs = tf.random_uniform((batch_size, height, width, 3))
     _, end_points = overfeat.overfeat(inputs, num_classes)
     expected_names = ['overfeat/conv1',
                       'overfeat/pool1',
                       'overfeat/conv2',
                       'overfeat/pool2',
                       'overfeat/conv3',
                       'overfeat/conv4',
                       'overfeat/conv5',
                       'overfeat/pool5',
                       'overfeat/fc6',
                       'overfeat/fc7',
                       'overfeat/fc8'
                      ]
     self.assertSetEqual(set(end_points.keys()), set(expected_names))
Ejemplo n.º 19
0
 def testNoClasses(self):
   batch_size = 5
   height, width = 231, 231
   num_classes = None
   with self.test_session():
     inputs = tf.random_uniform((batch_size, height, width, 3))
     net, end_points = overfeat.overfeat(inputs, num_classes)
     expected_names = ['overfeat/conv1',
                       'overfeat/pool1',
                       'overfeat/conv2',
                       'overfeat/pool2',
                       'overfeat/conv3',
                       'overfeat/conv4',
                       'overfeat/conv5',
                       'overfeat/pool5',
                       'overfeat/fc6',
                       'overfeat/fc7'
                      ]
     self.assertSetEqual(set(end_points.keys()), set(expected_names))
     self.assertTrue(net.op.name.startswith('overfeat/fc7'))