Last active
May 27, 2020 19:57
-
-
Save Eligijus112/48955f9d08db1d12b4ec3aef3fd609ae to your computer and use it in GitHub Desktop.
An image classifier pipeline using conv and pooling
This file contains hidden or 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
import tensorflow as tf | |
# Initiating the class | |
mnist = tf.keras.datasets.fashion_mnist | |
# Downloading the data | |
(training_images, training_labels), (test_images, test_labels) = mnist.load_data() | |
# Reshaping the images for the convolutional input | |
training_images=training_images.reshape(60000, 28, 28, 1) | |
test_images = test_images.reshape(10000, 28, 28, 1) | |
# Normalizing the images | |
training_images=training_images / 255.0 | |
test_images=test_images/255.0 | |
# Adding the conv layer and max pooling layer | |
model = tf.keras.models.Sequential([ | |
# Convolutional layer | |
tf.keras.layers.Conv2D(16, (3,3), activation='relu', input_shape=(28, 28, 1)), | |
# Max pooling layer | |
tf.keras.layers.MaxPooling2D(2, 2), | |
tf.keras.layers.Flatten(), | |
tf.keras.layers.Dense(128, activation='relu'), | |
tf.keras.layers.Dense(10, activation='sigmoid') | |
]) | |
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) | |
# Getting the summary of the model | |
model.summary() | |
# Fiting the model | |
# Fitting the model | |
model.fit(training_images, training_labels, epochs=10) | |
# Evaluating accuracy | |
test_loss = model.evaluate(test_images, test_labels, verbose=False) | |
print(test_loss[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment