AttributeError: module 'keras.preprocessing.image' has no attribute 'load_img'
时间: 2023-08-21 18:03:12 浏览: 212
图片预加载loading
这个错误是因为你使用的keras版本更新了,所以原来的代码中的load_img方法已经被移除了。为了解决这个问题,你需要使用keras.utils中的image_utils模块替代原来的keras.preprocessing中的image模块。具体来说,你可以将原始的代码中的导入语句改为from keras.utils import image_utils,然后使用image_utils.load_img方法替代原来的image.load_img方法。同样的,你还需将image.img_to_array方法改为image_utils.img_to_array方法。你可以参考下面的完整代码:
from keras.utils import image_utils
img_keras = image_utils.load_img('./test.jpg')
print(img_keras)
img_keras = image_utils.img_to_array(img_keras)
print(img_keras[:, 1, 1])
这样修改后,你就可以成功加载图像并将其转换为数组了。希望对你有帮助!<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [报错AttributeError: module ‘keras.preprocessing.image‘ has no attribute ‘load_img](https://blog.csdn.net/weixin_45647721/article/details/126833323)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [已解决module ‘keras.preprocessing.image‘ has no attribute ‘load_img](https://blog.csdn.net/yuan2019035055/article/details/126436821)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文