Home>

The person who has just started to be interested in programming recently.
So it may be difficult to read the program code, but it would be helpful if you could answer. .

I am trying to recognize handwritten numbers using a web camera.
When trying to create a learning model using MNIST,

TimeoutError: [WinError 10060] The connection could not be established because the connected callee did not respond correctly after a certain period of time. Or the established connection failed because the connected host did not respond.

and an error message like this were displayed.

Error message
Start
C: \ Users \ Taisei \ Anaconda3 \ envs \ opencv \ lib \ site-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)
C: \ Users \ Taisei \ Anaconda3 \ envs \ opencv \ lib \ site-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)
Traceback (most recent call last):
  File "C: \ Users \ Taisei \ Anaconda3 \ envs \ opencv \ lib \ urllib \ request.py", line 1318, in do_open
    encode_chunked = req.has_header ('Transfer-encoding'))
  File "C: \ Users \ Taisei \ Anaconda3 \ envs \ opencv \ lib \ http \ client.py", line 1239, in request
    self._send_request (method, url, body, headers, encode_chunked)
  File "C: \ Users \ Taisei \ Anaconda3 \ envs \ opencv \ lib \ http \ client.py", line 1285, in _send_request
    self.endheaders (body, encode_chunked = encode_chunked)
  File "C: \ Users \ Taisei \ Anaconda3 \ envs \ opencv \ lib \ http \ client.py", line 1234, in endheaders
    self._send_output (message_body, encode_chunked = encode_chunked)
  File "C: \ Users \ Taisei \ Anaconda3 \ envs \ opencv \ lib \ http \ client.py", line 1026, in _send_output
    self.send (msg)
  File "C: \ Users \ Taisei \ Anaconda3 \ envs \ opencv \ lib \ http \ client.py", line 964, in send
    self.connect ()
  File "C: \ Users \ Taisei \ Anaconda3 \ envs \ opencv \ lib \ http \ client.py", line 936, in connect
    (self.host, self.port), self.timeout, self.source_address)
  File "C: \ Users \ Taisei \ Anaconda3 \ envs \ opencv \ lib \ socket.py", line 724, in create_connection
    raise err
  File "C: \ Users \ Taisei \ Anaconda3 \ envs \ opencv \ lib \ socket.py", line 713, in create_connection
    sock.connect (sa)
TimeoutError: [WinError 10060] The connection could not be established because the connected callee did not respond correctly after a certain period of time. Or the established connection failed because the connected host did not respond.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):File "make_model.py", line 26, in<module>
    mnist = fetch_mldata ("MNIST original", data_home = ".")
  File "C: \ Users \ Taisei \ Anaconda3 \ envs \ opencv \ lib \ site-packages \ sklearn \ utils \ deprecation.py", line 86, in wrapped
    return fun (* args, ** kwargs)
  File "C: \ Users \ Taisei \ Anaconda3 \ envs \ opencv \ lib \ site-packages \ sklearn \ datasets \ mldata.py", line 126, in fetch_mldata
    mldata_url = urlopen (urlname)
  File "C: \ Users \ Taisei \ Anaconda3 \ envs \ opencv \ lib \ urllib \ request.py", line 223, in urlopen
    return opener.open (url, data, timeout)
  File "C: \ Users \ Taisei \ Anaconda3 \ envs \ opencv \ lib \ urllib \ request.py", line 526, in open
    response = self._open (req, data)
  File "C: \ Users \ Taisei \ Anaconda3 \ envs \ opencv \ lib \ urllib \ request.py", line 544, in _open
    '_open', req)
  File "C: \ Users \ Taisei \ Anaconda3 \ envs \ opencv \ lib \ urllib \ request.py", line 504, in _call_chain
    result = func (* args)
  File "C: \ Users \ Taisei \ Anaconda3 \ envs \ opencv \ lib \ urllib \ request.py", line 1346, in http_open
    return self.do_open (http.client.HTTPConnection, req)
  File "C: \ Users \ Taisei \ Anaconda3 \ envs \ opencv \ lib \ urllib \ request.py", line 1320, in do_open
    raise URLError (err)
urllib.error.URLError:<urlopen error [WinError 10060] The connection could not be made because the connected callee did not respond correctly after a certain period of time. Or the established connection failed because the connected host did not respond. >
Applicable source code
import numpy as np
from chainer import Variable, optimizers, serializers
from chainer import Chain
import chainer.functions as F
import chainer.links as L
from sklearn.datasets import fetch_mldata
class MyMLP (Chain):
    def __init __ (self, n_in = 784, n_units = 100, n_out = 10):
        super (MyMLP, self) .__ init __ (
            l1 = L.Linear (n_in, n_units),
            l2 = L.Linear (n_units, n_units),
            l3 = L.Linear (n_units, n_out),
        )
    def __call __ (self, x):
        h1 = F.relu (self.l1 (x))h2 = F.relu (self.l2 (h1))
        y = self.l3 (h2)
        return y
#Indicates that the program has started (because it takes time to download MNIST).
print ('Start')
mnist = fetch_mldata ("MNIST original", data_home = ".")
x_all = mnist ['data']. astype (np.float32)/255
y_all = mnist ['target']. astype (np.int32)
model = MyMLP ()
optimizer = optimizers.SGD ()
optimizer.setup (model)
BATCHSIZE = 100
DATASIZE = 70000
for epoch in range (20):
    print ('epoch% d'% epoch)
    indexes = np.random.permutation (DATASIZE)
    for i in range (0, DATASIZE, BATCHSIZE):
        x = Variable (x_all [indexes [i: i + BATCHSIZE]])
        t = Variable (y_all [indexes [i: i + BATCHSIZE]])
        model.zerograds ()
        y = model (x)
        loss = F.softmax_cross_entropy (y, t)
        loss.backward ()
        optimizer.update ()
serializers.save_npz ("mymodel.npz", model)
#Indicates that the program is finished.
print ('Finish')

Check that there is no problem with the network connection.

Supplemental information (FW/tool version etc.)

I use Python (3.6.8) with Anaconda.
The code is written in Spyder (3.3.6).
Chainer is already installed.

  • Answer # 1

    I have never encountered this error myself, but it appears that a similar error has been reported.

    https://github.com/YutaroOgawa/Deep-Reinforcement-Learning-Book/issues/4

    https://webbibouroku.com/Blog/Article/fetch-mldata-error

    To summarize the cause,fetch_mldatadownloads data from the server, but it seems that the server is down.
    For detailed solution, please refer to the above URL, but you can download MNIST data from another server.