[英]HOW TO FIX IT? AttributeError: module 'keras.preprocessing.image' has no attribute 'load_img'
import numpy as np
from keras.preprocessing import image
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
%matplotlib inline
path = './test/paper2.png'
img = image.load_img(path, target_size=(150,150))
imgplot = plt.imshow(img)
x = image.img_to_array(img)
img_test = np.expand_dims(x, axis=0)
classes = model.predict(img_test, batch_size=10)
print(classes)
paper, rock, scissors = classes[0]
if paper==1.:
print('paper')
elif rock==1.:
print('rock')
else:
print('scissors')
output:输出:
AttributeError: module 'keras.preprocessing.image' has no attribute 'load_img'
when I try to run.当我尝试跑步时。 What does the error mean and how can I fix it?
该错误是什么意思,我该如何解决? help guys:) I'm trying to learn I don't know anymore which one is wrong
帮助大家:)我正在努力学习我不知道哪个是错的
Replace:代替:
from keras.preprocessing import image
for:为了:
import keras.utils as image
I'm facing the same problem today.我今天面临同样的问题。 You can try using tensorflow 2.8.0 to fix it or try
tf.keras.utils.load_img
instead of image.load_img
.您可以尝试使用 tensorflow 2.8.0 来修复它或尝试
tf.keras.utils.load_img
而不是image.load_img
。
there is no 'load_img' https://github.com/keras-team/keras/blob/master/keras/preprocessing/image.py没有'load_img' https://github.com/keras-team/keras/blob/master/keras/preprocessing/image.py
I suppose you trying to use load_img of keras.utils.image_utils我想你试图使用 keras.utils.image_utils 的 load_img
use keras.utils.load_img
使用
keras.utils.load_img
import keras
import tensorflow as tf
image = keras.utils.load_img('path_to_image', target_size=(img_size, img_size))
I just added 'tensorflow.'我刚刚添加了“张量流”。 infront of the keras like 'tensorflow.keras.'
像'tensorflow.keras'这样的keras。 and it worked.
它奏效了。
I also face the same error.我也面临同样的错误。 I used
from tensorflow.keras.utils import load_img, img_to_array
and it work for me.我使用
from tensorflow.keras.utils import load_img, img_to_array
它对我有用。
first import首先导入
import tensorflow.compat.v2 as tf
then然后
tf.keras.preprocessing.image.load_img
Try this out试试这个
change this改变这个
from keras.preprocessing import image
test_image = image.load_img('$PATH', target_size = (64, 64))
test_image = image.img_to_array(test_image)
To this对此
from keras.utils import load_img, img_to_array
test_image = load_img('$PATH', target_size = (64, 64))
test_image = img_to_array(test_image)
reff:- https://keras.io/api/data_loading/image/参考资料:- https://keras.io/api/data_loading/image/
Source:- https://github.com/keras-team/keras/blob/v2.10.0/keras/utils/image_utils.py#L364来源:- https://github.com/keras-team/keras/blob/v2.10.0/keras/utils/image_utils.py#L364
I too had this and fixed我也有这个并修好了
changes in import进口变化
and change并改变
" img = image.load_img(path, target_size=(150,150)) " to "l oad_img(path, target_size=(150,150)) " “ img = image.load_img(path, target_size=(150,150)) ”到“l oad_img(path, target_size=(150,150)) ”
" x = image.img_to_array(img) " to " x = img_to_array(img) " “ x = image.img_to_array(img) ”到“ x = img_to_array(img) ”
The "AttributeError: module 'keras.preprocessing.image' has no attribute 'load_img'" occurs because the keras preprocessing API has been deprecated.出现“AttributeError: module 'keras.preprocessing.image' has no attribute 'load_img'”是因为 keras 预处理 API 已被弃用。 To solve the error, import the load_img() function from tensorflow.keras.utils.load_img.
要解决该错误,请从 tensorflow.keras.utils.load_img 中导入 load_img() 函数。
I too faced the same problem.我也面临同样的问题。 I used
from tensorflow.keras.utils import load_img, img_to_array
.我使用
from tensorflow.keras.utils import load_img, img_to_array
。 Problem got solved.问题得到了解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.