'keras.api._v2.keras' has no attribute 'mnist'

'keras.api._v2.keras' has no attribute 'mnist'

Problem Description:

I tried installing TensorFlow and I wanted to try something I saw on youtube.com but I’ve tried multiple things nothing worked for me and every time I got different error.`

import tensorflow as tf
import numpy as np
from keras.models import Sequential
import matplotlib.pyplot as plt
import time

(train_images,train_labels),(test_images,test_labels) = tf.keras.mnist.load_data()

plt.imshow(train_images[0])

This is the error

`

Traceback (most recent call last):
  File "c:pyprojectstensorflowmain.py", line 7, in <module>
    (train_images,train_labels),(test_images,test_labels) = tf.keras.mnist.load_data()
AttributeError: module 'keras.api._v2.keras' has no attribute 'mnist'

`

I tried different things as I said nothing worked.

Solution – 1

You should use tf.keras.datasets.mnist

import tensorflow as tf

mnist = tf.keras.datasets.mnist
(training_images, training_labels), (test_images, test_labels) = mnist.load_data()
Rate this post
We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.
Accept
Reject