Merge branch 'master' of https://github.com/nasheedyasin/layout-model-training
Browse files- utils/cocosplit.py +26 -8
utils/cocosplit.py
CHANGED
@@ -38,24 +38,42 @@ def main(annotation_path,
|
|
38 |
|
39 |
number_of_images = len(images)
|
40 |
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
if having_annotations:
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
-
|
47 |
|
48 |
# Train Data
|
49 |
-
coco.update({'images':
|
50 |
-
'annotations': filter_annotations(annotations,
|
51 |
save_coco(train_save_path, coco)
|
52 |
|
53 |
# Test Data
|
54 |
-
coco.update({'images':
|
55 |
-
'annotations': filter_annotations(annotations,
|
56 |
save_coco(test_save_path, coco)
|
57 |
|
58 |
-
print("Saved {} entries in {} and {} in {}".format(len(
|
|
|
|
|
|
|
59 |
|
60 |
|
61 |
if __name__ == "__main__":
|
|
|
38 |
|
39 |
number_of_images = len(images)
|
40 |
|
41 |
+
ids_with_annotations = funcy.lmap(lambda a: int(a['image_id']), annotations)
|
42 |
+
|
43 |
+
# Images with annotations
|
44 |
+
img_ann = funcy.lremove(lambda i: i['id'] not in ids_with_annotations, images)
|
45 |
+
tr_ann, ts_ann = train_test_split(img_ann, train_size=split_ratio,
|
46 |
+
random_state=random_state)
|
47 |
+
|
48 |
+
# Images without annotations
|
49 |
+
img_wo_ann = funcy.lremove(lambda i: i['id'] in ids_with_annotations, images)
|
50 |
+
tr_wo_ann, ts_wo_ann = train_test_split(img_wo_ann, train_size=split_ratio,
|
51 |
+
random_state=random_state)
|
52 |
|
53 |
if having_annotations:
|
54 |
+
tr, ts = tr_ann, ts_ann
|
55 |
+
|
56 |
+
else:
|
57 |
+
# Merging the 2 image lists (i.e. with and without annotation)
|
58 |
+
tr_ann.extend(tr_wo_ann)
|
59 |
+
ts_ann.extend(ts_wo_ann)
|
60 |
|
61 |
+
tr, ts = tr_ann, ts_ann
|
62 |
|
63 |
# Train Data
|
64 |
+
coco.update({'images': tr,
|
65 |
+
'annotations': filter_annotations(annotations, tr)})
|
66 |
save_coco(train_save_path, coco)
|
67 |
|
68 |
# Test Data
|
69 |
+
coco.update({'images': ts,
|
70 |
+
'annotations': filter_annotations(annotations, ts)})
|
71 |
save_coco(test_save_path, coco)
|
72 |
|
73 |
+
print("Saved {} entries in {} and {} in {}".format(len(tr),
|
74 |
+
train_save_path,
|
75 |
+
len(ts),
|
76 |
+
test_save_path))
|
77 |
|
78 |
|
79 |
if __name__ == "__main__":
|