首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法从“load_img”导入名称“keras.preprocessing.image”

无法从“load_img”导入名称“keras.preprocessing.image”
EN

Stack Overflow用户
提问于 2022-06-02 15:56:55
回答 2查看 23.7K关注 0票数 2

我为什么要面对这个问题?我可以从kera.preprocessing导入图像模块。但不能导入image_dataset_from_directory。信托基金版本: 2.9.1

代码语言:javascript
运行
复制
# make a prediction for a new image.
from keras.preprocessing.image import load_img
from keras.preprocessing.image import img_to_array
from keras.models import load_model

# load and prepare the image
def load_image(filename):
    # load the image
    img = load_img(filename, target_size=(224, 224))
    # convert to array
    img = img_to_array(img)
    # reshape into a single sample with 3 channels
    img = img.reshape(1, 224, 224, 3)
    # center pixel data
    img = img.astype('float32')
    img = img - [123.68, 116.779, 103.939]
    return img

# load an image and predict the class
def run_example():
    # load the image
    img = load_image('test.jpg')
    # load model
    model = load_model('final_model.h5')
    # predict the class
    result = model.predict(img)
    print(result[0])

# entry point, run the example
run_example()

错误

代码语言:javascript
运行
复制
from keras.preprocessing.image import load_img
ImportError: cannot import name 'load_img' from 'keras.preprocessing.image'
EN

回答 2

Stack Overflow用户

发布于 2022-09-11 06:10:37

替换

代码语言:javascript
运行
复制
    from keras.preprocessing.image import load_img

使用

代码语言:javascript
运行
复制
    from keras_preprocessing.image import load_img
票数 4
EN

Stack Overflow用户

发布于 2022-07-07 02:10:04

代码语言:javascript
运行
复制
from tensorflow.keras.preprocessing.image import load_img
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72479044

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档