Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix 'keras' has no attribute 'datasets'

Tags:

python

keras

I was following a keras tutorial and I had run this piece of code

import keras
mnist = keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()

and I get this error message

AttributeError: module 'keras' has no attribute 'datasets'

I've tried to look up other people with the same question, but can't seem to find the exact answer. How can I resolve this?

like image 987
Yuvanesh Anand Avatar asked Sep 08 '25 05:09

Yuvanesh Anand


1 Answers

Edited code :

import tensorflow.keras as tk
mnist = tk.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()

Reference:

https://keras.io/api/datasets/

https://www.tensorflow.org/api_docs/python/tf/keras/datasets/mnist/load_data

like image 53
user11530462 Avatar answered Sep 10 '25 10:09

user11530462