实现多层神经网络进行时装分类遇到一个问题,不知道怎么解决
from tensorflow import keras
import tensorflow as tf
from tensorflow.keras import datasets, layers, models
# 构建双层神经网络去进行时装模型训练与预测
# -读取数据集
# # # -建立神经网络模型
# # # -编译模型优化器、损失、准确率
# # # -进行fit训练
# # # -评估模型测试效果
class SingleNN(object):
# 建立网络模型
keras.Sequential([
keras.layers.Flatten(input_shape=(28, 28)),
keras.layers.Dense(128, activation=tf.nn.relu),
keras.layers.Dense(10, activation=tf.nn.softmax)
])
def __init__(self):
# 返回两个元组
(x_train, y_train), (x_test, y_test) = keras.datasets.fashion_mnist.load_data()
def singlenn_compile(self):
SingleNN.model.compile(optimizer=keras.optimizers.SGD(lr=0.01),
loss=keras.losses.sparse_categorical_crossentropy,
mmetrics=['accuracy'])
return None
def singlenn_fit(self):
SingleNN.model.fit(self.x_train, self.y_train, epochs=5)
return None
def single_evalute(self):
test_loss, test_acc = SingleNN.model.evaluate(self.x_train, self.y_train)
print(test_loss, test_acc)
return None
if __name__ == '__main__':
snn = SingleNN()
snn.singlenn_compile()
snn.singlenn_fit()
snn.singlenn_evalute()
pass