👚⚙️ A fashion-item classifier developed with TensorFlow 2.0.0
A fashion item classifier developed with TensorFlow 2.0.0 and Keras.
It is based of the popular fashion_mnist
dataset of Keras:
It’s important install TensorFlow 2.0.0 with PIP using:
pip install tensorflow==2.0.0-alpha0
Then install other libraries like:
With its latest version using PIP.
Load MNIST Fashion-item dataset:
data = keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = data.load_data()
The dataset split train_images
and test_images
are numpy type array with 784 numbers from 0 to 255. These arrays can be converted into images of 28 by 28 pixels (that’s why 784 numbers).
Then reduce the data dividing by 225, beacuse is a good practice shrink our data. Now the values of 225 is equal to 1.0 and so on:
train_images = train_images / 255.0
test_images = test_images / 255.0
Based on the labels for each fashion item, create a list for ten elements:
class_names = ['T-shirt/top',
'Trouser',
'Pullover',
'Dress',
'Coat',
'Sandal',
'Shirt',
'Sneaker',
'Bag',
'Ankle boot']
Using Sequential
class from Keras and add layers.
model = keras.Sequential([
keras.layers.Flatten(input_shape=(28, 28)),
keras.layers.Dense(128, activation="relu"),
keras.layers.Dense(10, activation="softmax")
])
Using compile
method of Sequential
using the necessary parameters:
adam
, an optimizing algorithm.sparse_categorical_crossentropy
model.compile(
optimizer="adam",
loss="sparse_categorical_crossentropy",
metrics=["accuracy"]
)