如何从图像分类中的卷积神经网络中获取预测标签
How get the predicted label from a Convolution Neural Net in image classification
我用 Convolution Neural Net
或 CNNs
构建了一个 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]
规格:
TENSORFLOW 版本:1.15.2
编辑:Google Colab
OS: Windows 7
GOOGLE COLAB 文件 LINK:
https://drive.google.com/file/d/1NpYGWvo9bNG0SJsFJ6R3se46b1ovDUX8/view?usp=sharing
注意: link 已过时
如果您想了解更多信息或不想对问题提出任何疑问,请告诉我!
你得到的是 class 的 indexes
,也就是每个 class 所代表的数字。在您的示例中,0 表示 'airplane',1 表示 'automobile',依此类推。
要获取名称,您只需访问 class 个名称即可。
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)
我用 Convolution Neural Net
或 CNNs
构建了一个 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]
规格:
TENSORFLOW 版本:1.15.2
编辑:Google Colab
OS: Windows 7
GOOGLE COLAB 文件 LINK: https://drive.google.com/file/d/1NpYGWvo9bNG0SJsFJ6R3se46b1ovDUX8/view?usp=sharing 注意: link 已过时
如果您想了解更多信息或不想对问题提出任何疑问,请告诉我!
你得到的是 class 的 indexes
,也就是每个 class 所代表的数字。在您的示例中,0 表示 'airplane',1 表示 'automobile',依此类推。
要获取名称,您只需访问 class 个名称即可。
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)