简体   繁体   中英

Modifying maxpooling layer in Resnet50 keras.applications

I am working on a segmentation project and was wondering if there is a way to modify the resent50 maxpooling layer in keras.application. I'm using keras.application in a Kaggle kernel and was wondering if I could update the layer through code.

x = ZeroPadding2D(padding=(3, 3), name='conv1_pad')(img_input)
x = Conv2D(64, (7, 7), strides=(2, 2), name='conv1')(img_input)
x = BatchNormalization(axis=bn_axis, name='bn_conv1')(x)
x = Activation('relu')(x)
x = MaxPooling2D((3, 3), strides=(2, 2))(x)

to:

x = Conv2D(64, (7, 7), strides=(2, 2), padding='same', name='conv1')(img_input)
x = BatchNormalization(axis=bn_axis, name='bn_conv1')(x)
x = Activation('relu')(x)
x = MaxPooling2D((3, 3), strides=(2, 2), padding = 'same')(x)

You can always copy the source code and create alternative versions.

Copy the source code for resnet, rename the class to CustomResnet and change what you want.

From my experience with segmentation, though, this will not help you much if you intend to use it with variable sizes, because at the time you perform the UpSamplings, you will not know the original size of the image. So the UpSamplings will often end up bigger than the original.

Now, if you're working with fixed sizes, OK, you can end up finding a way of padding properly inside the model.

But I really suggest you count the amount of MaxPooling layers and make sure your input images sizes are multiples of 2^poolingLayers .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM