Exemple #1
0
 def testDivisibleBy(self):
     tf.reset_default_graph()
     mobilenet_v2.mobilenet(tf.placeholder(tf.float32, (10, 224, 224, 16)),
                            conv_defs=mobilenet_v2.V2_DEF,
                            divisible_by=16,
                            min_depth=32)
     s = [
         op.outputs[0].get_shape().as_list()[-1]
         for op in find_ops('Conv2D')
     ]
     s = set(s)
     self.assertSameElements(
         [32, 64, 96, 160, 192, 320, 384, 576, 960, 1280, 1001], s)
Exemple #2
0
 def testDivisibleByWithArgScope(self):
     tf.reset_default_graph()
     # Verifies that depth_multiplier arg scope actually works
     # if no default min_depth is provided.
     with slim.arg_scope((mobilenet.depth_multiplier, ), min_depth=32):
         mobilenet_v2.mobilenet(tf.placeholder(tf.float32,
                                               (10, 224, 224, 2)),
                                conv_defs=mobilenet_v2.V2_DEF,
                                depth_multiplier=0.1)
         s = [
             op.outputs[0].get_shape().as_list()[-1]
             for op in find_ops('Conv2D')
         ]
         s = set(s)
         self.assertSameElements(s, [32, 192, 128, 1001])
Exemple #3
0
    def testFineGrained(self):
        tf.reset_default_graph()
        # Verifies that depth_multiplier arg scope actually works
        # if no default min_depth is provided.

        mobilenet_v2.mobilenet(tf.placeholder(tf.float32, (10, 224, 224, 2)),
                               conv_defs=mobilenet_v2.V2_DEF,
                               depth_multiplier=0.01,
                               finegrain_classification_mode=True)
        s = [
            op.outputs[0].get_shape().as_list()[-1]
            for op in find_ops('Conv2D')
        ]
        s = set(s)
        # All convolutions will be 8->48, except for the last one.
        self.assertSameElements(s, [8, 48, 1001, 1280])
Exemple #4
0
    def testImageSizes(self):
        for input_size, output_size in [(224, 7), (192, 6), (160, 5), (128, 4),
                                        (96, 3)]:
            tf.reset_default_graph()
            _, ep = mobilenet_v2.mobilenet(
                tf.placeholder(tf.float32, (10, input_size, input_size, 3)))

            self.assertEqual(ep['layer_18/output'].get_shape().as_list()[1:3],
                             [output_size] * 2)
Exemple #5
0
def mobilenet_backbone(input_tensor, depth_multiplier, output_stride,
                       is_training, weight_decay, bn_decay):
    with tf.contrib.slim.arg_scope(
            mobilenet_v2.training_scope(is_training=is_training,
                                        weight_decay=weight_decay)):
        with tf.contrib.slim.arg_scope(
            [tf.contrib.slim.conv2d],
                normalizer_params={
                    'scale': True,
                    'center': True,
                    'epsilon': 1e-3,
                    'decay': bn_decay,
                    'fused': False
                }):
            logits, endpoints = mobilenet_v2.mobilenet(
                input_tensor=input_tensor,
                num_classes=2,
                depth_multiplier=depth_multiplier,
                output_stride=output_stride,
                final_endpoint='layer_18')

    net = endpoints['layer_18']
    return net, endpoints