123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583 |
- # Copyright 2016 The TensorFlow Authors. All Rights Reserved.
- #
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- # ==============================================================================
- """Tests for slim.nets.vgg."""
- from __future__ import absolute_import
- from __future__ import division
- from __future__ import print_function
- import tensorflow as tf
- from nets import vgg
- slim = tf.contrib.slim
- class VGGATest(tf.test.TestCase):
- 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_a(inputs, num_classes)
- self.assertEquals(logits.op.name, 'vgg_a/fc8/squeezed')
- self.assertListEqual(logits.get_shape().as_list(),
- [batch_size, num_classes])
- 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_a(inputs, num_classes, spatial_squeeze=False)
- self.assertEquals(logits.op.name, 'vgg_a/fc8/BiasAdd')
- self.assertListEqual(logits.get_shape().as_list(),
- [batch_size, 2, 2, num_classes])
- def testGlobalPool(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_a(inputs, num_classes, spatial_squeeze=False,
- global_pool=True)
- self.assertEquals(logits.op.name, 'vgg_a/fc8/BiasAdd')
- self.assertListEqual(logits.get_shape().as_list(),
- [batch_size, 1, 1, num_classes])
- 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_a(inputs, num_classes)
- expected_names = ['vgg_a/conv1/conv1_1',
- 'vgg_a/pool1',
- 'vgg_a/conv2/conv2_1',
- 'vgg_a/pool2',
- 'vgg_a/conv3/conv3_1',
- 'vgg_a/conv3/conv3_2',
- 'vgg_a/pool3',
- 'vgg_a/conv4/conv4_1',
- 'vgg_a/conv4/conv4_2',
- 'vgg_a/pool4',
- 'vgg_a/conv5/conv5_1',
- 'vgg_a/conv5/conv5_2',
- 'vgg_a/pool5',
- 'vgg_a/fc6',
- 'vgg_a/fc7',
- 'vgg_a/fc8'
- ]
- self.assertSetEqual(set(end_points.keys()), set(expected_names))
- def testNoClasses(self):
- batch_size = 5
- height, width = 224, 224
- num_classes = None
- with self.test_session():
- inputs = tf.random_uniform((batch_size, height, width, 3))
- net, end_points = vgg.vgg_a(inputs, num_classes)
- expected_names = ['vgg_a/conv1/conv1_1',
- 'vgg_a/pool1',
- 'vgg_a/conv2/conv2_1',
- 'vgg_a/pool2',
- 'vgg_a/conv3/conv3_1',
- 'vgg_a/conv3/conv3_2',
- 'vgg_a/pool3',
- 'vgg_a/conv4/conv4_1',
- 'vgg_a/conv4/conv4_2',
- 'vgg_a/pool4',
- 'vgg_a/conv5/conv5_1',
- 'vgg_a/conv5/conv5_2',
- 'vgg_a/pool5',
- 'vgg_a/fc6',
- 'vgg_a/fc7',
- ]
- self.assertSetEqual(set(end_points.keys()), set(expected_names))
- self.assertTrue(net.op.name.startswith('vgg_a/fc7'))
- 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_a(inputs, num_classes)
- expected_names = ['vgg_a/conv1/conv1_1/weights',
- 'vgg_a/conv1/conv1_1/biases',
- 'vgg_a/conv2/conv2_1/weights',
- 'vgg_a/conv2/conv2_1/biases',
- 'vgg_a/conv3/conv3_1/weights',
- 'vgg_a/conv3/conv3_1/biases',
- 'vgg_a/conv3/conv3_2/weights',
- 'vgg_a/conv3/conv3_2/biases',
- 'vgg_a/conv4/conv4_1/weights',
- 'vgg_a/conv4/conv4_1/biases',
- 'vgg_a/conv4/conv4_2/weights',
- 'vgg_a/conv4/conv4_2/biases',
- 'vgg_a/conv5/conv5_1/weights',
- 'vgg_a/conv5/conv5_1/biases',
- 'vgg_a/conv5/conv5_2/weights',
- 'vgg_a/conv5/conv5_2/biases',
- 'vgg_a/fc6/weights',
- 'vgg_a/fc6/biases',
- 'vgg_a/fc7/weights',
- 'vgg_a/fc7/biases',
- 'vgg_a/fc8/weights',
- 'vgg_a/fc8/biases',
- ]
- model_variables = [v.op.name for v in slim.get_model_variables()]
- self.assertSetEqual(set(model_variables), set(expected_names))
- 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_a(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 = 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_a(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_a(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])
- 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_a(inputs)
- sess.run(tf.global_variables_initializer())
- output = sess.run(logits)
- self.assertTrue(output.any())
- class VGG16Test(tf.test.TestCase):
- 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])
- 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])
- def testGlobalPool(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,
- global_pool=True)
- self.assertEquals(logits.op.name, 'vgg_16/fc8/BiasAdd')
- self.assertListEqual(logits.get_shape().as_list(),
- [batch_size, 1, 1, num_classes])
- 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 testNoClasses(self):
- batch_size = 5
- height, width = 224, 224
- num_classes = None
- with self.test_session():
- inputs = tf.random_uniform((batch_size, height, width, 3))
- net, 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',
- ]
- self.assertSetEqual(set(end_points.keys()), set(expected_names))
- self.assertTrue(net.op.name.startswith('vgg_16/fc7'))
- 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))
- 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])
- 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])
- 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())
- class VGG19Test(tf.test.TestCase):
- 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_19(inputs, num_classes)
- self.assertEquals(logits.op.name, 'vgg_19/fc8/squeezed')
- self.assertListEqual(logits.get_shape().as_list(),
- [batch_size, num_classes])
- 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_19(inputs, num_classes, spatial_squeeze=False)
- self.assertEquals(logits.op.name, 'vgg_19/fc8/BiasAdd')
- self.assertListEqual(logits.get_shape().as_list(),
- [batch_size, 2, 2, num_classes])
- def testGlobalPool(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_19(inputs, num_classes, spatial_squeeze=False,
- global_pool=True)
- self.assertEquals(logits.op.name, 'vgg_19/fc8/BiasAdd')
- self.assertListEqual(logits.get_shape().as_list(),
- [batch_size, 1, 1, num_classes])
- 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_19(inputs, num_classes)
- expected_names = [
- 'vgg_19/conv1/conv1_1',
- 'vgg_19/conv1/conv1_2',
- 'vgg_19/pool1',
- 'vgg_19/conv2/conv2_1',
- 'vgg_19/conv2/conv2_2',
- 'vgg_19/pool2',
- 'vgg_19/conv3/conv3_1',
- 'vgg_19/conv3/conv3_2',
- 'vgg_19/conv3/conv3_3',
- 'vgg_19/conv3/conv3_4',
- 'vgg_19/pool3',
- 'vgg_19/conv4/conv4_1',
- 'vgg_19/conv4/conv4_2',
- 'vgg_19/conv4/conv4_3',
- 'vgg_19/conv4/conv4_4',
- 'vgg_19/pool4',
- 'vgg_19/conv5/conv5_1',
- 'vgg_19/conv5/conv5_2',
- 'vgg_19/conv5/conv5_3',
- 'vgg_19/conv5/conv5_4',
- 'vgg_19/pool5',
- 'vgg_19/fc6',
- 'vgg_19/fc7',
- 'vgg_19/fc8'
- ]
- self.assertSetEqual(set(end_points.keys()), set(expected_names))
- def testNoClasses(self):
- batch_size = 5
- height, width = 224, 224
- num_classes = None
- with self.test_session():
- inputs = tf.random_uniform((batch_size, height, width, 3))
- net, end_points = vgg.vgg_19(inputs, num_classes)
- expected_names = [
- 'vgg_19/conv1/conv1_1',
- 'vgg_19/conv1/conv1_2',
- 'vgg_19/pool1',
- 'vgg_19/conv2/conv2_1',
- 'vgg_19/conv2/conv2_2',
- 'vgg_19/pool2',
- 'vgg_19/conv3/conv3_1',
- 'vgg_19/conv3/conv3_2',
- 'vgg_19/conv3/conv3_3',
- 'vgg_19/conv3/conv3_4',
- 'vgg_19/pool3',
- 'vgg_19/conv4/conv4_1',
- 'vgg_19/conv4/conv4_2',
- 'vgg_19/conv4/conv4_3',
- 'vgg_19/conv4/conv4_4',
- 'vgg_19/pool4',
- 'vgg_19/conv5/conv5_1',
- 'vgg_19/conv5/conv5_2',
- 'vgg_19/conv5/conv5_3',
- 'vgg_19/conv5/conv5_4',
- 'vgg_19/pool5',
- 'vgg_19/fc6',
- 'vgg_19/fc7',
- ]
- self.assertSetEqual(set(end_points.keys()), set(expected_names))
- self.assertTrue(net.op.name.startswith('vgg_19/fc7'))
- 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_19(inputs, num_classes)
- expected_names = [
- 'vgg_19/conv1/conv1_1/weights',
- 'vgg_19/conv1/conv1_1/biases',
- 'vgg_19/conv1/conv1_2/weights',
- 'vgg_19/conv1/conv1_2/biases',
- 'vgg_19/conv2/conv2_1/weights',
- 'vgg_19/conv2/conv2_1/biases',
- 'vgg_19/conv2/conv2_2/weights',
- 'vgg_19/conv2/conv2_2/biases',
- 'vgg_19/conv3/conv3_1/weights',
- 'vgg_19/conv3/conv3_1/biases',
- 'vgg_19/conv3/conv3_2/weights',
- 'vgg_19/conv3/conv3_2/biases',
- 'vgg_19/conv3/conv3_3/weights',
- 'vgg_19/conv3/conv3_3/biases',
- 'vgg_19/conv3/conv3_4/weights',
- 'vgg_19/conv3/conv3_4/biases',
- 'vgg_19/conv4/conv4_1/weights',
- 'vgg_19/conv4/conv4_1/biases',
- 'vgg_19/conv4/conv4_2/weights',
- 'vgg_19/conv4/conv4_2/biases',
- 'vgg_19/conv4/conv4_3/weights',
- 'vgg_19/conv4/conv4_3/biases',
- 'vgg_19/conv4/conv4_4/weights',
- 'vgg_19/conv4/conv4_4/biases',
- 'vgg_19/conv5/conv5_1/weights',
- 'vgg_19/conv5/conv5_1/biases',
- 'vgg_19/conv5/conv5_2/weights',
- 'vgg_19/conv5/conv5_2/biases',
- 'vgg_19/conv5/conv5_3/weights',
- 'vgg_19/conv5/conv5_3/biases',
- 'vgg_19/conv5/conv5_4/weights',
- 'vgg_19/conv5/conv5_4/biases',
- 'vgg_19/fc6/weights',
- 'vgg_19/fc6/biases',
- 'vgg_19/fc7/weights',
- 'vgg_19/fc7/biases',
- 'vgg_19/fc8/weights',
- 'vgg_19/fc8/biases',
- ]
- model_variables = [v.op.name for v in slim.get_model_variables()]
- self.assertSetEqual(set(model_variables), set(expected_names))
- 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_19(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 = 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_19(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_19(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])
- 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_19(inputs)
- sess.run(tf.global_variables_initializer())
- output = sess.run(logits)
- self.assertTrue(output.any())
- if __name__ == '__main__':
- tf.test.main()
|