Skip to content

Instantly share code, notes, and snippets.

@Eligijus112
Last active May 27, 2020 19:57
Show Gist options
  • Save Eligijus112/48955f9d08db1d12b4ec3aef3fd609ae to your computer and use it in GitHub Desktop.
Save Eligijus112/48955f9d08db1d12b4ec3aef3fd609ae to your computer and use it in GitHub Desktop.
An image classifier pipeline using conv and pooling
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