我已经通过多种方式尝试了很多次,但无论如何它都不起作用。
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_dataput_data
如果你想加载MNIST
数据集,你可以试试这个:
import tensorflow as tf
import matplotlib.pyplot as plt
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()
fig, axes = plt.subplots(2,5,figsize=(15,6))
for idx, axe in enumerate(axes.flatten()):
axe.axis('off')
axe.set_title(f'label : {y_train[idx]}')
axe.imshow(x_train[idx])
plt.show()
或者你可以tensorflow_datasets
像下面这样使用:
import tensorflow_datasets as tfds
import matplotlib.pyplot as plt
dataset = tfds.load('mnist', download=True, as_supervised=True, split = 'train').batch(10)
image, label = next(iter(dataset))
fig, axes = plt.subplots(2,5,figsize=(15,6))
for idx, axe in enumerate(axes.flatten()):
axe.axis('off')
axe.set_title(f'label : {label[idx]}')
axe.imshow(image[idx][...,0])
plt.show()
输出:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句