Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

This error while downloading datasets: ValueError: I/O operation on closed file

I have started with deep learning with Theano and Keras. However, for any program, I will have to load the dataset, and i'm not able to load any dataset.

Even if I run these two lines:-

from keras.datasets import cifar10
(X_train, y_train), (X_test, y_test) = cifar10.load_data()

I even tried the above with minst dataset. Exact same error.

I tried to run the commands one by one, the first import goes well. In the second command, it runs and python begins downloading. However, after a few seconds, it breaks.

This is the exact error:-

(X_train, y_train), (X_test, y_test) = cifar10.load_data() Downloading data from http://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz
8929280/170498071 [>.............................] - ETA: 82sTraceback (most recent call last):

File "", line 1, in (X_train, y_train), (X_test, y_test) = cifar10.load_data()

File "C:\Users\Aseem\Anaconda3\envs\AnacondaAseem\lib\site-packages\keras\datasets\cifar10.py", line 11, in load_data path = get_file(dirname, origin=origin, untar=True)

File "C:\Users\Aseem\Anaconda3\envs\AnacondaAseem\lib\site-packages\keras\utils\data_utils.py", line 76, in get_file raise e

ValueError: I/O operation on closed file

I do not know why this is happening. Seems like something is wrong in the file data_utils.py

What do I do?

like image 520
Aseem Ahir Avatar asked Apr 23 '16 01:04

Aseem Ahir


People also ask

How do I fix ValueError IO operation on a closed file in Python?

The Python "ValueError: I/O operation on closed file" occurs when we try to perform an operation on a closed file. To solve the error, make sure to indent the code that tries to access the file correctly if using the with open() statement.

What does I O operation on closed file means?

The “ValueError : I/O operation on closed file” error is raised when you try to read from or write to a file that has been closed. If you are using a with statement, check to make sure that your code is properly indented.

What happens if you try to read from a closed file in Python?

Can I read/write on a closed file in python? No, you can't read and write on a closed file. If you try to do so, it will raise a ValueError. You can only perform read and write operations when the file is opened.


1 Answers

I tried your exact code and it works fine on my computer. The failure could be due to several reasons, like a unstable internet connection or not enough free space in your home folder.

What you can do is to download the file manually using a download manager, put it in ~/.keras/datasets and rename it to cifar-10-batches-py.tar.gz and run the code again, it should pick up the file and continue processing from there.

like image 192
Dr. Snoopy Avatar answered Sep 27 '22 20:09

Dr. Snoopy