Repository navigation
Expand file tree
/
Copy pathcreate_coco_jsons.py
More file actions
87 lines (73 loc) · 2.24 KB
/
Copy pathcreate_coco_jsons.py
File metadata and controls
87 lines (73 loc) · 2.24 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
import json
import random
def create_test_data():
ground_truth = {
"annotations": []
}
predictions = {
"annotations": []
}
image_id = 1
category_id = 1
annotation_id = 1
# Generate True Positives
for i in range(1500):
x1 = random.randint(0, 500)
y1 = random.randint(0, 500)
w = random.randint(20, 50)
h = random.randint(20, 50)
gt_box = {
"annotation_id": annotation_id,
"image_id": image_id,
"category_id": category_id,
"bbox": [x1, y1, w, h]
}
ground_truth["annotations"].append(gt_box)
pred_box = {
"annotation_id": annotation_id,
"image_id": image_id,
"category_id": category_id,
'bbox': [
x1 + random.randint(-5, 5),
y1 + random.randint(-5, 5),
w,
h
],
}
predictions["annotations"].append(pred_box)
annotation_id += 1
# Generate False Positives
for i in range(1500, 1800):
x1 = random.randint(0, 500)
y1 = random.randint(0, 500)
w = random.randint(20, 50)
h = random.randint(20, 50)
pred_box = {
"annotation_id": annotation_id,
"image_id": image_id,
"category_id": category_id,
"bbox": [x1, y1, w, h]
}
predictions["annotations"].append(pred_box)
annotation_id += 1
# Generate False Negatives
for i in range(1800, 2300):
x1 = random.randint(0, 500)
y1 = random.randint(0, 500)
w = random.randint(20, 50)
h = random.randint(20, 50)
gt_box = {
"annotation_id": annotation_id,
"image_id": image_id,
"category_id": category_id,
"bbox": [x1, y1, w, h]
}
ground_truth["annotations"].append(gt_box)
annotation_id += 1
# Save data to JSON files
with open('small_jsons/ground_truths.json', 'w') as gt_file:
json.dump(ground_truth, gt_file, indent=2)
with open('small_jsons/predictions.json', 'w') as preds_file:
json.dump(predictions, preds_file, indent=2)
if __name__ == '__main__':
create_test_data()