def mobilenetv2_head(inputs, is_training=True, stage='stage1'): if stage == 'stage1': with slim.arg_scope( mobilenetv2_scope(is_training=is_training, trainable=True)): flatten, _ = mobilenet_v2.mobilenet( input_tensor=inputs, num_classes=None, is_training=False, depth_multiplier=1.0, scope='MobilenetV2', conv_defs=V2_HEAD_DEF, finegrain_classification_mode=False ) #有global average pooling输出1*1*1280 flatten = tf.squeeze(flatten, [1, 2]) else: fc_flatten = slim.flatten(input) net = slim.fully_connected(fc_flatten, 1024, scope='fc_1_{}'.format(stage)) net = slim.dropout(net, keep_prob=0.5, is_training=is_training, scope='dropout_{}'.format(stage)) flatten = slim.fully_connected(net, 1024, scope='fc_2_{}'.format(stage)) return flatten
def mobilenetv2_head(inputs, is_training=True): with slim.arg_scope(mobilenetv2_scope(is_training=is_training, trainable=True)): net, _ = mobilenet_v2.mobilenet(input_tensor=inputs, num_classes=None, is_training=False, depth_multiplier=1.0, scope='MobilenetV2', conv_defs=V2_HEAD_DEF, finegrain_classification_mode=False) net = tf.squeeze(net, [1, 2]) return net