Exemple #1
0
 def testEndpointsReuse(self):
     inputs = create_test_input(2, 32, 32, 3)
     with slim.arg_scope(xception.xception_arg_scope()):
         _, end_points0 = xception.xception_65(inputs,
                                               num_classes=10,
                                               reuse=False)
     with slim.arg_scope(xception.xception_arg_scope()):
         _, end_points1 = xception.xception_65(inputs,
                                               num_classes=10,
                                               reuse=True)
     self.assertItemsEqual(end_points0.keys(), end_points1.keys())
Exemple #2
0
 def testEndpointsReuse(self):
   inputs = create_test_input(2, 32, 32, 3)
   with slim.arg_scope(xception.xception_arg_scope()):
     _, end_points0 = xception.xception_65(
         inputs,
         num_classes=10,
         reuse=False)
   with slim.arg_scope(xception.xception_arg_scope()):
     _, end_points1 = xception.xception_65(
         inputs,
         num_classes=10,
         reuse=True)
   self.assertItemsEqual(end_points0.keys(), end_points1.keys())
 def testAtrousFullyConvolutionalValues(self):
   """Verify dense feature extraction with atrous convolution."""
   nominal_stride = 32
   for output_stride in [4, 8, 16, 32, None]:
     with slim.arg_scope(xception.xception_arg_scope()):
       with tf.Graph().as_default():
         with self.test_session() as sess:
           tf.set_random_seed(0)
           inputs = create_test_input(2, 96, 97, 3)
           # Dense feature extraction followed by subsampling.
           output, _ = self._xception_small(
               inputs,
               None,
               is_training=False,
               global_pool=False,
               output_stride=output_stride)
           if output_stride is None:
             factor = 1
           else:
             factor = nominal_stride // output_stride
           output = resnet_utils.subsample(output, factor)
           # Make the two networks use the same weights.
           tf.get_variable_scope().reuse_variables()
           # Feature extraction at the nominal network rate.
           expected, _ = self._xception_small(
               inputs,
               None,
               is_training=False,
               global_pool=False)
           sess.run(tf.global_variables_initializer())
           self.assertAllClose(output.eval(), expected.eval(),
                               atol=1e-5, rtol=1e-5)
Exemple #4
0
 def testFullyConvolutionalUnknownHeightWidth(self):
     batch = 2
     height, width = 65, 65
     global_pool = False
     inputs = create_test_input(batch, None, None, 3)
     with slim.arg_scope(xception.xception_arg_scope()):
         output, _ = self._xception_small(inputs,
                                          None,
                                          global_pool=global_pool)
     self.assertListEqual(output.get_shape().as_list(),
                          [batch, None, None, 16])
     images = create_test_input(batch, height, width, 3)
     with self.test_session() as sess:
         sess.run(tf.global_variables_initializer())
         output = sess.run(output, {inputs: images.eval()})
         self.assertEquals(output.shape, (batch, 3, 3, 16))
Exemple #5
0
 def testFullyConvolutionalUnknownHeightWidth(self):
   batch = 2
   height, width = 65, 65
   global_pool = False
   inputs = create_test_input(batch, None, None, 3)
   with slim.arg_scope(xception.xception_arg_scope()):
     output, _ = self._xception_small(
         inputs,
         None,
         global_pool=global_pool)
   self.assertListEqual(output.get_shape().as_list(),
                        [batch, None, None, 16])
   images = create_test_input(batch, height, width, 3)
   with self.test_session() as sess:
     sess.run(tf.global_variables_initializer())
     output = sess.run(output, {inputs: images.eval()})
     self.assertEquals(output.shape, (batch, 3, 3, 16))
