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

TensorFlow: ประเมินผลโมเดล CNN ด้วย Python

ประเมินประสิทธิภาพโมเดล CNN ที่ฝึกแล้ว ด้วย model.evaluate() และวาดกราฟ accuracy

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

print("วาดกราฟ Accuracy ต่อ Epoch...")
plt.plot(history.history['accuracy'], label='accuracy')
plt.plot(history.history['val_accuracy'], label='val_accuracy')
plt.xlabel('Epoch')
plt.ylabel('Accuracy')
plt.ylim([0.5, 1])
plt.legend(loc='lower right')

print("กำลังประเมินโมเดล...")
test_loss, test_acc = model.evaluate(test_images, test_labels, verbose=2)
print("ความแม่นยำของโมเดล:", test_acc)

ผลลัพธ์

วาดกราฟ Accuracy ต่อ Epoch...
กำลังประเมินโมเดล...
313/313 - 3s - loss: 0.8884 - accuracy: 0.7053
ความแม่นยำของโมเดล: 0.705299973487854

TensorFlow: ประเมินผลโมเดล CNN ด้วย Python

คำอธิบาย

  • history.history['accuracy'] และ val_accuracy: ข้อมูล accuracy ทุก epoch จากการฝึก
  • model.evaluate(): คำนวณ loss และ metrics บน test set (ข้อมูลที่ไม่เคยเห็น)
  • Test accuracy: 70.5% - ประสิทธิภาพบนข้อมูลทดสอบ
  • กราฟแสดง training accuracy สูงขึ้นเรื่อยๆ (เกือบ 100%) แต่ validation accuracy คงที่ ~70% -> Overfitting
  • เทคนิคแก้ overfitting: Data Augmentation, Dropout, Regularization