The method of using the (fashion-)mnist dataset offline (solve the error message: EOFError: Compressed file ended before the end-of-stream marker wa

Reference blog: https://www.cnblogs.com/qiutenglong/archive/2019/07/07/11146357.html
There is one point that is not mentioned in the blog, here is an addition: Note that you must create a new folder not called "datasets" , then there will be no error

tensorflow can download mnist (or fashion-mnist data set) through the code:

import tensorflow as tf
from tensorflow import keras
fashion_mnist = keras.datasets.fashion_mnist
(train_images,train_labels),(test_images,test_labels) = fashion_mnist.load_data()

You can download the fashion_mnist data set from the Internet, and after running this code once, an error will be reported when you run it again: EOFError: Compressed file ended before the end-of-stream marker was reached, because it cannot be downloaded repeatedly.
The general idea is to read the file directly... What is the error? = =
I want to prevent this error. The idea is to use this data set offline and test fashion-mnist. Mnist should be the same

From the error message, you can see that he will run a py file, fashion-mnist.py , which allows tensorflow to download the fashion-mnist dataset online, which is at: /home/wolfy/.local/lib/python3.5/site -In packages/tensorflow/python/keras/_impl/keras/datasets,
note that if .local is not found, it is hidden. Use ctr+h to display hidden files in ubuntu. Open
this file and you can see the following code:
insert image description here
the code inside dirname = os.path.join('datasets', 'fashion-mnist') is downloaded to /home/wolfy/.keras/datasets by default

Here it is found that if the code is changed to dirname = os.path.join('new_datasets/fashion-mnist'),
no error will be reported (as long as it is not called datasets), reaching "download if there is no dataset, and restart with the dataset No error will be reported after running the code, but the effect of using this data set directly
so that it can be used offline

Guess you like

Origin blog.csdn.net/Only_Wolfy/article/details/97935867