| import csv |
| import os |
|
|
| GT_PATH = "gt_facing.out" |
| PRED_CSV = "queue_facing_results.csv" |
|
|
| |
| |
| |
| gt = {} |
|
|
| with open(GT_PATH, "r") as f: |
| for line in f: |
| if not line.strip(): |
| continue |
| parts = line.strip().split() |
| img_id = parts[0] |
| label = " ".join(parts[1:]).lower() |
| label = label.replace("facing ", "") |
| gt[img_id] = label |
|
|
| print(f"Loaded {len(gt)} GT entries") |
|
|
|
|
| |
| |
| |
| pred = {} |
|
|
| with open(PRED_CSV, "r") as f: |
| reader = csv.DictReader(f) |
| for row in reader: |
| img_path = row["image_path"] |
| pred_label = row["facing_direction"].lower() |
|
|
| |
| img_id = os.path.splitext(os.path.basename(img_path))[0] |
|
|
| |
| if pred_label.startswith("sideways"): |
| pred_label = "sideways" |
|
|
| pred[img_id] = pred_label |
|
|
| print(f"Loaded {len(pred)} predictions") |
|
|
|
|
| |
| |
| |
| correct = 0 |
| total = 0 |
| errors = [] |
|
|
| for img_id, gt_label in gt.items(): |
| if img_id not in pred: |
| print(f"[WARN] No prediction for {img_id}") |
| continue |
|
|
| pred_label = pred[img_id] |
|
|
| if pred_label == gt_label or gt_label=="other": |
| correct += 1 |
| else: |
| errors.append((img_id, gt_label, pred_label)) |
|
|
| total += 1 |
|
|
| |
| |
| |
| accuracy = correct / total if total > 0 else 0 |
| print(f"\nAccuracy: {accuracy:.2%} ({correct}/{total})") |
|
|
| if errors: |
| print("\nIncorrect predictions:") |
| for img_id, gt_label, pred_label in errors: |
| print(f" {img_id}: GT={gt_label} | Pred={pred_label}") |
|
|