Created
March 17, 2019 13:15
-
-
Save himanshurawlani/1fdf2d149b0a415849ee42cbda266be0 to your computer and use it in GitHub Desktop.
Building a simple CNN using tf.keras functional API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tensorflow import keras | |
# Creating a simple CNN model in keras using functional API | |
def create_model(): | |
img_inputs = keras.Input(shape=IMG_SHAPE) | |
conv_1 = keras.layers.Conv2D(32, (3, 3), activation='relu')(img_inputs) | |
maxpool_1 = keras.layers.MaxPooling2D((2, 2))(conv_1) | |
conv_2 = keras.layers.Conv2D(64, (3, 3), activation='relu')(maxpool_1) | |
maxpool_2 = keras.layers.MaxPooling2D((2, 2))(conv_2) | |
conv_3 = keras.layers.Conv2D(64, (3, 3), activation='relu')(maxpool_2) | |
flatten = keras.layers.Flatten()(conv_3) | |
dense_1 = keras.layers.Dense(64, activation='relu')(flatten) | |
output = keras.layers.Dense(metadata.features['label'].num_classes, activation='softmax')(dense_1) | |
model = keras.Model(inputs=img_inputs, outputs=output) | |
return model |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to call create_model
Is it
x = create_model()
y = x(image)