引发 EOFError("压缩文件在" EOFError:压缩文件在到达流结束标记之前结束")



每次我尝试运行使用fashion_mist的程序时,它都会返回这个错误:

raise EOFError('Compressed file ended before the " EOFError: Compressed file ended before the end-of-stream marker was reached')

我代码:

import tensorflow as tf
from tensorflow import keras
shoe = "shoe.png"
fashion_mnist = keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
model = 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)
])
model.fit(train_images, train_labels, epochs=5)
test_loss, test_acc = model.evaluate(test_images, test_labels)
predictions = model.predict(shoe)

我试着重新安装tensorflow,看看我是否只是有一个过时的版本,但这不起作用

之后,我尝试重新安装fashion_mnist数据集。

您正在传递一个字符串给predict()而不是一个图像数组。请先加载图像并将其转换为数组。然后将其传递给predict()方法,如下所示

shoe=tf.keras.utils.load_img("/content/shoe.jpeg")
shoe=tf.keras.utils.img_to_array(shoe)
shoe=tf.image.rgb_to_grayscale(shoe)
shoe=np.resize(shoe,(1, 28,28,1))
predictions=model.predict(shoe)
print(predictions) 

另外,你必须在训练/测试之前编译你的模型。

model.compile('adam','sparse_categorical_crossentropy', metrics='acc' )

请在这里找到工作代码。谢谢你!

相关内容

  • 没有找到相关文章

最新更新