1

I'm trying to download MNIST dataset on GPU of google colaboratory. But it is showing me "ConnectionResetError: [Errno 104] Connection reset by peer" error message.

from sklearn.datasets import fetch_mldata
dataset = fetch_mldata('MNIST original')
data = dataset.data

And the following error I'm getting:

/usr/local/lib/python3.6/dist-packages/sklearn/utils/deprecation.py:85: DeprecationWarning: Function fetch_mldata is deprecated; fetch_mldata was deprecated in version 0.20 and will be removed in version 0.22. Please use fetch_openml.
  warnings.warn(msg, category=DeprecationWarning)
/usr/local/lib/python3.6/dist-packages/sklearn/utils/deprecation.py:85: DeprecationWarning: Function mldata_filename is deprecated; mldata_filename was deprecated in version 0.20 and will be removed in version 0.22. Please use fetch_openml.
  warnings.warn(msg, category=DeprecationWarning)
---------------------------------------------------------------------------
ConnectionResetError                      Traceback (most recent call last)
<ipython-input-8-8ae517e9a088> in <module>()
      1 from sklearn.datasets import fetch_mldata
----> 2 dataset = fetch_mldata('MNIST original')
      3 data = dataset.data

11 frames
/usr/lib/python3.6/socket.py in readinto(self, b)
    584         while True:
    585             try:
--> 586                 return self._sock.recv_into(b)
    587             except timeout:
    588                 self._timeout_occurred = True

ConnectionResetError: [Errno 104] Connection reset by peer

It is taking too long to show this error message. How to resolve this?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Abdus Samad
  • 11
  • 1
  • 1
  • 3

2 Answers2

0

Take a look at this response, it is very similar SO answer

But, you can simply wrap the dataset = fetch_mldata('MNIST original') in a try-except block.

try:
     dataset = fetch_mldata('MNIST original')
except ConnectionResetError as exc:
     print('Oh no, conection error', str(exc))
     raise

This will catch the exception, print a statement, and then reraise the original exception.

This is the exception being raised socket.py You can try calling socket.settimeout with a larger timeout value to give your request time to complete. To be clear, this will make the exception take even longer to appear (60 seconds in the code below). If it still occurs, there may be an issue with your network that is causing a disconnect.

from sklearn.datasets import fetch_mldata
import socket

socket.settimeout(60) # sets the socket timeout to 60 seconds.
dataset = fetch_mldata('MNIST original')
data = dataset.data

Another caveat, take a look at the first line of the error response you provided.

/usr/local/lib/python3.6/dist-packages/sklearn/utils/deprecation.py:85: DeprecationWarning: Function fetch_mldata is deprecated; fetch_mldata was deprecated in version 0.20 and will be removed in version 0.22. Please use fetch_openml.

warnings.warn(msg, category=DeprecationWarning)

You may want to try using fetch_openml since fetch_mldata is being deprecated.

ryankdwyer
  • 681
  • 7
  • 16
0

The MNIST dataset is removed from the sklearn. That is why I was facing that problem. Following is an alternate solution to load MNIST data:

from sklearn.datasets import fetch_mldata
mnist = fetch_mldata('MNIST original')
Abdus Samad
  • 11
  • 1
  • 1
  • 3