nets_factory_test.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 testGetNetworkFn(self):
  23. batch_size = 5
  24. num_classes = 1000
  25. for net in nets_factory.networks_map:
  26. with self.test_session():
  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. if __name__ == '__main__':
  37. tf.test.main()