Skip to content

Instantly share code, notes, and snippets.

@adekunleba
Created November 23, 2018 12:57
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 adekunleba/8ba24de4f47ce93cf161bdc4f07303d3 to your computer and use it in GitHub Desktop.
Save adekunleba/8ba24de4f47ce93cf161bdc4f07303d3 to your computer and use it in GitHub Desktop.
dataset = generate(tfrecordfiles)
IM_SIZE = 224 # image size
image_input = tf.keras.Input(shape=(IM_SIZE, IM_SIZE, 3), name='input_layer')
# Some convolutional layers
conv_1 = tf.keras.layers.Conv2D(32,
kernel_size=(3, 3),
padding='same',
activation='relu')(image_input)
conv_1 = tf.keras.layers.MaxPooling2D(padding='same')(conv_1)
conv_2 = tf.keras.layers.Conv2D(32,
kernel_size=(3, 3),
padding='same',
activation='relu')(conv_1)
conv_2 = tf.keras.layers.MaxPooling2D(padding='same')(conv_2)
# Flatten the output of the convolutional layers
conv_flat = tf.keras.layers.Flatten()(conv_2)
# Some dense layers with two separate outputs
fc_1 = tf.keras.layers.Dense(128,
# activation='relu')(conv_flat)
fc_1 = tf.keras.layers.Dropout(0.2)(fc_1)
fc_2 = tf.keras.layers.Dense(128,
activation='relu')(fc_1)
fc_2 = tf.keras.layers.Dropout(0.2)(fc_2)
# Output layers: separate outputs for the weather and the ground labels
output = tf.keras.layers.Dense(2,
activation='softmax',
name='weather')(fc_2)
final_model = tf.keras.Model(inputs=image_input, outputs=[output])
final_model.compile(optimizer='adam',
loss="categorical_crossentropy",
metrics=['accuracy'])
final_model.summary()
print("Training model")
final_model.fit(dataset, epochs=2, steps_per_epoch=10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment