Untitled
3 years ago in Plain Text
from tensorflow.keras import Sequential
from tensorflow.keras.layers import Conv2D, Flatten, Dense, AvgPool2D
import matplotlib.pyplot as plt
import numpy as np
features_train = np.load('/datasets/fashion_mnist/train_features.npy')
target_train = np.load('/datasets/fashion_mnist/train_target.npy')
features_test = np.load('/datasets/fashion_mnist/test_features.npy')
target_test = np.load('/datasets/fashion_mnist/test_target.npy')
features_train = features_train.reshape(-1, 28, 28, 1) / 255.0
features_test = features_test.reshape(-1, 28, 28, 1) / 255.0
model = Sequential()
model.add(Conv2D(6, (5, 5), padding='same', activation='tanh',
input_shape=(28, 28, 1)))
model.add(AvgPool2D(pool_size=(2, 2)))
model.add(Conv2D(16, (5, 5), padding='valid', activation='tanh'))
model.add(AvgPool2D(pool_size=(2, 2)))
model.add(Flatten())
model.add(Dense(120, activation='tanh'))
model.add(Dense(84, activation='tanh'))
model.add(Dense(10, activation='softmax'))
model.compile(loss='sparse_categorical_crossentropy', optimizer='sgd', metrics=['acc'])
model.summary()
model.fit(features_train, target_train, epochs=1, verbose=1,
steps_per_epoch=1, batch_size=1)