我刚刚开始编写神经网络和代码si,如下所示
#create model
model = keras.Sequential([
keras.layers.Flatten(input_shape=(28,28)),
keras.layers.Dense(16, activation="relu"),
keras.layers.Dense(16, activation="relu"),
keras.layers.Dense(10, activation="softmax")
])
model.compile(optimizer="adam",
loss="sparse_categorical_crossentropy",
metrics=["accuracy"])
#train model
history = model.fit(x_train, y_train, epochs=5)
但是,我如何查看我的模型的训练样本有误。印刷历史给了我<tensorflow.python.keras.callbacks.History object at 0x000000001CCAB2B0>
您可以model.predict
用来预测图像上的标签。因此,对于训练图像,您可以执行以下操作:
import numpy as np
y_probabilities = model.predict(x_train)
y_pred = np.array([np.argmax(probs) for probs in y_probs]
然后比较y_pred
用y_train
。例如
np.where(y_pred != y_train)[0]
将为您提供一个numpy数组,其中包含模型出错的所有图像索引。请参阅此Keras教程以获取更多详细信息。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句