Indra Gunawan
Indra Gunawan

Reputation: 36

Unable to Load MNIST dataset in Tensorflow using Jupyter Notebook in Windows

I encountered some error when loading Mnist datasets in Jupyter Notebook, and i'm using windows.

My python version is 3.7, I installed using microsoft visual studio. i have anaconda installed.

i tried to run this code :

import numpy as np
import tensorflow as tf

import tensorflow_datasets as tfds

mnist_dataset, mnist_info = tfds.load(name='mnist', with_info=True, as_supervised=True)

here is the error message that i get :

SSLError: Failed to construct dataset mnistHTTPSConnectionPool(host='storage.googleapis.com', port=443): Max retries exceeded with url: /tfds-data/?prefix=dataset_info/mnist/3.0.1/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)')))

​Please help, Thanks before!

Upvotes: 1

Views: 2319

Answers (2)

A.Ametov
A.Ametov

Reputation: 2020

I had some troubes with final tensors when tried to load MNIST from mnist.npz. I recommend to download raw tar.gz files from YannLeCun and place them somewhere locally. Method _get_manually_downloaded_path from download_manager.py (\venv\Lib\site-packages\tensorflow_datasets\core\download) will tell you where it wants your archives to be

manual_path = manual_dir / expected_url_info.filename
if not manual_path.exists():  # File not manually downloaded
    print('LOOKED FOR FILES IN', manual_path) # Added myself
    return None

When calling, use this

(ds_train, ds_test), ds_info = tfds.load(
    'mnist',
    split=['train', 'test'],
    shuffle_files=True,
    as_supervised=True,
    with_info=True,
    download=True,
    data_dir='C:\\Users\\Batman\\tensorflow_datasets\\mnist'
)

It is the only one solution for MNIST I have found. Other datasets could be downloaded but also support this manual hack, tried with fashion_mnist with tars from Github

Upvotes: 0

curtisp
curtisp

Reputation: 2315

This load_data documentation has link to Github repository which provides url to get mnist.npz file.

https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz

Put it into any local directory:

path = '/your local directory path/'

Per doc'n mnist is "Tuple of Numpy arrays: (x_train, y_train), (x_test, y_test)" so you can read it as follows:

(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data(
    path=path + 'mnist.npz'
)

And then start using it in model.

Upvotes: 3

Related Questions