簡體   English   中英

在Pycharm上使用Keras運行ResNet50時發生AttributeError

[英]AttributeError occurs while running ResNet50 using Keras on Pycharm

我正在使用PyCharm並導入ResNet50來對示例圖像進行圖像識別。 當我運行代碼時,發生以下錯誤。

我正在使用需要由學習者完成的在線代碼進行學習。 我配置了PyCharm並安裝了建議的必需軟件包。 在使用ResNet50學習圖像識別的過程中,運行代碼時出現以下錯誤。 我應該在pycharm上自定義安裝ResNet50才能正常工作嗎? 講師說,IDE將在代碼執行期間自動下載ResNet50。 在下面附加python代碼。

import numpy as np
from keras.preprocessing import image
from keras.applications import resnet50

model = resnet50.ResNet50

img = image.load_img("bay.jpg", target_size=(224, 224))

x = image.img_to_array(img)

x = np.expand_dims(x, axis=0)

x = resnet50.preprocess_input(x)

predictions = model.predict(x)

predicted_classes = resnet50.decode_predictions(predictions, top=9)

print("This is an image of:")

for imagenet_id, name, likelihood in predicted_classes[0]:
    print(" - {}: {:2f} likelihood".format(name, likelihood))

這是我在執行過程中遇到的結果錯誤。

File "/home/warlock/Downloads/Ex_Files_Building_Deep_Learning_Apps/
Exercise Files/05/image_recognition.py", line 21, in <module>
    predictions = model.predict(x)
AttributeError: 'function' object has no attribute 'predict'

您有此錯誤,因為ResNet50是功能,因此您需要像功能一樣實現它:

model = resnet50.ResNet50()

為了具有所有默認參數的resnet50模型

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM