nets_factory_test.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Copyright 2016 Google Inc. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ==============================================================================
  15. """Tests for slim.inception."""
  16. from __future__ import absolute_import
  17. from __future__ import division
  18. from __future__ import print_function
  19. import tensorflow as tf
  20. from nets import nets_factory
  21. class NetworksTest(tf.test.TestCase):
  22. def testGetNetworkFnFirstHalf(self):
  23. batch_size = 5
  24. num_classes = 1000
  25. for net in nets_factory.networks_map.keys()[:10]:
  26. with tf.Graph().as_default() as g, self.test_session(g):
  27. net_fn = nets_factory.get_network_fn(net, num_classes)
  28. # Most networks use 224 as their default_image_size
  29. image_size = getattr(net_fn, 'default_image_size', 224)
  30. inputs = tf.random_uniform((batch_size, image_size, image_size, 3))
  31. logits, end_points = net_fn(inputs)
  32. self.assertTrue(isinstance(logits, tf.Tensor))
  33. self.assertTrue(isinstance(end_points, dict))
  34. self.assertEqual(logits.get_shape().as_list()[0], batch_size)
  35. self.assertEqual(logits.get_shape().as_list()[-1], num_classes)
  36. def testGetNetworkFnSecondHalf(self):
  37. batch_size = 5
  38. num_classes = 1000
  39. for net in nets_factory.networks_map.keys()[10:]:
  40. with tf.Graph().as_default() as g, self.test_session(g):
  41. net_fn = nets_factory.get_network_fn(net, num_classes)
  42. # Most networks use 224 as their default_image_size
  43. image_size = getattr(net_fn, 'default_image_size', 224)
  44. inputs = tf.random_uniform((batch_size, image_size, image_size, 3))
  45. logits, end_points = net_fn(inputs)
  46. self.assertTrue(isinstance(logits, tf.Tensor))
  47. self.assertTrue(isinstance(end_points, dict))
  48. self.assertEqual(logits.get_shape().as_list()[0], batch_size)
  49. self.assertEqual(logits.get_shape().as_list()[-1], num_classes)
  50. if __name__ == '__main__':
  51. tf.test.main()