-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_labels.py
More file actions
113 lines (76 loc) · 2.66 KB
/
update_labels.py
File metadata and controls
113 lines (76 loc) · 2.66 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import os
import firebase_admin
from firebase_admin import credentials, firestore
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
SERVICE_ACCOUNT_PATH = os.path.join(BASE_DIR, "serviceAccountKey.json")
if not firebase_admin._apps:
cred = credentials.Certificate(SERVICE_ACCOUNT_PATH)
firebase_admin.initialize_app(cred)
db = firestore.client()
def list_cases():
"""
List all cases stored in Firestore
"""
docs = db.collection("cases").stream()
rows = []
for doc in docs:
data = doc.to_dict()
rows.append({
"id": doc.id,
"prediction": data.get("prediction", ""),
"confidence": data.get("confidence", 0),
"groundTruth": data.get("groundTruth", ""),
})
print("\nCases in Firestore:\n")
for i, row in enumerate(rows, start=1):
print(
f"{i}. ID: {row['id']} | "
f"Prediction: {row['prediction']} | "
f"Confidence: {row['confidence']:.3f} | "
f"GroundTruth: {row['groundTruth'] or 'EMPTY'}"
)
def update_case_label(case_id: str, label: str):
"""
Update groundTruth for a specific case
"""
label = label.strip().capitalize()
if label not in {"Fracture", "Normal"}:
raise ValueError("Label must be 'Fracture' or 'Normal'")
ref = db.collection("cases").document(case_id)
snap = ref.get()
if not snap.exists:
print("Case not found")
return
ref.update({"groundTruth": label})
print(f"Updated {case_id} -> groundTruth = {label}")
def fill_empty_labels(default_label="Normal"):
"""
Fill all empty groundTruth labels
"""
docs = db.collection("cases").stream()
count = 0
for doc in docs:
data = doc.to_dict()
if not data.get("groundTruth"):
db.collection("cases").document(doc.id).update({
"groundTruth": default_label
})
count += 1
print(f"Updated {count} cases")
if __name__ == "__main__":
print("\nMEDORA Label Tool\n")
print("1 - Show all cases")
print("2 - Update single case label")
print("3 - Fill empty labels")
choice = input("\nChoose option: ")
if choice == "1":
list_cases()
elif choice == "2":
case_id = input("Enter case ID: ")
label = input("Enter label (Fracture / Normal): ")
update_case_label(case_id, label)
elif choice == "3":
label = input("Default label (Fracture / Normal): ")
fill_empty_labels(label)
else:
print("Invalid option")