Reputation: 53
I am trying to import a locale MNIST dataset from my computer into Jupyter Notebook, but i am getting a ModuleNotFound error.
I have installed the python-mnist package
# Import necessary modules
from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import train_test_split
from mnist import MNIST
import numpy as np
import matplotlib.pyplot as plt
mnist = MNIST('../Dataset/MNIST')
x_train, y_train = mnist.load_training() #60000 samples
x_test, y_test = mnist.load_testing() #10000 samples
THE ERROR MESSAGE
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-4e881af1c89c> in <module>
2 from sklearn.neighbors import KNeighborsClassifier
3 from sklearn.model_selection import train_test_split
----> 4 from mnist import MNIST
5
6 import numpy as np
ModuleNotFoundError: No module named 'mnist'
Upvotes: 3
Views: 11180
Reputation: 78
I suppose that you must install
python-mnist
see this link: python-mnist 0.7
Upvotes: 0
Reputation: 19322
You can directly fetch the database from tf.keras.datasets.mnist.load_data()
as well.
Here is the code for that.
import tensorflow as tf
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()
print([i.shape for i in (x_train, y_train, x_test, y_test)])
[(60000, 28, 28), (60000,), (10000, 28, 28), (10000,)]
Upvotes: 1
Reputation: 81
Try using:
import tensorflow_datasets as tfds
datasets = tfds.load('mnist')
train_dataset = datasets['train']
test_dataset = datasets['test']
IMAGE_INPUT_NAME = 'image'
LABEL_INPUT_NAME = 'label'
https://www.tensorflow.org/datasets/overview
Upvotes: 1