Skip to content

Instantly share code, notes, and snippets.

@arkajyotiMukherjee
Created June 28, 2019 08:43
Show Gist options
  • Select an option

  • Save arkajyotiMukherjee/3e1053fe7f747f2c856f2c2758d88fe6 to your computer and use it in GitHub Desktop.

Select an option

Save arkajyotiMukherjee/3e1053fe7f747f2c856f2c2758d88fe6 to your computer and use it in GitHub Desktop.
# Make an input tensor
inputs = tf.keras.Input(shape=(28,28,1))
# A layer instance is callable on a tensor, and returns a tensor.
x = layers.Conv2D(filters=32, kernel_size=(3,3), strides=2, activation='relu')(inputs)
# We have to provide the input for each layer manually
# This is how we can make arbitrary connections
x = layers.Conv2D(filters=64, kernel_size=(3,3),strides= 2, activation='relu')(x)
# Notice how we are using the same variable x, as python performs the operation first then the assignment
x = layers.Conv2D(filters=64, kernel_size=(3,3),strides=2, padding='same', activation='relu')(x)
x = layers.Flatten()(x)
x = layers.Dense(128, activation='relu')(x)
# This is the output tensor
preds = layers.Dense(10, activation='softmax')(x)
# Now we pass the input and output tensors to the tf.keras.Model instance
model = tf.keras.Model(inputs=inputs, outputs=preds)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment