-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseed_test_cases.py
More file actions
99 lines (70 loc) · 2.25 KB
/
seed_test_cases.py
File metadata and controls
99 lines (70 loc) · 2.25 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
import os
import random
import uuid
import firebase_admin
from firebase_admin import credentials, firestore
from datetime import datetime
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 generate_case():
"""
Generate one synthetic case
"""
# randomly choose real label
ground_truth = random.choice(["Fracture", "Normal"])
# simulate model prediction
if ground_truth == "Fracture":
confidence = random.uniform(0.6, 0.95)
prediction = (
"Fracture"
if random.random() < 0.85
else "Normal"
)
else:
confidence = random.uniform(0.05, 0.4)
prediction = (
"Normal"
if random.random() < 0.85
else "Fracture"
)
case = {
"prediction": prediction,
"confidence": confidence,
"fractureProbability": confidence,
"riskLevel": (
"High" if confidence >= 0.8
else "Moderate" if confidence >= 0.5
else "Low"
),
"boxes": [],
"originalImageBase64": "",
"annotatedImageBase64": "",
"gradCamBase64": "",
"modelName": "EfficientNet-B3 + YOLOv8",
"summary": "Synthetic evaluation case",
"recommendation": "Test dataset entry",
"groundTruth": ground_truth,
"createdAt": firestore.SERVER_TIMESTAMP,
}
return case
def seed_cases(count=100):
print(f"\nGenerating {count} test cases...\n")
for i in range(count):
case = generate_case()
doc_id = str(uuid.uuid4())
db.collection("cases").document(doc_id).set(case)
if i % 10 == 0:
print(f"{i} cases inserted")
print("\nDone.")
if __name__ == "__main__":
print("\nMEDORA Dataset Seeder\n")
count = input("How many cases to generate? (default 100): ")
if count.strip() == "":
count = 100
else:
count = int(count)
seed_cases(count)