1 # Copyright 2016 Google Inc. All Rights Reserved.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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 # ==============================================================================
16 """Tests for slim.inception."""
18 from __future__ import absolute_import
19 from __future__ import division
20 from __future__ import print_function
22 import tensorflow as tf
24 from nets import nets_factory
26 slim = tf.contrib.slim
29 class NetworksTest(tf.test.TestCase):
31 def testGetNetworkFn(self):
34 for net in nets_factory.networks_map:
35 with self.test_session():
36 net_fn = nets_factory.get_network_fn(net, num_classes)
37 # Most networks use 224 as their default_image_size
38 image_size = getattr(net_fn, 'default_image_size', 224)
39 inputs = tf.random_uniform((batch_size, image_size, image_size, 3))
40 logits, end_points = net_fn(inputs)
41 self.assertTrue(isinstance(logits, tf.Tensor))
42 self.assertTrue(isinstance(end_points, dict))
43 self.assertEqual(logits.get_shape().as_list()[0], batch_size)
44 self.assertEqual(logits.get_shape().as_list()[-1], num_classes)
46 def testGetNetworkFnArgScope(self):
50 with self.test_session(use_gpu=True):
51 net_fn = nets_factory.get_network_fn(net, num_classes)
52 image_size = getattr(net_fn, 'default_image_size', 224)
53 with slim.arg_scope([slim.model_variable, slim.variable],
55 inputs = tf.random_uniform((batch_size, image_size, image_size, 3))
57 weights = tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES, 'CifarNet/conv1')[0]
58 self.assertDeviceEqual('/CPU:0', weights.device)
60 if __name__ == '__main__':