Skip to content

Commit

Permalink
update to be elu instead of relu, drop dropout
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmanderson committed Mar 20, 2020
1 parent ccd11a6 commit a13b3e5
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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':
Expand All @@ -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)
Expand All @@ -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`.
Expand Down

0 comments on commit a13b3e5

Please sign in to comment.