'ModuleNotFoundError: No module named 'tensorflow.examples' (i am just tried now)
I have tried lots of times by taking many ways but it doesn't work anyway.
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_dataput_data
Solution 1:[1]
If you want to load MNIST dataset, you can try this:
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()
Or you can use tensorflow_datasets like below:
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()
Output:
Solution 2:[2]
In in tensorflow 2, you don't need turorial package, use:
tf.keras.datasets.mnist.load_data(
path='mnist.npz'
)
You can read more : here
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | saleh sargolzaee |

