I have built a CIFAR-10
image classification model with Convolution Neural Net
or CNNs
.
The model fully completed and has got around 59% accuracy, but my problem is that how to get the predicted label from the model. it can predict these classes(10):
['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck']
What I’m trying to say is that, for example we give the model a image of a airplane it should predict and show me the label after predicting but I can’t i understand how to obtain the predicted label.
Here is what i tried, but don’t understand what is the output:
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}))
OUPUT:
[0 0 0 ... 0 3 3] [3 8 8 ... 5 1 7]
SPECFICATIONS:
TENSORFLOW VERSION: 1.15.2
EDITOR: Google Colab
OS: Windows 7
GOOGLE COLAB FILE LINK: https://drive.google.com/file/d/1NpYGWvo9bNG0SJsFJ6R3se46b1ovDUX8/view?usp=sharing NOTE: The link is outdated
If you want any more information or wan’t to ask any queries about the question please let me know!
Advertisement
Answer
What you are getting are the indexes
of the classes, that is the number each class is represented by. In your example, 0 means ‘airplane’, 1 means ‘automobile’ and so on.
To get the names you just need to access the class names.
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)