我正在尝试从计算机中将语言环境MNIST数据集导入Jupyter Notebook,但出现ModuleNotFound错误。
我已经安装了python-mnist软件包
# 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'
答案 0 :(得分:1)
尝试使用:
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'
答案 1 :(得分:0)
您也可以直接从 tf.keras.datasets.mnist.load_data()
获取数据库。
这是代码。
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,)]