-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove_low_scored_boxes.py
More file actions
33 lines (26 loc) · 1.08 KB
/
remove_low_scored_boxes.py
File metadata and controls
33 lines (26 loc) · 1.08 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
import argparse
import json
from utils.coco_tools import retain_annotations
def build_parser():
parser = argparse.ArgumentParser()
parser.add_argument('-json', '--json-file', required=True, type=str)
parser.add_argument('-thr', '--threshold', required=True, type=float)
parser.add_argument('-out', '--out-file', required=True, type=str)
return parser
def remove_low_scored_boxes(json_dict, threshold):
idxs_to_leave = list()
for i in range(len(json_dict['annotations'])):
if json_dict['annotations'][i]['score'] >= threshold:
idxs_to_leave.append(i)
removed = len(json_dict['annotations']) - len(idxs_to_leave)
retain_annotations(json_dict['annotations'], idxs_to_leave)
return removed
if __name__ == '__main__':
parser = build_parser()
args = parser.parse_args()
with open(args.json_file, 'r') as f:
json_dict = json.load(f)
removed = remove_low_scored_boxes(json_dict, args.threshold)
print('Removed {} boxes'.format(removed))
with open(args.out_file, 'w') as f:
json.dump(json_dict, f, indent=2)