from tensorflow.examples.tutorials.mnist import input_data ModuleNotFoundError: No module named 'tensorflow.examples'
时间: 2024-01-02 14:23:00 浏览: 233
您遇到的错误是因为您的环境中缺少了tensorflow.examples模块。这个模块通常是在TensorFlow的旧版本中使用的,而在新版本中已经被移除了。您可以尝试更新您的TensorFlow版本或者使用其他方法来导入MNIST数据集。
以下是两种导入MNIST数据集的方法:
1. 使用keras库导入MNIST数据集:
```python
from keras.datasets import mnist
# 加载MNIST数据集
(x_train, y_train), (x_test, y_test) = mnist.load_data()
# 打印数据集的形状
print("训练集数据形状:", x_train.shape) # 输出:(60000, 28, 28)
print("训练集标签形状:", y_train.shape) # 输出:(60000,)
print("测试集数据形状:", x_test.shape) # 输出:(10000, 28, 28)
print("测试集标签形状:", y_test.shape) # 输出:(10000,)
```
2. 使用tf.keras库导入MNIST数据集:
```python
import tensorflow as tf
# 加载MNIST数据集
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
# 打印数据集的形状
print("训练集数据形状:", x_train.shape) # 输出:(60000, 28, 28)
print("训练集标签形状:", y_train.shape) # 输出:(60000,)
print("测试集数据形状:", x_test.shape) # 输出:(10000, 28, 28)
print("测试集标签形状:", y_test.shape) # 输出:(10000,)
```
阅读全文
相关推荐


















