Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

การถอดรหัสการทำนาย (Decode Predictions) ด้วย TensorFlow และ Python


แนวคิด

แปลงภาพเป็น NumPy array แล้วใช้ ImageNet labels ถอดรหัสการทำนาย

แนวคิด Transfer Learning, TensorFlow Hub, Google Colab เหมือนเดิม

ตัวอย่างโค้ด

print("Decoding the predictions")
labels_path = tf.keras.utils.get_file('ImageNetLabels.txt',
    'https://storage.googleapis.com/download.tensorflow.org/data/ImageNetLabels.txt')
imagenet_labels = np.array(open(labels_path).read().splitlines())
plt.imshow(grace_hopper)
plt.axis('off')
predicted_class_name = imagenet_labels[predicted_class]
_ = plt.title("Prediction is: " + predicted_class_name.title())

Credit: TensorFlow Tutorials

ผลลัพธ์

Decoding the predictions
Downloading data from https://storage.googleapis.com/download.tensorflow.org/data/ImageNetLabels.txt
16384/10484 [==============================================] - 0s 0us/step

การถอดรหัสการทำนาย (Decode Predictions) ด้วย TensorFlow และ Python

คำอธิบาย

  • ใช้ predicted class ID ดึง ImageNet labels มาถอดรหัส
  • แสดงภาพที่ทำนายบนคอนโซล