Skip to content

Instantly share code, notes, and snippets.

@maxrohleder
Created February 7, 2021 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxrohleder/6c49f9c21a84757b1e57b2662d8f6377 to your computer and use it in GitHub Desktop.
Save maxrohleder/6c49f9c21a84757b1e57b2662d8f6377 to your computer and use it in GitHub Desktop.
this toy-resnet demonstrates the functional api of keras.
# taken from https://www.tensorflow.org/guide/keras/functional#a_toy_resnet_model
inputs = keras.Input(shape=(32, 32, 3), name="img")
x = layers.Conv2D(32, 3, activation="relu")(inputs)
x = layers.Conv2D(64, 3, activation="relu")(x)
block_1_output = layers.MaxPooling2D(3)(x)
x = layers.Conv2D(64, 3, activation="relu", padding="same")(block_1_output)
x = layers.Conv2D(64, 3, activation="relu", padding="same")(x)
block_2_output = layers.add([x, block_1_output])
x = layers.Conv2D(64, 3, activation="relu", padding="same")(block_2_output)
x = layers.Conv2D(64, 3, activation="relu", padding="same")(x)
block_3_output = layers.add([x, block_2_output])
x = layers.Conv2D(64, 3, activation="relu")(block_3_output)
x = layers.GlobalAveragePooling2D()(x)
x = layers.Dense(256, activation="relu")(x)
x = layers.Dropout(0.5)(x)
outputs = layers.Dense(10)(x)
model = keras.Model(inputs, outputs, name="toy_resnet")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment