简体   繁体   English

使用 keras 的时尚 MNIST

[英]Fashion-MNIST using keras

Code:代码:

import keras.datasets.fashion_mnist as fashion_mnist
import keras
import matplotlib.pyplot as plt
from keras.utils import np_utils
from sklearn.model_selection import train_test_split
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data() 
xtrain, xvalid, ytrain, yvalid = train_test_split(train_images, train_labels, test_size=0.33, shuffle= True)

xtrain = xtrain / 255.0
xvalid =  xvalid/255.0
ytrain = np_utils.to_categorical(ytrain )
yvalid = np_utils.to_categorical(yvalid)

history_dict = history.history
print(history_dict.keys())

history=model1.fit(train_images, train_labels, epochs=30, batch_size=64)

loss = history.history['loss']
val_loss = history.history['val_loss']

accuracy = history.history['binary_accuracy']
val_accuracy = history.history['val_accuracy']

plt.plot(history.history['accuracy'])  
plt.plot(history.history['val_accuracy'])
plt.plot(history.history['loss'])
plt.plot(history.history['val_loss'])
plt.show()

I get the following result,: KeyError: 'val_accuracy ' ,, I use google.colab. dict_keys(['loss', 'accuracy'])我得到以下结果: KeyError: 'val_accuracy ' ,我使用google.colab. dict_keys(['loss', 'accuracy']) google.colab. dict_keys(['loss', 'accuracy']) , only two variables are available. google.colab. dict_keys(['loss', 'accuracy']) ,只有两个变量可用。 how to reach val_accuracy and val_loss?如何达到 val_accuracy 和 val_loss?

Any suggestions would be appreciated任何建议,将不胜感激

To need to have val_accuracy and val_loss , you need to supply validation data to the model.fit .需要有val_accuracyval_loss ,你需要验证的数据提供给model.fit Try this:尝试这个:

history = model1.fit(train_images, train_labels, 
                  validation_data = (xvalid,yvalid), 
                  epochs=30, batch_size=64)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM