I need to use the mnist
Python library for downloading and reading MNIST data (PyPi, Github):
import mnist
mnist_dataset = mnist.test_images().astype(np.float32)
On my university cluster I load the data without problem. Locally on my PC, however, I get:
---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
<ipython-input-24-78f59b728818> in <module>
8 DATASET_SIZE = 512
9 DIGIT_SIZE = 28
---> 10 mnist_dataset = mnist.test_images().astype(np.float32)
11 np.random.shuffle(mnist_dataset)
12 mnist_dataset = np.reshape(mnist_dataset[:DATASET_SIZE] / 255.0, newshape=(DATASET_SIZE, DIGIT_SIZE*DIGIT_SIZE))
~\anaconda3\lib\site-packages\mnist\__init__.py in test_images()
174 columns of the image
175 """
--> 176 return download_and_parse_mnist_file('t10k-images-idx3-ubyte.gz')
177
178
~\anaconda3\lib\site-packages\mnist\__init__.py in download_and_parse_mnist_file(fname, target_dir, force)
141 Numpy array with the dimensions and the data in the IDX file
142 """
--> 143 fname = download_file(fname, target_dir=target_dir, force=force)
144 fopen = gzip.open if os.path.splitext(fname)[1] == '.gz' else open
145 with fopen(fname, 'rb') as fd:
~\anaconda3\lib\site-packages\mnist\__init__.py in download_file(fname, target_dir, force)
57 if force or not os.path.isfile(target_fname):
58 url = urljoin(datasets_url, fname)
---> 59 urlretrieve(url, target_fname)
60
61 return target_fname
~\anaconda3\lib\urllib\request.py in urlretrieve(url, filename, reporthook, data)
245 url_type, path = splittype(url)
246
--> 247 with contextlib.closing(urlopen(url, data)) as fp:
248 headers = fp.info()
249
~\anaconda3\lib\urllib\request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
220 else:
221 opener = _opener
--> 222 return opener.open(url, data, timeout)
223
224 def install_opener(opener):
~\anaconda3\lib\urllib\request.py in open(self, fullurl, data, timeout)
529 for processor in self.process_response.get(protocol, []):
530 meth = getattr(processor, meth_name)
--> 531 response = meth(req, response)
532
533 return response
~\anaconda3\lib\urllib\request.py in http_response(self, request, response)
639 if not (200 <= code < 300):
640 response = self.parent.error(
--> 641 'http', request, response, code, msg, hdrs)
642
643 return response
~\anaconda3\lib\urllib\request.py in error(self, proto, *args)
567 if http_err:
568 args = (dict, 'default', 'http_error_default') + orig_args
--> 569 return self._call_chain(*args)
570
571 # XXX probably also want an abstract factory that knows when it makes
~\anaconda3\lib\urllib\request.py in _call_chain(self, chain, kind, meth_name, *args)
501 for handler in handlers:
502 func = getattr(handler, meth_name)
--> 503 result = func(*args)
504 if result is not None:
505 return result
~\anaconda3\lib\urllib\request.py in http_error_default(self, req, fp, code, msg, hdrs)
647 class HTTPDefaultErrorHandler(BaseHandler):
648 def http_error_default(self, req, fp, code, msg, hdrs):
--> 649 raise HTTPError(req.full_url, code, msg, hdrs, fp)
650
651 class HTTPRedirectHandler(BaseHandler):
HTTPError: HTTP Error 403: Forbidden
I have inspected the functions through inspect
module. The HTTP addresses called by both local and cluster versions are the same, i.e. http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz. I can download it without problems from my web browser.
What can I do about this in Python?