Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Đánh giá (evaluate) mô hình CNN TensorFlow Python

Đánh giá mô hình CNN đã train trên tập test, vẽ đồ thị accuracy theo epoch.

Mã ví dụ

print("Vẽ đồ thị accuracy vs 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("Đánh giá mô hình trên test set...")
test_loss, test_acc = model.evaluate(test_images, test_labels, verbose=2)
print("Độ chính xác mô hình:", test_acc)

Kết quả

Vẽ đồ thị accuracy vs epoch
Đánh giá mô hình trên test set...
313/313 - 3s - loss: 0.8884 - accuracy: 0.7053
Độ chính xác mô hình: 0.705299973487854

Đánh giá (evaluate) mô hình CNN TensorFlow Python

Giải thích

  • history.history['accuracy']: Training accuracy từng epoch.
  • history.history['val_accuracy']: Validation accuracy từng epoch.
  • Đồ thị cho thấy: Train accuracy tăng đến ~0.99, Val accuracy dao động ~0.65-0.70 → Overfitting.
  • model.evaluate(): Tính loss và metrics trên test set (chưa từng thấy).
  • Test accuracy ~70.5% - mô hình cơ bản, có thể cải thiện với data augmentation, dropout, transfer learning.