亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Keras - 如何使用 argmax 進行預測

Keras - 如何使用 argmax 進行預測

斯蒂芬大帝 2021-10-10 14:44:03
我有 3 類課程Tree, Stump, Ground。我為這些類別列出了一個清單:CATEGORIES = ["Tree", "Stump", "Ground"]當我打印我的預測時,它給了我輸出[[0. 1. 0.]]我已經閱讀了 numpy 的 Argmax,但我不完全確定在這種情況下如何使用它。我試過使用print(np.argmax(prediction))但這給了我1. 太好了,但我想找出索引是什么1,然后打印出類別而不是最高值。import cv2import tensorflow as tfimport numpy as npCATEGORIES = ["Tree", "Stump", "Ground"]def prepare(filepath):    IMG_SIZE = 150 # This value must be the same as the value in Part1    img_array = cv2.imread(filepath, cv2.IMREAD_GRAYSCALE)    new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))    return new_array.reshape(-1, IMG_SIZE, IMG_SIZE, 1)# Able to load a .model, .h3, .chibai and even .dogmodel = tf.keras.models.load_model("models/test.model")prediction = model.predict([prepare('image.jpg')])print("Predictions:")print(prediction)print(np.argmax(prediction))我希望我的預測告訴我:Predictions:[[0. 1. 0.]]Stump
查看完整描述

2 回答

?
慕無忌1623718

TA貢獻1744條經驗 獲得超4個贊

您只需要使用以下結果對類別進行索引np.argmax:


pred_name = CATEGORIES[np.argmax(prediction)]

print(pred_name)


查看完整回答
反對 回復 2021-10-10
  • 2 回答
  • 0 關注
  • 514 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號