Skip to content

Instantly share code, notes, and snippets.

@Eligijus112
Last active May 25, 2020 05:43
Show Gist options
  • Save Eligijus112/ee1433ba5990790e2dd95b88ffa6480f to your computer and use it in GitHub Desktop.
Save Eligijus112/ee1433ba5990790e2dd95b88ffa6480f to your computer and use it in GitHub Desktop.
A very simple classifier for the fashion mnist dataset
# Importing the packages
import tensorflow as tf
# Downloading data
# The default split is 60k images in the training set and 10k in the test set
mnist = tf.keras.datasets.fashion_mnist
(training_images, training_labels), (test_images, test_labels) = mnist.load_data()
# Normalizing the pixel values
training_images = training_images / 255.0
test_images = test_images / 255.0
# Defining a basic NN
model = tf.keras.models.Sequential(
[
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(256, activation=tf.nn.relu),
tf.keras.layers.Dense(10, activation=tf.nn.softmax)
]
)
# Compiliing and fitting
model.compile(
optimizer = tf.optimizers.Adam(),
loss = 'sparse_categorical_crossentropy',
metrics=['accuracy']
)
model.fit(training_images, training_labels, epochs=5)
# Printing the accuracy
print(model.evaluate(test_images, test_labels, verbose=False)[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment