55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
import sys
|
|
import json
|
|
from pathlib import Path
|
|
import matplotlib.pyplot as plt
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
from utils.config import MODEL_DIR, ACCURACY_DIR, LOSS_DIR
|
|
|
|
CATEGORIES = ["kata", "abjad_bisindo", "abjad_sibi", "angka"]
|
|
|
|
def main():
|
|
for category in CATEGORIES:
|
|
history_path = MODEL_DIR / category / "history.json"
|
|
|
|
if not history_path.exists():
|
|
print(f"History not found for {category} at {history_path}")
|
|
continue
|
|
|
|
with open(history_path, 'r') as f:
|
|
history = json.load(f)
|
|
|
|
# Plot Accuracy
|
|
plt.figure(figsize=(10, 6))
|
|
plt.plot(history['train_acc'], label='Train Accuracy')
|
|
plt.plot(history['test_acc'], label='Test (Validation) Accuracy')
|
|
|
|
title_name = category.replace("_", " ").title()
|
|
|
|
plt.title(f'{title_name} Model Accuracy')
|
|
plt.xlabel('Epoch')
|
|
plt.ylabel('Accuracy (%)')
|
|
plt.legend()
|
|
plt.grid(True)
|
|
acc_path = ACCURACY_DIR / f"{category}_accuracy.png"
|
|
plt.savefig(acc_path)
|
|
plt.close()
|
|
print(f"[{category}] Accuracy plot saved to: {acc_path}")
|
|
|
|
# Plot Loss
|
|
plt.figure(figsize=(10, 6))
|
|
plt.plot(history['train_loss'], label='Train Loss')
|
|
plt.plot(history['test_loss'], label='Test (Validation) Loss')
|
|
plt.title(f'{title_name} Model Loss')
|
|
plt.xlabel('Epoch')
|
|
plt.ylabel('Loss')
|
|
plt.legend()
|
|
plt.grid(True)
|
|
loss_path = LOSS_DIR / f"{category}_loss.png"
|
|
plt.savefig(loss_path)
|
|
plt.close()
|
|
print(f"[{category}] Loss plot saved to: {loss_path}")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|