Skip to content

Commit

Permalink
fix padding
Browse files Browse the repository at this point in the history
  • Loading branch information
Nguyendat-bit committed Oct 30, 2021
1 parent 3b4b703 commit f8dce5c
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@ def __init__(self,*, classes, alpha = 1.0, rho = 1.0, droppout = 0.001, img_size
self.model = None
self._droppout = droppout
self.img_size = img_size
def _correct_padding(self, inp_shape):
return int((((inp_shape[1] - 1) * 2 + 3 ) - inp_shape[1]) / 2)
def __Standard_Conv(self):
return models.Sequential([
Conv2D(filters= 32, kernel_size=(3,3), strides= (2,2), padding= 'valid'),
BatchNormalization(),
Activation('relu')
])

def __Depthwise_Conv(self, strides):
def __Depthwise_Conv(self, strides, padding):
return models.Sequential([
DepthwiseConv2D(kernel_size= (3,3), strides= strides, padding= 'same' if strides == (1,1) else 'valid'),
DepthwiseConv2D(kernel_size= (3,3), strides= strides, padding= padding),
BatchNormalization(),
Activation('relu')
])
Expand All @@ -35,9 +33,9 @@ def __Pointwise_Conv(self, filters):

])

def __Depthwise_Separable_Conv( self,*, strides_depthwise, filters_pointwise):
def __Depthwise_Separable_Conv( self,*, strides_depthwise, padding_depthwise, filters_pointwise):
return models.Sequential([
self.__Depthwise_Conv(strides= strides_depthwise),
self.__Depthwise_Conv(strides= strides_depthwise, padding= padding_depthwise),
self.__Pointwise_Conv(filters= filters_pointwise)
])

Expand All @@ -51,29 +49,28 @@ def build(self):
self.__Standard_Conv(),

# Depth_Separable_Conv 1
self.__Depthwise_Separable_Conv(strides_depthwise= (1,1), filters_pointwise= 64),
self.__Depthwise_Separable_Conv(strides_depthwise= (1,1), padding_depthwise= 'same',filters_pointwise= 64),
# Depth_Separable_Conv 2
self.__Depthwise_Separable_Conv(strides_depthwise= (2,2), filters_pointwise= 128),
self.__Depthwise_Separable_Conv(strides_depthwise= (2,2), padding_depthwise= 'valid', filters_pointwise= 128),
# Depth_Separable_Conv 3
self.__Depthwise_Separable_Conv(strides_depthwise= (1,1), filters_pointwise= 128),
self.__Depthwise_Separable_Conv(strides_depthwise= (1,1), padding_depthwise= 'same', filters_pointwise= 128),
# Depth_Separable_Conv 4
self.__Depthwise_Separable_Conv(strides_depthwise= (2,2), filters_pointwise= 256),
self.__Depthwise_Separable_Conv(strides_depthwise= (2,2), padding_depthwise= 'valid', filters_pointwise= 256),
# Depth_Separable_Conv 5
self.__Depthwise_Separable_Conv(strides_depthwise= (1,1), filters_pointwise= 256),
self.__Depthwise_Separable_Conv(strides_depthwise= (1,1), padding_depthwise= 'same', filters_pointwise= 256),
# Depth_Separable_Conv 6
self.__Depthwise_Separable_Conv(strides_depthwise= (2,2), filters_pointwise= 512),
self.__Depthwise_Separable_Conv(strides_depthwise= (2,2), padding_depthwise= 'valid', filters_pointwise= 512),
# Depth_Separable_Conv 7 - > 11
self.__Depthwise_Separable_Conv(strides_depthwise= (1,1), filters_pointwise= 512),
self.__Depthwise_Separable_Conv(strides_depthwise= (1,1), filters_pointwise= 512),
self.__Depthwise_Separable_Conv(strides_depthwise= (1,1), filters_pointwise= 512),
self.__Depthwise_Separable_Conv(strides_depthwise= (1,1), filters_pointwise= 512),
self.__Depthwise_Separable_Conv(strides_depthwise= (1,1), filters_pointwise= 512),
self.__Depthwise_Separable_Conv(strides_depthwise= (1,1), padding_depthwise= 'same', filters_pointwise= 512),
self.__Depthwise_Separable_Conv(strides_depthwise= (1,1), padding_depthwise= 'same', filters_pointwise= 512),
self.__Depthwise_Separable_Conv(strides_depthwise= (1,1), padding_depthwise= 'same', filters_pointwise= 512),
self.__Depthwise_Separable_Conv(strides_depthwise= (1,1), padding_depthwise= 'same', filters_pointwise= 512),
self.__Depthwise_Separable_Conv(strides_depthwise= (1,1), padding_depthwise= 'same', filters_pointwise= 512),
# Depth_Separable_Conv 12
self.__Depthwise_Separable_Conv(strides_depthwise= (2,2), filters_pointwise= 1024),
ZeroPadding2D(padding= self._correct_padding),
self.__Depthwise_Separable_Conv(strides_depthwise= (2,2), padding_depthwise= 'valid', filters_pointwise= 1024),

# Depth_Separable_Conv 13
self.__Depthwise_Separable_Conv(strides_depthwise= (2,2), filters_pointwise= 1024),
self.__Depthwise_Separable_Conv(strides_depthwise= (2,2), padding_depthwise= 'same', filters_pointwise= 1024),
GlobalAveragePooling2D(),

# FC
Expand Down

0 comments on commit f8dce5c

Please sign in to comment.