gpt4 book ai didi

python - 属性错误: 'function' object has no attribute 'preprocess_input'

转载 作者:太空宇宙 更新时间:2023-11-03 20:31:58 27 4
gpt4 key购买 nike

我想尝试 MobileNetV2 的预测。我总是收到错误消息,但我不知道要更改什么。

import keras
from keras import backend as K
from keras.preprocessing.image import ImageDataGenerator
from keras.preprocessing import image
from keras.applications import imagenet_utils
from keras.layers import Dense,GlobalAveragePooling2D
from keras.applications.mobilenetv2 import decode_predictions
from keras.applications.mobilenetv2 import MobileNetV2
from keras.applications.mobilenetv2 import preprocess_input
import numpy as np
from IPython.display import Image
from keras.optimizers import Adam

mobilenet = MobileNetV2()

def process_image(img_path):
img = image.load_img(img_path, target_size=(224, 224))
img_array = image.img_to_array(img)
img_array = np.expand_dims(img_array, axis=0)
pImg = MobileNetV2.preprocess_input(img_array)
return pImg

process_image(IMG_PATH)

这是错误消息。

---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-29-6cdb09c1b552> in <module>()
----> 1 process_image('IMG_PATH')

<ipython-input-28-1b1187d4c25c> in process_image(img_path)
3 img_array = image.img_to_array(img)
4 img_array = np.expand_dims(img_array, axis=0)
----> 5 pImg = MobileNetV2.preprocess_input(img_array)
6 return pImg

AttributeError: 'function' object has no attribute 'preprocess_input'

也许有人可以帮助我。

最佳答案

如果你查看 keras_applications/mobilenet_v2你会发现 MobilNetV2 没有属性 preprocess_input

您可以从 mobilenet_v2 导入 preprocess_input:

from keras.applications.mobilenetv2 import preprocess_input

然后你可以使用:

pImg = preprocess_input(img_array)

关于python - 属性错误: 'function' object has no attribute 'preprocess_input' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57443026/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com