Home > Blockchain >  'keras.api._v2.keras' has no attribute 'mnist'
'keras.api._v2.keras' has no attribute 'mnist'

Time:12-07

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:\pyprojects\tensorflow\main.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.

CodePudding user response:

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()
  • Related