-
Notifications
You must be signed in to change notification settings - Fork 0
/
ResNet.py
42 lines (31 loc) · 1.26 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
33
34
35
36
37
38
39
40
41
import numpy as np
from keras import layers
import keras.backend as K
def Resnet_v1(x,output_filters):
input_filters=x._keras_shape[-1]
res_x=layers.Conv2D(filters=output_filters,kernel_size=(3,3),padding='same')(x)
res_x=layers.BatchNormalization()(res_x)
res_x=layers.ReLU()(res_x)
res_x=layers.Conv2D(filters=output_filters,kernel_size=(3,3),padding='same')(res_x)
res_x=layers.BatchNormalization()(res_x)
if input_filters == output_filters:
pass
else:
x=layers.Conv2D(filters=output_filters,kernel_size=(1,1),padding='same')(x)
output=layers.add([x,res_x])
output=layers.ReLU()(output)
return output
def Resnet_v2(x,output_filters):
input_filters=x._keras_shape[-1]
res_x = layers.BatchNormalization()(x)
res_x = layers.ReLU()(res_x)
res_x = layers.Conv2D(filters=output_filters, kernel_size=(3, 3), padding='same')(res_x)
res_x = layers.BatchNormalization()(res_x)
res_x = layers.ReLU()(res_x)
res_x = layers.Conv2D(filters=output_filters, kernel_size=(3, 3), padding='same')(res_x)
if input_filters == output_filters:
pass
else:
x = layers.Conv2D(filters=output_filters, kernel_size=(1, 1), padding='same')(x)
output = layers.add([x, res_x])
return output