Exemple #6
0
 def testClassificationEndPoints(self):
     global_pool = True
     num_classes = 10
     inputs = create_test_input(2, 224, 224, 3)
     with slim.arg_scope(xception.xception_arg_scope()):
         logits, end_points = self._xception_small(inputs,
                                                   num_classes=num_classes,
                                                   global_pool=global_pool,
                                                   scope='xception')
     self.assertTrue(logits.op.name.startswith('xception/logits'))
     self.assertListEqual(logits.get_shape().as_list(),
                          [2, 1, 1, num_classes])
     self.assertTrue('predictions' in end_points)
     self.assertListEqual(end_points['predictions'].get_shape().as_list(),
                          [2, 1, 1, num_classes])
     self.assertTrue('global_pool' in end_points)
     self.assertListEqual(end_points['global_pool'].get_shape().as_list(),
                          [2, 1, 1, 16])
Exemple #7
0
 def testUseBoundedAcitvation(self):
   global_pool = False
   num_classes = 10
   output_stride = 8
   for use_bounded_activation in (True, False):
     tf.reset_default_graph()
     inputs = create_test_input(2, 321, 321, 3)
     with slim.arg_scope(xception.xception_arg_scope(
         use_bounded_activation=use_bounded_activation)):
       _, _ = self._xception_small(
           inputs,
           num_classes,
           global_pool=global_pool,
           output_stride=output_stride,
           scope='xception')
       for node in tf.get_default_graph().as_graph_def().node:
         if node.op.startswith('Relu'):
           self.assertEqual(node.op == 'Relu6', use_bounded_activation)
Exemple #8
0
 def testUseBoundedAcitvation(self):
   global_pool = False
   num_classes = 10
   output_stride = 8
   for use_bounded_activation in (True, False):
     tf.reset_default_graph()
     inputs = create_test_input(2, 321, 321, 3)
     with slim.arg_scope(xception.xception_arg_scope(
         use_bounded_activation=use_bounded_activation)):
       _, _ = self._xception_small(
           inputs,
           num_classes,
           global_pool=global_pool,
           output_stride=output_stride,
           scope='xception')
       for node in tf.get_default_graph().as_graph_def().node:
         if node.op.startswith('Relu'):
           self.assertEqual(node.op == 'Relu6', use_bounded_activation)
Exemple #9
0
 def testClassificationEndPoints(self):
   global_pool = True
   num_classes = 10
   inputs = create_test_input(2, 224, 224, 3)
   with slim.arg_scope(xception.xception_arg_scope()):
     logits, end_points = self._xception_small(
         inputs,
         num_classes=num_classes,
         global_pool=global_pool,
         scope='xception')
   self.assertTrue(
       logits.op.name.startswith('xception/logits'))
   self.assertListEqual(logits.get_shape().as_list(), [2, 1, 1, num_classes])
   self.assertTrue('predictions' in end_points)
   self.assertListEqual(end_points['predictions'].get_shape().as_list(),
                        [2, 1, 1, num_classes])
   self.assertTrue('global_pool' in end_points)
   self.assertListEqual(end_points['global_pool'].get_shape().as_list(),
                        [2, 1, 1, 16])
Exemple #10
0
 def testUnknownBatchSize(self):
     batch = 2
     height, width = 65, 65
     global_pool = True
     num_classes = 10
     inputs = create_test_input(None, height, width, 3)
     with slim.arg_scope(xception.xception_arg_scope()):
         logits, _ = self._xception_small(inputs,
                                          num_classes,
                                          global_pool=global_pool,
                                          scope='xception')
     self.assertTrue(logits.op.name.startswith('xception/logits'))
     self.assertListEqual(logits.get_shape().as_list(),
                          [None, 1, 1, num_classes])
     images = create_test_input(batch, height, width, 3)
     with self.test_session() as sess:
         sess.run(tf.global_variables_initializer())
         output = sess.run(logits, {inputs: images.eval()})
         self.assertEquals(output.shape, (batch, 1, 1, num_classes))
