import tensorflow as tf
from tensorflow import keras
tf.__version__
'2.1.0'
keras.__version__
'2.2.4-tf'
使用Keras加载数据集
fashion_mnist = keras.datasets.fashion_mnist
(X_train_full,y_train_full),(X_test,y_test) = fashion_mnist.load_data()
X_train_full.shape
(60000, 28, 28)
X_train_full.dtype
dtype('uint8')
X_vaild,X_train = X_train_full[:5000]/255.0,X_train_full[5000:]/255.0
y_vaild,y_train = y_train_full[:5000],y_train_full[5000:]
class_names = ["T-shirt/top","Trouser","Pullover","Dress","Coat","Sandal","Shirt","Sneaker","Bag","Ankle boot"]
使用顺序API创建模型
model = keras.models.Sequential()
model.add(keras.layers.Flatten(input_shape=[28,28]))
model.add(keras.layers.Dense(300,activation="relu"))