File size: 1,892 Bytes
b27cd24 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | import csv
import os
GT_PATH = "gt_facing.out"
PRED_CSV = "queue_facing_results.csv"
# -----------------------
# Load Ground Truth
# -----------------------
gt = {} # { 'IMG_5954': 'away', ... }
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() # "facing away"
label = label.replace("facing ", "") # "away"
gt[img_id] = label
print(f"Loaded {len(gt)} GT entries")
# -----------------------
# Load Predictions
# -----------------------
pred = {} # { 'IMG_5954': 'away', ... }
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()
# extract basename without extension
img_id = os.path.splitext(os.path.basename(img_path))[0]
# normalize predictions
if pred_label.startswith("sideways"):
pred_label = "sideways"
pred[img_id] = pred_label
print(f"Loaded {len(pred)} predictions")
# -----------------------
# Compare
# -----------------------
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
# -----------------------
# Output Accuracy
# -----------------------
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}")
|