Exemple #11
0
 def testUnknownBatchSize(self):
   batch = 2
   height, width = 65, 65
   global_pool = True
   num_classes = 10
   inputs = create_test_input(None, height, width, 3)
   with slim.arg_scope(xception.xception_arg_scope()):
     logits, _ = self._xception_small(
         inputs,
         num_classes,
         global_pool=global_pool,
         scope='xception')
   self.assertTrue(logits.op.name.startswith('xception/logits'))
   self.assertListEqual(logits.get_shape().as_list(),
                        [None, 1, 1, num_classes])
   images = create_test_input(batch, height, width, 3)
   with self.test_session() as sess:
     sess.run(tf.global_variables_initializer())
     output = sess.run(logits, {inputs: images.eval()})
     self.assertEquals(output.shape, (batch, 1, 1, num_classes))
 def testFullyConvolutionalEndpointShapes(self):
   global_pool = False
   num_classes = 10
   inputs = create_test_input(2, 321, 321, 3)
   with slim.arg_scope(xception.xception_arg_scope()):
     _, end_points = self._xception_small(
         inputs,
         num_classes,
         global_pool=global_pool,
         scope='xception')
     endpoint_to_shape = {
         'xception/entry_flow/conv1_1': [2, 161, 161, 32],
         'xception/entry_flow/block1': [2, 81, 81, 1],
         'xception/entry_flow/block2': [2, 41, 41, 2],
         'xception/entry_flow/block4': [2, 21, 21, 4],
         'xception/middle_flow/block1': [2, 21, 21, 4],
         'xception/exit_flow/block1': [2, 11, 11, 8],
         'xception/exit_flow/block2': [2, 11, 11, 16]}
     for endpoint, shape in six.iteritems(endpoint_to_shape):
       self.assertListEqual(end_points[endpoint].get_shape().as_list(), shape)
 def testClassificationShapes(self):
   global_pool = True
   num_classes = 10
   inputs = create_test_input(2, 224, 224, 3)
   with slim.arg_scope(xception.xception_arg_scope()):
     _, end_points = self._xception_small(
         inputs,
         num_classes,
         global_pool=global_pool,
         scope='xception')
     endpoint_to_shape = {
         'xception/entry_flow/conv1_1': [2, 112, 112, 32],
         'xception/entry_flow/block1': [2, 56, 56, 1],
         'xception/entry_flow/block2': [2, 28, 28, 2],
         'xception/entry_flow/block4': [2, 14, 14, 4],
         'xception/middle_flow/block1': [2, 14, 14, 4],
         'xception/exit_flow/block1': [2, 7, 7, 8],
         'xception/exit_flow/block2': [2, 7, 7, 16]}
     for endpoint, shape in six.iteritems(endpoint_to_shape):
       self.assertListEqual(end_points[endpoint].get_shape().as_list(), shape)
