nets_factory_test.py 2.42 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Copyright 2016 Google Inc. 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.inception."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

derekjchow's avatar
derekjchow committed
22

23
24
25
26
27
28
29
import tensorflow as tf

from nets import nets_factory


class NetworksTest(tf.test.TestCase):

derekjchow's avatar
derekjchow committed
30
  def testGetNetworkFnFirstHalf(self):
31
32
    batch_size = 5
    num_classes = 1000
derekjchow's avatar
derekjchow committed
33
34
    for net in nets_factory.networks_map.keys()[:10]:
      with tf.Graph().as_default() as g, self.test_session(g):
35
36
37
38
39
40
41
42
43
44
        net_fn = nets_factory.get_network_fn(net, num_classes)
        # Most networks use 224 as their default_image_size
        image_size = getattr(net_fn, 'default_image_size', 224)
        inputs = tf.random_uniform((batch_size, image_size, image_size, 3))
        logits, end_points = net_fn(inputs)
        self.assertTrue(isinstance(logits, tf.Tensor))
        self.assertTrue(isinstance(end_points, dict))
        self.assertEqual(logits.get_shape().as_list()[0], batch_size)
        self.assertEqual(logits.get_shape().as_list()[-1], num_classes)

derekjchow's avatar
derekjchow committed
45
  def testGetNetworkFnSecondHalf(self):
46
    batch_size = 5
derekjchow's avatar
derekjchow committed
47
48
49
50
51
52
    num_classes = 1000
    for net in nets_factory.networks_map.keys()[10:]:
      with tf.Graph().as_default() as g, self.test_session(g):
        net_fn = nets_factory.get_network_fn(net, num_classes)
        # Most networks use 224 as their default_image_size
        image_size = getattr(net_fn, 'default_image_size', 224)
53
        inputs = tf.random_uniform((batch_size, image_size, image_size, 3))
derekjchow's avatar
derekjchow committed
54
55
56
57
58
        logits, end_points = net_fn(inputs)
        self.assertTrue(isinstance(logits, tf.Tensor))
        self.assertTrue(isinstance(end_points, dict))
        self.assertEqual(logits.get_shape().as_list()[0], batch_size)
        self.assertEqual(logits.get_shape().as_list()[-1], num_classes)
59

60
61
if __name__ == '__main__':
  tf.test.main()