Skip to content

Instantly share code, notes, and snippets.

@johnolafenwa
Last active April 25, 2018 09:08
Show Gist options
  • Save johnolafenwa/406b08431474d200193f8d3093aea051 to your computer and use it in GitHub Desktop.
Save johnolafenwa/406b08431474d200193f8d3093aea051 to your computer and use it in GitHub Desktop.
# A single resnet module consisting of 1 x 1 conv - 3 x 3 conv and 1 x 1 conv
def resnet_identity_module(x, filters, pool=False):
res = x
stride = 1
if pool:
stride = 2
res = Conv2D(filters, kernel_size=1, strides=2, padding="same")(res)
x = BatchNormalization()(x)
x = Activation("relu")(x)
x = Conv2D(int(filters / 4), kernel_size=1, strides=stride, padding="same")(x)
x = BatchNormalization()(x)
x = Activation("relu")(x)
x = Conv2D(int(filters / 4), kernel_size=3, strides=1, padding="same")(x)
x = BatchNormalization()(x)
x = Activation("relu")(x)
x = Conv2D(filters, kernel_size=1, strides=1, padding="same")(x)
x = add([x, res])
return x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment