Sequential()
,我只是把所有的东西都拿出来,一层一层地添加到
model
.
import tensorflow as tf
from tensorflow import keras
from keras.models import Sequential
from keras.layers import Dense
import numpy as np
from matplotlib.pyplot import show
import matplotlib.pyplot as plt
from matplotlib.pyplot import figure
from matplotlib.pyplot import imshow
from matplotlib.pyplot import colorbar
from matplotlib.pyplot import axis
from matplotlib.pyplot import plot
from matplotlib.pyplot import show
print(tf.__version__)
fashion_mnist = keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',
'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']
N1, N2, N3 = test_images.shape
train_images = train_images / 255.0
test_images = test_images / 255.0
model= Sequential()
model.add(Dense(128, activation=tf.nn.relu))
model.add(Dense(10, activation=tf.nn.softmax))
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model.fit(train_images.reshape(len(train_images),784), train_labels, epochs=5)
使用此代码,它的运行方式如下所示。
32/60000 [..............................] - 预计到达时间:3:02-损失:2.6468-
行政协调会:0
1344/60000 [..............................] - 预计到达时间:6秒-损失:1.3037-
行政协调会:0.5
2816/60000[>………]预计到达时间:4s-损失:1.0207-
4256/60000[=>……]-预计到达时间:3秒-损失:0.9073-
5632/60000[=>……]预计到达时间:2秒-损失:0.8394-
7104/60000[=>……]-预计到达时间:2秒-损失:0.7912-
行政协调会:0.7