def _image_to_head(self, is_training, reuse=None):
        with slim.arg_scope(nasnet_large_arg_scope()):
            pool, _ = build_nasnet_large(self._input,
                                         0,
                                         is_training=is_training)

        return pool
Exemplo n.º 2
0
 def testBuildPreLogitsLargeModel(self):
     batch_size = 5
     height, width = 331, 331
     num_classes = None
     inputs = tf.random_uniform((batch_size, height, width, 3))
     tf.train.create_global_step()
     with slim.arg_scope(nasnet.nasnet_large_arg_scope()):
         net, end_points = nasnet.build_nasnet_large(inputs, num_classes)
     self.assertFalse('AuxLogits' in end_points)
     self.assertFalse('Predictions' in end_points)
     self.assertTrue(net.op.name.startswith('final_layer/Mean'))
     self.assertListEqual(net.get_shape().as_list(), [batch_size, 4032])
Exemplo n.º 3
0
    def infer(self, inputs):
        images = inputs['images']
        with tf.variable_scope(tf.get_variable_scope()):
            with slim.arg_scope(nasnet.nasnet_large_arg_scope()):
                _, _, nas_dict = build_nasnet_large(
                    images, is_training=self.is_training)
            with tf.variable_scope('refinenet'):
                pred, _ = build_refine_net(nas_dict,
                                           num_classes=self.num_cls,
                                           keep_prob=self.keep_prob)

        return {'logits': pred}
Exemplo n.º 4
0
 def __call__(self, x_input, batch_size=None, is_training=False):
     """ Construct the model and return probablities for given input ."""
     if self.built:
         return self.logits
     with slim.arg_scope(nasnet.nasnet_large_arg_scope()):
         with tf.variable_scope(self.ckpt):
             logits, end_points = nasnet.build_nasnet_large(
                 x_input, self.num_classes, is_training=False)
     self.built = True
     self.scores = end_points['Predictions']
     self.logits = logits
     self.preds = tf.argmax(logits, axis=1)
     return self.logits
Exemplo n.º 5
0
 def testOverrideHParamsLargeModel(self):
     batch_size = 5
     height, width = 331, 331
     num_classes = 1000
     inputs = tf.random_uniform((batch_size, height, width, 3))
     tf.train.create_global_step()
     config = nasnet.large_imagenet_config()
     config.set_hparam('data_format', 'NCHW')
     with slim.arg_scope(nasnet.nasnet_large_arg_scope()):
         _, end_points = nasnet.build_nasnet_large(inputs,
                                                   num_classes,
                                                   config=config)
     self.assertListEqual(end_points['Stem'].shape.as_list(),
                          [batch_size, 336, 42, 42])
Exemplo n.º 6
0
 def testNoAuxHeadLargeModel(self):
     batch_size = 5
     height, width = 331, 331
     num_classes = 1000
     for use_aux_head in (True, False):
         tf.reset_default_graph()
         inputs = tf.random_uniform((batch_size, height, width, 3))
         tf.train.create_global_step()
         config = nasnet.large_imagenet_config()
         config.set_hparam('use_aux_head', int(use_aux_head))
         with slim.arg_scope(nasnet.nasnet_large_arg_scope()):
             _, end_points = nasnet.build_nasnet_large(inputs,
                                                       num_classes,
                                                       config=config)
         self.assertEqual('AuxLogits' in end_points, use_aux_head)
Exemplo n.º 7
0
 def testBuildLogitsLargeModel(self):
     batch_size = 5
     height, width = 331, 331
     num_classes = 1000
     inputs = tf.random_uniform((batch_size, height, width, 3))
     tf.train.create_global_step()
     with slim.arg_scope(nasnet.nasnet_large_arg_scope()):
         logits, end_points = nasnet.build_nasnet_large(inputs, num_classes)
     auxlogits = end_points['AuxLogits']
     predictions = end_points['Predictions']
     self.assertListEqual(auxlogits.get_shape().as_list(),
                          [batch_size, num_classes])
     self.assertListEqual(logits.get_shape().as_list(),
                          [batch_size, num_classes])
     self.assertListEqual(predictions.get_shape().as_list(),
                          [batch_size, num_classes])
Exemplo n.º 8
0
 def testAllEndPointsShapesLargeModel(self):
     batch_size = 5
     height, width = 331, 331
     num_classes = 1000
     inputs = tf.random_uniform((batch_size, height, width, 3))
     tf.train.create_global_step()
     with slim.arg_scope(nasnet.nasnet_large_arg_scope()):
         _, end_points = nasnet.build_nasnet_large(inputs, num_classes)
     endpoints_shapes = {
         'Stem': [batch_size, 42, 42, 336],
         'Cell_0': [batch_size, 42, 42, 1008],
         'Cell_1': [batch_size, 42, 42, 1008],
         'Cell_2': [batch_size, 42, 42, 1008],
         'Cell_3': [batch_size, 42, 42, 1008],
         'Cell_4': [batch_size, 42, 42, 1008],
         'Cell_5': [batch_size, 42, 42, 1008],
         'Cell_6': [batch_size, 21, 21, 2016],
         'Cell_7': [batch_size, 21, 21, 2016],
         'Cell_8': [batch_size, 21, 21, 2016],
         'Cell_9': [batch_size, 21, 21, 2016],
         'Cell_10': [batch_size, 21, 21, 2016],
         'Cell_11': [batch_size, 21, 21, 2016],
         'Cell_12': [batch_size, 11, 11, 4032],
         'Cell_13': [batch_size, 11, 11, 4032],
         'Cell_14': [batch_size, 11, 11, 4032],
         'Cell_15': [batch_size, 11, 11, 4032],
         'Cell_16': [batch_size, 11, 11, 4032],
         'Cell_17': [batch_size, 11, 11, 4032],
         'Reduction_Cell_0': [batch_size, 21, 21, 1344],
         'Reduction_Cell_1': [batch_size, 11, 11, 2688],
         'global_pool': [batch_size, 4032],
         # Logits and predictions
         'AuxLogits': [batch_size, num_classes],
         'Logits': [batch_size, num_classes],
         'Predictions': [batch_size, num_classes]
     }
     self.assertItemsEqual(endpoints_shapes.keys(), end_points.keys())
     for endpoint_name in endpoints_shapes:
         tf.logging.info('Endpoint name: {}'.format(endpoint_name))
         expected_shape = endpoints_shapes[endpoint_name]
         self.assertTrue(endpoint_name in end_points)
         self.assertListEqual(
             end_points[endpoint_name].get_shape().as_list(),
             expected_shape)
Exemplo n.º 9
0
def pnasnet_large_arg_scope(weight_decay=4e-5,
                            batch_norm_decay=0.9997,
                            batch_norm_epsilon=0.001):
    """Default arg scope for the PNASNet Large ImageNet model."""
    return nasnet.nasnet_large_arg_scope(weight_decay, batch_norm_decay,
                                         batch_norm_epsilon)