|
import tensorflow as tf |
|
from tensorflow import keras |
|
|
|
|
|
|
|
mnist = keras.datasets.fashion_mnist.load_data() |
|
|
|
(x_train,y_train),(x_test,y_test) = mnist |
|
|
|
import numpy as np |
|
|
|
|
|
np.min(x_train), np.min(x_train) |
|
|
|
|
|
class_names = ['top', 'trouser', 'pullover', 'dress', ' coat', 'sandal', 'shirt', 'sneaker', 'bag', 'ankle boot'] |
|
|
|
|
|
|
|
X_train = x_train/255.0 |
|
X_test = x_test/255.0 |
|
|
|
from keras import Sequential as Sequ |
|
from tensorflow.keras.layers import Flatten, Dense |
|
|
|
model = Sequ() |
|
|
|
model.add(Flatten(input_shape=(28,28))) |
|
|
|
model.add(Dense(128, activation='relu')) |
|
model.add(Dense(256, activation='relu')) |
|
|
|
|
|
model.add(Dense(10, activation='softmax')) |
|
|
|
print(model.summary()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) |
|
|
|
|
|
model_checkpoint_best_callback = keras.callbacks.ModelCheckpoint( |
|
filepath = '../my_models/fashion_model.keras', |
|
monitor = 'val_loss', |
|
verbose = 1, |
|
save_best_only = False, |
|
save_weights_only = False |
|
) |
|
model.fit(X_train, y_train, epochs=10, batch_size=32, callbacks=[model_checkpoint_best_callback]) |
|
|
|
|