Reputation: 225
Im new here. I have problem with this code,
#Library
import numpy as np
import pickle
import cv2
from os import listdir
from sklearn.preprocessing import LabelBinarizer
from keras.models import Sequential
from keras.layers import BatchNormalization
from keras.layers.convolutional import Conv2D
from keras.layers.convolutional import MaxPooling2D
from keras.layers.core import Activation, Flatten, Dropout, Dense
from keras import backend as K
from keras.preprocessing.image import ImageDataGenerator
from keras.optimizers import Adam
from keras.preprocessing import image
#from tensorflow.keras.preprocessing.image import img_to_array
from keras.preprocessing.image import img_to_array
from sklearn.preprocessing import MultiLabelBinarizer
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
I got an error
this code is from github link
Im using
Upvotes: 12
Views: 80032
Reputation: 41
Either this is a moving target or a lot of the responses here didn't even attempt their own solutions.
Working for me in Colab as of 9/26/2023.
from keras.utils.image_utils import img_to_array, load_img
Upvotes: 0
Reputation: 41
Instead of:
from keras.preprocessing.image import img_to_array
Try:
from keras_preprocessing.image import img_to_array
Notice the underscore (_) instead of the dot (.)
Upvotes: 4
Reputation: 41
Now is 2022.07.20 My method is : try from keras.utils.image_utils import img_to_array It is fine!
Upvotes: 4
Reputation: 649
In Keras Documentation V2.9.0,
In tf version 2.9.0 the img_to_array moved to utlis
Insted of,
from keras.preprocessing.image import img_to_array
Try this,
from tensorflow.keras.utils import img_to_array
Upvotes: 33