Skip to content
Snippets Groups Projects
Commit ee1d7f08 authored by nz11's avatar nz11
Browse files

make everything approxhpvm compatible

parent d0cbb1f2
No related branches found
No related tags found
No related merge requests found
...@@ -55,24 +55,22 @@ def _inverted_res_block(inputs, expansion, stride, alpha, filters, block_id): ...@@ -55,24 +55,22 @@ def _inverted_res_block(inputs, expansion, stride, alpha, filters, block_id):
# Expand # Expand
if block_id: if block_id:
x = Conv2D(expansion * in_channels, kernel_size=1, strides=1, padding='same', use_bias=False, activation=None, kernel_initializer="he_normal", kernel_regularizer=regularizers.l2(4e-5), name=prefix + 'expand')(x) x = Conv2D(expansion * in_channels, kernel_size=1, strides=1, padding='same', use_bias=False, activation=None, kernel_initializer="he_normal", kernel_regularizer=regularizers.l2(4e-5))(x)
x = BatchNormalization(epsilon=1e-3, momentum=0.999, name=prefix + 'expand_BN')(x) x = BatchNormalization(epsilon=1e-3, momentum=0.999)(x)
x = ReLU(6., name=prefix + 'expand_relu')(x) x = Activation('relu')(x)
else:
prefix = 'expanded_conv_'
# Depthwise # Depthwise
x = DepthwiseConv2D(kernel_size=3, strides=stride, activation=None, use_bias=False, padding='same', kernel_initializer="he_normal", depthwise_regularizer=regularizers.l2(4e-5), name=prefix + 'depthwise')(x) x = DepthwiseConv2D(kernel_size=3, strides=stride, activation=None, use_bias=False, padding='same', kernel_initializer="he_normal", depthwise_regularizer=regularizers.l2(4e-5))(x)
x = BatchNormalization(epsilon=1e-3, momentum=0.999, name=prefix + 'depthwise_BN')(x) x = BatchNormalization(epsilon=1e-3, momentum=0.999)(x)
x = ReLU(6., name=prefix + 'depthwise_relu')(x) x = Activation('relu')(x)
# Project # Project
x = Conv2D(pointwise_filters, kernel_size=1, strides=1, padding='same', use_bias=False, activation=None, kernel_initializer="he_normal", kernel_regularizer=regularizers.l2(4e-5), name=prefix + 'project')(x) x = Conv2D(pointwise_filters, kernel_size=1, strides=1, padding='same', use_bias=False, activation=None, kernel_initializer="he_normal", kernel_regularizer=regularizers.l2(4e-5))(x)
x = BatchNormalization(epsilon=1e-3, momentum=0.999, name=prefix + 'project_BN')(x) x = BatchNormalization(epsilon=1e-3, momentum=0.999)(x)
if in_channels == pointwise_filters and stride == 1: if in_channels == pointwise_filters and stride == 1:
return Add(name=prefix + 'add')([inputs, x]) return Add()([inputs, x])
return x return x
# build MobileNetV2 models # build MobileNetV2 models
...@@ -84,9 +82,9 @@ def get_mobilenetv2(alpha=1.0, depth_multiplier=1): ...@@ -84,9 +82,9 @@ def get_mobilenetv2(alpha=1.0, depth_multiplier=1):
img_input = Input(shape=input_shape) img_input = Input(shape=input_shape)
# model architechture # model architechture
x = Conv2D(first_block_filters, kernel_size=3, strides=1, padding='same', use_bias=False, kernel_initializer="he_normal", kernel_regularizer=regularizers.l2(4e-5), name='Conv1')(img_input) x = Conv2D(first_block_filters, kernel_size=3, strides=1, padding='same', use_bias=False, kernel_initializer="he_normal", kernel_regularizer=regularizers.l2(4e-5))(img_input)
#x = BatchNormalization(epsilon=1e-3, momentum=0.999, name='bn_Conv1')(x) #x = BatchNormalization(epsilon=1e-3, momentum=0.999)(x)
#x = ReLU(6., name='Conv1_relu')(x) #x = Activation('relu')(x)
x = _inverted_res_block(x, filters=16, alpha=alpha, stride=1, expansion=1, block_id=0 ) x = _inverted_res_block(x, filters=16, alpha=alpha, stride=1, expansion=1, block_id=0 )
...@@ -123,9 +121,9 @@ def get_mobilenetv2(alpha=1.0, depth_multiplier=1): ...@@ -123,9 +121,9 @@ def get_mobilenetv2(alpha=1.0, depth_multiplier=1):
last_block_filters = 1280 last_block_filters = 1280
x = Conv2D(last_block_filters, kernel_size=1, use_bias=False, kernel_initializer="he_normal", kernel_regularizer=regularizers.l2(4e-5), name='Conv_1')(x) x = Conv2D(last_block_filters, kernel_size=1, use_bias=False, kernel_initializer="he_normal", kernel_regularizer=regularizers.l2(4e-5))(x)
x = BatchNormalization(epsilon=1e-3, momentum=0.999, name='Conv_1_bn')(x) x = BatchNormalization(epsilon=1e-3, momentum=0.999)(x)
x = ReLU(6., name='out_relu')(x) x = Activation('relu')(x)
x = AveragePooling2D(pool_size=2)(x) x = AveragePooling2D(pool_size=2)(x)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment