[英]ImportError: cannot import name 'img_to_array' from 'keras.preprocessing.image'
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此代码来自github 链接
Im using我在用着
In Keras Documentation V2.9.0 ,在Keras 文档 V2.9.0中,
In tf version 2.9.0 the img_to_array moved to utlis在tf 版本 2.9.0 中,img_to_array 移至 utlis
Insted of,安装,
from keras.preprocessing.image import img_to_array
Try this,尝试这个,
from tensorflow.keras.utils import img_to_array
现在是 2022.07.20 我的方法是:试试 from keras.utils.image_utils import img_to_array 就可以了!
Insted of,安装,
from keras.preprocessing.image import img_to_array从 keras.preprocessing.image 导入 img_to_array
Try:-尝试:-
from keras_preprocessing.image import img_to_array从 keras_preprocessing.image 导入 img_to_array
note: underscore (_) instead of dot (.)注意:下划线 (_) 而不是点 (.)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.