def build_net(self, ):
        batch_norm_params = {
            'is_training': self.config.is_train,
            'center': True,
            'scale': True,
            'decay': 0.9997,
            'epsilon': 1e-3,
        }
        self.im_input = tf.placeholder(tf.string, name='input')
        im, b_scale, = self.handle_im(self.im_input, size=self.config.img_size)
        im.set_shape(
            tf.TensorShape(
                [None, self.config.img_size, self.config.img_size, 3]))
        im = im / 255 * 2 - 1

        batch_m = tf.shape(im)[0]
        with tf.variable_scope('FeatureExtractor'):
            with tf.contrib.slim.arg_scope(
                    mobilenet_v2.training_scope(
                        is_training=self.config.is_train,
                        weight_decay=0.00004,
                        stddev=0.03,
                        dropout_keep_prob=0.8,
                        bn_decay=0.9997)):
                logits, endpoints = mobilenet_v2.mobilenet(im,
                                                           num_classes=None)

                net15 = endpoints['layer_15/expansion_output']
                net19 = endpoints['layer_19']
                print(net15, net19)
                with slim.arg_scope([slim.batch_norm], **batch_norm_params):
                    net20 = new_conv2d(net19, 512, 2, 2)
                    net21 = new_conv2d(net20, 256, 2, 3)
                    net22 = new_conv2d(net21, 256, 2, 4)
                    net23 = new_conv2d(net22, 128, 2, 5)

        var_pre = tf.global_variables()[1:]
        weights_init = tf.truncated_normal_initializer(stddev=0.03)
        net = [net15, net19, net20, net21, net22, net23]
        with slim.arg_scope([slim.conv2d],
                            activation_fn=None,
                            weights_initializer=weights_init,
                            weights_regularizer=slim.l2_regularizer(
                                self.config.weight_decay),
                            normalizer_fn=None):
            for i in range(len(self.config.num_anchors)):
                with tf.variable_scope('BoxPredictor_%d' % i):
                    with tf.variable_scope('ClassPredictor'):
                        net_cls = slim.conv2d(
                            net[i], self.config.num_anchors[i] *
                            (self.config.num_cls + 1), [1, 1])
                    with tf.variable_scope('BoxEncodingPredictor'):
                        net_box = slim.conv2d(
                            net[i],
                            self.config.num_anchors[i] * 4,
                            [1, 1],
                        )
                    net_cls = tf.reshape(
                        net_cls,
                        (batch_m, -1, self.config.num_cls + 1),
                    )
                    net_box = tf.reshape(
                        net_box,
                        (batch_m, -1, 4),
                    )
                    net[i] = tf.concat([net_cls, net_box], axis=-1)
        net = tf.concat(net, axis=1, name='net')
        pre_bboxes = loc2bbox(
            net[..., -4:] *
            tf.constant([0.1, 0.1, 0.2, 0.2], dtype=tf.float32), self.anchors)
        pre = predict(pre_bboxes[0],
                      net[0][..., :-4],
                      size=self.config.img_size,
                      c_thresh=1e-2,
                      num_cls=self.config.num_cls)
        self.result = tf.concat([pre[..., :4] * b_scale, pre[..., 4:]],
                                axis=-1,
                                name='out')
        print(self.result)
    def build_net(self, Iter):
        batch_norm_params = {
            'is_training': self.config.is_train,
            'center': True,
            'scale': True,
            'decay': 0.9997,
            'epsilon': 1e-3,
        }
        im, bboxes, nums = Iter.get_next()
        im.set_shape(
            tf.TensorShape(
                [None, self.config.img_size, self.config.img_size, 3]))
        im = im / 255 * 2 - 1
        batch_m = tf.shape(im)[0]
        with tf.variable_scope('FeatureExtractor'):
            with tf.contrib.slim.arg_scope(
                    mobilenet_v2.training_scope(
                        is_training=self.config.is_train,
                        weight_decay=0.00004,
                        stddev=0.03,
                        dropout_keep_prob=0.8,
                        bn_decay=0.9997)):
                logits, endpoints = mobilenet_v2.mobilenet(im,
                                                           num_classes=None)
                net15 = endpoints['layer_15/expansion_output']
                net19 = endpoints['layer_19']
                print(net15, net19)
                with slim.arg_scope([slim.batch_norm], **batch_norm_params):
                    net20 = new_conv2d(net19, 512, 2, 2)
                    net21 = new_conv2d(net20, 256, 2, 3)
                    net22 = new_conv2d(net21, 256, 2, 4)
                    net23 = new_conv2d(net22, 128, 2, 5)

        var_pre = tf.global_variables()[1:]
        weights_init = tf.truncated_normal_initializer(stddev=0.03)
        net = [net15, net19, net20, net21, net22, net23]
        with slim.arg_scope([slim.conv2d],
                            activation_fn=None,
                            weights_initializer=weights_init,
                            weights_regularizer=slim.l2_regularizer(
                                self.config.weight_decay),
                            normalizer_fn=None):
            for i in range(len(self.config.num_anchors)):
                with tf.variable_scope('BoxPredictor_%d' % i):
                    with tf.variable_scope('ClassPredictor'):
                        net_cls = slim.conv2d(
                            net[i], self.config.num_anchors[i] *
                            (self.config.num_cls + 1), [1, 1])
                    with tf.variable_scope('BoxEncodingPredictor'):
                        net_box = slim.conv2d(
                            net[i],
                            self.config.num_anchors[i] * 4,
                            [1, 1],
                        )
                    net_cls = tf.reshape(
                        net_cls,
                        (batch_m, -1, self.config.num_cls + 1),
                    )
                    net_box = tf.reshape(
                        net_box,
                        (batch_m, -1, 4),
                    )
                    net[i] = tf.concat([net_cls, net_box], axis=-1)

        net = tf.concat(net, axis=1, name='net')
        loss, Num = self.get_loss(net, bboxes, nums)
        return tf.reduce_sum(loss) / tf.reduce_sum(Num + 1e-10), var_pre