导入错误:无法从“keras.preprocessing.image”导入名称“img_to_array”

bzzcjhmw  于 2022-11-13  发布在  其他
关注(0)|答案(3)|浏览(291)

我是新来。我对这段代码有问题,

#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

出现错误

此代码来自github link
即时通讯使用

  1. Python 3.7.13版
    1.tensorflow 2.9
    1.开放性版本4.5.5
    1.卡拉斯2.9.0
dldeef67

dldeef671#

Keras Documentation V2.9.0中,
tf版本2.9.0中,img_to_array已移至utlis
代替,
from keras.preprocessing.image import img_to_array
试试这个,
from tensorflow.keras.utils import img_to_array

wlp8pajw

wlp8pajw2#

而不是:

from keras.preprocessing.image import img_to_array

请尝试:

from keras_preprocessing.image import img_to_array

请注意下划线(_)而不是点号(.)

aemubtdh

aemubtdh3#

现在是2022.07.20我的方法是:尝试从keras.utils.image_utils导入img_to_array它很好!

相关问题