Exemple #14
0
 def testAtrousFullyConvolutionalEndpointShapes(self):
   global_pool = False
   num_classes = 3
   output_stride = 8
   inputs = create_test_input(2, 65, 65, 3)
   with slim.arg_scope(xception.xception_arg_scope()):
     _, end_points = self._xception_small(
         inputs,
         num_classes,
         global_pool=global_pool,
         output_stride=output_stride,
         scope='xception')
     endpoint_to_shape = {
         'xception/entry_flow/block1': [2, 17, 17, 1],
         'xception/entry_flow/block2': [2, 9, 9, 2],
         'xception/entry_flow/block4': [2, 9, 9, 4],
         'xception/middle_flow/block1': [2, 9, 9, 4],
         'xception/exit_flow/block1': [2, 9, 9, 8],
         'xception/exit_flow/block2': [2, 9, 9, 16]}
     for endpoint, shape in six.iteritems(endpoint_to_shape):
       self.assertListEqual(end_points[endpoint].get_shape().as_list(), shape)
 def testEndpointNames(self):
   global_pool = True
   num_classes = 10
   inputs = create_test_input(2, 224, 224, 3)
   with slim.arg_scope(xception.xception_arg_scope()):
     _, end_points = self._xception_small(
         inputs,
         num_classes=num_classes,
         global_pool=global_pool,
         scope='xception')
   expected = [
       'xception/entry_flow/conv1_1',
       'xception/entry_flow/conv1_2',
       'xception/entry_flow/block1/unit_1/xception_module/separable_conv1',
       'xception/entry_flow/block1/unit_1/xception_module/separable_conv2',
       'xception/entry_flow/block1/unit_1/xception_module/separable_conv3',
       'xception/entry_flow/block1/unit_1/xception_module/shortcut',
       'xception/entry_flow/block1/unit_1/xception_module',
       'xception/entry_flow/block1',
       'xception/entry_flow/block2/unit_1/xception_module/separable_conv1',
       'xception/entry_flow/block2/unit_1/xception_module/separable_conv2',
       'xception/entry_flow/block2/unit_1/xception_module/separable_conv3',
       'xception/entry_flow/block2/unit_1/xception_module/shortcut',
       'xception/entry_flow/block2/unit_1/xception_module',
       'xception/entry_flow/block2',
       'xception/entry_flow/block3/unit_1/xception_module/separable_conv1',
       'xception/entry_flow/block3/unit_1/xception_module/separable_conv2',
       'xception/entry_flow/block3/unit_1/xception_module/separable_conv3',
       'xception/entry_flow/block3/unit_1/xception_module/shortcut',
       'xception/entry_flow/block3/unit_1/xception_module',
       'xception/entry_flow/block3',
       'xception/entry_flow/block4/unit_1/xception_module/separable_conv1',
       'xception/entry_flow/block4/unit_1/xception_module/separable_conv2',
       'xception/entry_flow/block4/unit_1/xception_module/separable_conv3',
       'xception/entry_flow/block4/unit_1/xception_module/shortcut',
       'xception/entry_flow/block4/unit_1/xception_module',
       'xception/entry_flow/block4',
       'xception/middle_flow/block1/unit_1/xception_module/separable_conv1',
       'xception/middle_flow/block1/unit_1/xception_module/separable_conv2',
       'xception/middle_flow/block1/unit_1/xception_module/separable_conv3',
       'xception/middle_flow/block1/unit_1/xception_module',
       'xception/middle_flow/block1/unit_2/xception_module/separable_conv1',
       'xception/middle_flow/block1/unit_2/xception_module/separable_conv2',
       'xception/middle_flow/block1/unit_2/xception_module/separable_conv3',
       'xception/middle_flow/block1/unit_2/xception_module',
       'xception/middle_flow/block1',
       'xception/exit_flow/block1/unit_1/xception_module/separable_conv1',
       'xception/exit_flow/block1/unit_1/xception_module/separable_conv2',
       'xception/exit_flow/block1/unit_1/xception_module/separable_conv3',
       'xception/exit_flow/block1/unit_1/xception_module/shortcut',
       'xception/exit_flow/block1/unit_1/xception_module',
       'xception/exit_flow/block1',
       'xception/exit_flow/block2/unit_1/xception_module/separable_conv1',
       'xception/exit_flow/block2/unit_1/xception_module/separable_conv2',
       'xception/exit_flow/block2/unit_1/xception_module/separable_conv3',
       'xception/exit_flow/block2/unit_1/xception_module',
       'xception/exit_flow/block2',
       'global_pool',
       'xception/logits',
       'predictions',
   ]
   self.assertItemsEqual(end_points.keys(), expected)
Exemple #16
0
sys.path.append(TF_API)

from deeplab.core import xception
from tensorflow.contrib.slim.nets import resnet_utils

slim = tf.contrib.slim





if __name__ == '__main__':
    inputs = tf.random_normal([1, 224, 224, 3])
    
    
    with slim.arg_scope(xception.xception_arg_scope()):
    
        net, end_points = xception.xception_65(inputs,
                    num_classes=100,
                    is_training=False,
                    global_pool=True,
                    keep_prob=0.5,
                    output_stride=None,
                    regularize_depthwise=False,
                    multi_grid=[12,16,18],
                    reuse=None,
                    scope='xception_65')
   
    writer = tf.summary.FileWriter("./logs", graph=tf.get_default_graph())