1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| def nn_p3p4p5(img_input=None, offset=True, num_scale=1, trainable=False): bn_axis = 3 x = ZeroPadding2D((3, 3))(img_input) x = Convolution2D(64, (7, 7), strides=(2, 2), name='conv1', trainable=False)(x) x = BatchNormalization(axis=bn_axis, name='bn_conv1')(x) x = Activation('relu')(x) x = MaxPooling2D((3, 3), strides=(2, 2), padding='same')(x) x = conv_block(x, 3, [64, 64, 256], stage=2, block='a', strides=(1, 1), trainable=False) x = identity_block(x, 3, [64, 64, 256], stage=2, block='b', trainable=False) stage2 = identity_block(x, 3, [64, 64, 256], stage=2, block='c', trainable=False) x = conv_block(stage2, 3, [128, 128, 512], stage=3, block='a', trainable=trainable) x = identity_block(x, 3, [128, 128, 512], stage=3, block='b', trainable=trainable) x = identity_block(x, 3, [128, 128, 512], stage=3, block='c', trainable=trainable) stage3 = identity_block(x, 3, [128, 128, 512], stage=3, block='d', trainable=trainable) x = conv_block(stage3, 3, [256, 256, 1024], stage=4, block='a', trainable=trainable) x = identity_block(x, 3, [256, 256, 1024], stage=4, block='b', trainable=trainable) x = identity_block(x, 3, [256, 256, 1024], stage=4, block='c', trainable=trainable) x = identity_block(x, 3, [256, 256, 1024], stage=4, block='d', trainable=trainable) x = identity_block(x, 3, [256, 256, 1024], stage=4, block='e', trainable=trainable) stage4 = identity_block(x, 3, [256, 256, 1024], stage=4, block='f', trainable=trainable) x = conv_block(stage4, 3, [512, 512, 2048], stage=5, block='a', strides=(1, 1), dila=(2, 2), trainable=trainable) x = identity_block(x, 3, [512, 512, 2048], stage=5, block='b', dila=(2, 2), trainable=trainable) stage5 = identity_block(x, 3, [512, 512, 2048], stage=5, block='c', dila=(2, 2), trainable=trainable)
P3_up = Deconvolution2D(256, kernel_size=4, strides=2, padding='same', kernel_initializer='glorot_normal', name='P3up', trainable=trainable)(stage3) P4_up = Deconvolution2D(256, kernel_size=4, strides=4, padding='same', kernel_initializer='glorot_normal', name='P4up', trainable=trainable)(stage4) P5_up = Deconvolution2D(256, kernel_size=4, strides=4, padding='same', kernel_initializer='glorot_normal', name='P5up', trainable=trainable)(stage5)
P3_up = L2Normalization(gamma_init=10, name='P3norm')(P3_up) P4_up = L2Normalization(gamma_init=10, name='P4norm')(P4_up) P5_up = L2Normalization(gamma_init=10, name='P5norm')(P5_up) conc = Concatenate(axis=-1)([P3_up, P4_up, P5_up])
feat = Convolution2D(256, (3, 3), padding='same', kernel_initializer='glorot_normal', name='feat', trainable=trainable)(conc) feat = BatchNormalization(axis=bn_axis, name='bn_feat')(feat) feat = Activation('relu')(feat)
x_class = Convolution2D(1, (1, 1), activation='sigmoid', kernel_initializer='glorot_normal', bias_initializer=prior_probability_onecls(probability=0.01), name='center_cls', trainable=trainable)(feat) x_regr = Convolution2D(num_scale, (1, 1), activation='linear', kernel_initializer='glorot_normal', name='height_regr', trainable=trainable)(feat)
if offset: x_offset = Convolution2D(2, (1, 1), activation='linear', kernel_initializer='glorot_normal', name='offset_regr', trainable=trainable)(feat) return [x_class, x_regr, x_offset] else: return [x_class, x_regr]
|