myasin commited on
Commit
e2c51cc
·
1 Parent(s): 3e88d4b

Addressing the comments.

Browse files
Files changed (2) hide show
  1. tools/train_net.py +5 -5
  2. utils/cocosplit.py +31 -33
tools/train_net.py CHANGED
@@ -46,7 +46,7 @@ def get_augs(cfg):
46
  augs.append(T.RandomFlip(horizontal=horizontal_flip,
47
  vertical=not horizontal_flip))
48
  # Rotate the image between -90 to 0 degrees clockwise around the centre
49
- augs.append(T.RandomRotation(angle=[90.0, 0.0]))
50
  return augs
51
 
52
  class Trainer(DefaultTrainer):
@@ -171,11 +171,11 @@ if __name__ == "__main__":
171
  parser = default_argument_parser()
172
 
173
  # Extra Configurations for dataset names and paths
174
- parser.add_argument("--dataset_name", default="", help="The Dataset Name")
175
  parser.add_argument("--json_annotation_train", default="", metavar="FILE", help="The path to the training set JSON annotation")
176
- parser.add_argument("--image_path_train", default="", metavar="FILE", help="The path to the training set image folder")
177
- parser.add_argument("--json_annotation_val", default="", metavar="FILE", help="The path to the validation set JSON annotation")
178
- parser.add_argument("--image_path_val", default="", metavar="FILE", help="The path to the validation set image folder")
179
 
180
  args = parser.parse_args()
181
  print("Command Line Args:", args)
 
46
  augs.append(T.RandomFlip(horizontal=horizontal_flip,
47
  vertical=not horizontal_flip))
48
  # Rotate the image between -90 to 0 degrees clockwise around the centre
49
+ augs.append(T.RandomRotation(angle=[-90.0, 0.0]))
50
  return augs
51
 
52
  class Trainer(DefaultTrainer):
 
171
  parser = default_argument_parser()
172
 
173
  # Extra Configurations for dataset names and paths
174
+ parser.add_argument("--dataset_name", default="", help="The Dataset Name")
175
  parser.add_argument("--json_annotation_train", default="", metavar="FILE", help="The path to the training set JSON annotation")
176
+ parser.add_argument("--image_path_train", default="", metavar="FILE", help="The path to the training set image folder")
177
+ parser.add_argument("--json_annotation_val", default="", metavar="FILE", help="The path to the validation set JSON annotation")
178
+ parser.add_argument("--image_path_val", default="", metavar="FILE", help="The path to the validation set image folder")
179
 
180
  args = parser.parse_args()
181
  print("Command Line Args:", args)
utils/cocosplit.py CHANGED
@@ -10,7 +10,7 @@ parser.add_argument('--annotation_path', metavar='coco_annotations', type=str,
10
  help='Path to COCO annotations file.')
11
  parser.add_argument('--train', type=str, help='Where to store COCO training annotations')
12
  parser.add_argument('--test', type=str, help='Where to store COCO test annotations')
13
- parser.add_argument('--s', dest='split_ratio', type=float, required=True,
14
  help="A percentage of a split; a number in (0, 1)")
15
  parser.add_argument('--having-annotations', dest='having_annotations', action='store_true',
16
  help='Ignore all images without annotations. Keep only these with at least one annotation')
@@ -33,47 +33,45 @@ def main(annotation_path,
33
  with open(annotation_path, 'rt', encoding='UTF-8') as annotations:
34
  coco = json.load(annotations)
35
 
36
- images = coco['images']
37
- annotations = coco['annotations']
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__":
 
10
  help='Path to COCO annotations file.')
11
  parser.add_argument('--train', type=str, help='Where to store COCO training annotations')
12
  parser.add_argument('--test', type=str, help='Where to store COCO test annotations')
13
+ parser.add_argument('--split-ratio', dest='split_ratio', type=float, required=True,
14
  help="A percentage of a split; a number in (0, 1)")
15
  parser.add_argument('--having-annotations', dest='having_annotations', action='store_true',
16
  help='Ignore all images without annotations. Keep only these with at least one annotation')
 
33
  with open(annotation_path, 'rt', encoding='UTF-8') as annotations:
34
  coco = json.load(annotations)
35
 
36
+ images = coco['images']
37
+ annotations = coco['annotations']
38
 
39
+ ids_with_annotations = funcy.lmap(lambda a: int(a['image_id']), annotations)
40
 
41
+ # Images with annotations
42
+ img_ann = funcy.lremove(lambda i: i['id'] not in ids_with_annotations, images)
43
+ tr_ann, ts_ann = train_test_split(img_ann, train_size=split_ratio,
44
+ random_state=random_state)
45
 
46
+ # Images without annotations
47
+ img_wo_ann = funcy.lremove(lambda i: i['id'] in ids_with_annotations, images)
48
+ tr_wo_ann, ts_wo_ann = train_test_split(img_wo_ann, train_size=split_ratio,
49
+ random_state=random_state)
50
 
51
+ if having_annotations:
52
+ tr, ts = tr_ann, ts_ann
 
 
53
 
54
+ else:
55
+ # Merging the 2 image lists (i.e. with and without annotation)
56
+ tr_ann.extend(tr_wo_ann)
57
+ ts_ann.extend(ts_wo_ann)
58
 
59
+ tr, ts = tr_ann, ts_ann
 
 
 
60
 
61
+ # Train Data
62
+ coco.update({'images': tr,
63
+ 'annotations': filter_annotations(annotations, tr)})
64
+ save_coco(train_save_path, coco)
65
 
66
+ # Test Data
67
+ coco.update({'images': ts,
68
+ 'annotations': filter_annotations(annotations, ts)})
69
+ save_coco(test_save_path, coco)
70
 
71
+ print("Saved {} entries in {} and {} in {}".format(len(tr),
72
+ train_save_path,
73
+ len(ts),
74
+ test_save_path))
 
 
 
 
 
75
 
76
 
77
  if __name__ == "__main__":