Skip to content
Advertisement

AttributeError: module ‘keras.preprocessing.image’ has no attribute ‘img_to_array’

I have added following libraries and half part of the code is executing. In second half I get this error.

Libraries added:

#importing libraries
import keras
import tensorflow as tf
from tensorflow.keras.applications.resnet50 import ResNet50, preprocess_input
from tensorflow.keras.utils import img_to_array

Error: AttributeError: module ‘keras.preprocessing.image’ has no attribute ‘img_to_array’

I was following this code and changes the libraries too still can’t resolve the issue. https://www.analyticsvidhya.com/blog/2021/06/k-means-clustering-and-transfer-learning-for-image-classification/

Advertisement

Answer

It has now moved to tf.keras.utils.img_to_array. See the docs

Advertisement