From a13b3e5a909a582988f0931b7c18af97d94c4cc7 Mon Sep 17 00:00:00 2001 From: "bmanderson@mdanderson.org" Date: Thu, 19 Mar 2020 23:31:38 -0500 Subject: [PATCH] update to be elu instead of relu, drop dropout --- model.py | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/model.py b/model.py index 4282ffa..c7fd834 100644 --- a/model.py +++ b/model.py @@ -72,17 +72,17 @@ def SepConv_BN(x, filters, prefix, stride=1, kernel_size=3, rate=1, depth_activa depth_padding = 'valid' if not depth_activation: - x = Activation('relu')(x) + x = Activation('elu')(x) x = DepthwiseConv2D((kernel_size, kernel_size), strides=(stride, stride), dilation_rate=(rate, rate), padding=depth_padding, use_bias=False, name=prefix + '_depthwise')(x) x = BatchNormalization(name=prefix + '_depthwise_BN', epsilon=epsilon)(x) if depth_activation: - x = Activation('relu')(x) + x = Activation('elu')(x) x = Conv2D(filters, (1, 1), padding='same', use_bias=False, name=prefix + '_pointwise')(x) x = BatchNormalization(name=prefix + '_pointwise_BN', epsilon=epsilon)(x) if depth_activation: - x = Activation('relu')(x) + x = Activation('elu')(x) return x @@ -274,11 +274,11 @@ def Deeplabv3(weights='pascal_voc', input_tensor=None, input_shape=(512, 512, 3) x = Conv2D(32, (3, 3), strides=(2, 2), name='entry_flow_conv1_1', use_bias=False, padding='same')(img_input) x = BatchNormalization(name='entry_flow_conv1_1_BN')(x) - x = Activation('relu')(x) + x = Activation('elu')(x) x = _conv2d_same(x, 64, 'entry_flow_conv1_2', kernel_size=3, stride=1) x = BatchNormalization(name='entry_flow_conv1_2_BN')(x) - x = Activation('relu')(x) + x = Activation('elu')(x) x = _xception_block(x, [128, 128, 128], 'entry_flow_block1', skip_connection_type='conv', stride=2, @@ -367,15 +367,14 @@ def Deeplabv3(weights='pascal_voc', input_tensor=None, input_shape=(512, 512, 3) b4 = Conv2D(256, (1, 1), padding='same', use_bias=False, name='image_pooling')(b4) b4 = BatchNormalization(name='image_pooling_BN', epsilon=1e-5)(b4) - b4 = Activation('relu')(b4) + b4 = Activation('elu')(b4) # upsample. have to use compat because of the option align_corners size_before = K.int_shape(x) - b4 = Lambda(lambda x: tf.compat.v1.image.resize(x, size_before[1:3], - method='bilinear', align_corners=True))(b4) + b4 = Lambda(lambda x: tf.compat.v1.image.resize_bilinear(x, size_before[1:3],align_corners=True))(b4) # simple 1x1 b0 = Conv2D(256, (1, 1), padding='same', use_bias=False, name='aspp0')(x) b0 = BatchNormalization(name='aspp0_BN', epsilon=1e-5)(b0) - b0 = Activation('relu', name='aspp0_activation')(b0) + b0 = Activation('elu', name='aspp0_activation')(b0) # there are only 2 branches in mobilenetV2. not sure why if backbone == 'xception': @@ -397,22 +396,21 @@ def Deeplabv3(weights='pascal_voc', input_tensor=None, input_shape=(512, 512, 3) x = Conv2D(256, (1, 1), padding='same', use_bias=False, name='concat_projection')(x) x = BatchNormalization(name='concat_projection_BN', epsilon=1e-5)(x) - x = Activation('relu')(x) - x = Dropout(0.1)(x) + x = Activation('elu')(x) + # x = Dropout(0.1)(x) # DeepLab v.3+ decoder if backbone == 'xception': # Feature projection # x4 (x2) block size_before2 = tf.keras.backend.int_shape(x) - x = Lambda(lambda xx: tf.compat.v1.image.resize(xx, - skip1.shape[1:3], - method='bilinear', align_corners=True))(x) + x = Lambda(lambda xx: tf.compat.v1.image.resize_bilinear(xx, + skip1.shape[1:3], align_corners=True))(x) dec_skip1 = Conv2D(48, (1, 1), padding='same', use_bias=False, name='feature_projection0')(skip1) dec_skip1 = BatchNormalization( name='feature_projection0_BN', epsilon=1e-5)(dec_skip1) - dec_skip1 = Activation('relu')(dec_skip1) + dec_skip1 = Activation('elu')(dec_skip1) x = Concatenate()([x, dec_skip1]) x = SepConv_BN(x, 256, 'decoder_conv0', depth_activation=True, epsilon=1e-5) @@ -427,9 +425,8 @@ def Deeplabv3(weights='pascal_voc', input_tensor=None, input_shape=(512, 512, 3) x = Conv2D(classes, (1, 1), padding='same', name=last_layer_name)(x) size_before3 = tf.keras.backend.int_shape(img_input) - x = Lambda(lambda xx: tf.compat.v1.image.resize(xx, - size_before3[1:3], - method='bilinear', align_corners=True))(x) + x = Lambda(lambda xx: tf.compat.v1.image.resize_bilinear(xx, + size_before3[1:3], align_corners=True))(x) # Ensure that the model takes into account # any potential predecessors of `input_tensor`.