簡體   English   中英

如何從圖像分類中的卷積神經網絡中獲取預測標簽

[英]How get the predicted label from a Convolution Neural Net in image classification

我已經使用Convolution Neural NetCNNs構建了CIFAR-10圖像分類模型。
模型完全完成並獲得了大約 59% 的准確率,但我的問題是如何從模型中獲取預測標簽。 它可以預測這些類(10):

['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck']

我想說的是,例如,我們給模型一個飛機的圖像,它應該預測並在預測后向我顯示標簽,但我不明白如何獲得預測的標簽。

這是我嘗試過的,但不明白輸出是什么:

with tf.Session() as sess:
    sess.run(init)
    print(sess.run(tf.argmax(y_pred, 1), feed_dict={x:ch.test_images, y_true:ch.test_labels, hold_prob:1.0}))
    print(sess.run(tf.argmax(y_true, 1), feed_dict={x:ch.test_images, y_true:ch.test_labels, hold_prob:1.0}))

輸出:

[0 0 0 ... 0 3 3]
[3 8 8 ... 5 1 7]

規格
張量流版本:1.15.2
編輯:谷歌 Colab
操作系統:Windows 7

GOOGLE COLAB 文件鏈接https : //drive.google.com/file/d/1NpYGWvo9bNG0SJsFJ6R3se46b1ovDUX8/view?usp = sharing注意:鏈接已過時

如果您想了解更多信息或不想對問題提出任何疑問,請告訴我!

你得到的是類的indexes ,即每個類所代表的數字。 在您的示例中,0 表示“飛機”,1 表示“汽車”,依此類推。

要獲取名稱,您只需要訪問類名稱。

classes=['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck']
with tf.Session() as sess:
    sess.run(init)
    idxs = sess.run(tf.argmax(y_pred, 1), feed_dict={x:ch.test_images, y_true:ch.test_labels, hold_prob:1.0}))
    labels = [classes[idx] for idx in idxs]
    print(labels)

暫無
暫無

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

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