解决 'AttributeError: module 'keras.preprocessing.image' has no attribute 'load_img'' 错误
当您尝试使用 keras.preprocessing.image 模块中的 load_img 函数时,如果您的 Keras 版本不支持该函数,就会出现此错误。
为了解决此错误,您可以尝试升级 Keras 版本,或者使用其他方法来加载图像,例如使用 PIL 库或 cv2 库。
以下是使用 PIL 库加载图像的示例:
from PIL import Image
img_path = 'smile.png'
img = Image.open(img_path)
img = img.resize((64, 64))
img.show()
x = np.array(img)
注意:在使用上述代码之前,您需要导入必要的库(PIL 和 numpy)。
原文地址: https://www.cveoy.top/t/topic/mM4S 著作权归作者所有。请勿转载和采集!