-
Notifications
You must be signed in to change notification settings - Fork 0
/
ResNet.py
32 lines (24 loc) · 1.03 KB
/
ResNet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from tensorflow import keras
from keras.models import Model
from keras.layers import *
from keras.utils import conv_utils
from keras.engine.topology import get_source_inputs
from SE_Block import squeeze_excite_block
def resnet_block(input, filters, k=1, strides=(1, 1)):
init = input
channel_axis = -1
x = BatchNormalization(axis=channel_axis)(input)
x = Activation('relu')(x)
if strides != (1, 1) or init._keras_shape[channel_axis] != filters * k:
init = Conv2D(filters * k, (1, 1), padding='same', kernel_initializer='he_normal',
use_bias=False, strides=strides)(x)
x = Conv2D(filters * k, (3, 3), padding='same', kernel_initializer='he_normal',
use_bias=False, strides=strides)(x)
x = BatchNormalization(axis=channel_axis)(x)
x = Activation('relu')(x)
x = Conv2D(filters * k, (3, 3), padding='same', kernel_initializer='he_normal',
use_bias=False)(x)
# squeeze and excite block
x = squeeze_excite_block(x)
m = add([x, init])
return m