-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter_results.py
33 lines (24 loc) · 999 Bytes
/
filter_results.py
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
#!/usr/bin/env python
# coding: utf-8
import shutil
import sys
from glob import glob
from pathlib import Path
from tqdm import tqdm
def get_originals(originals_dir: str) -> None:
labels_dir = f'{originals_dir}-results/labels'
images = [x for x in glob(f'{originals_dir}/*') if Path(x).is_file()]
labels = sorted(glob(f'{labels_dir}/*'))
labels_stem = [Path(x).stem for x in labels]
images_with_detections = sorted(
[x for x in images if Path(x).stem in labels_stem])
print(len(images_with_detections), len(labels))
assert len(images_with_detections) == len(labels)
for x, y in zip(images_with_detections, labels):
assert Path(x).stem == Path(y).stem
with_detection_dir_original = f'{originals_dir}-with-detection-original'
Path(with_detection_dir_original).mkdir(exist_ok=True)
for im in tqdm(images_with_detections):
shutil.copy2(im, with_detection_dir_original)
if __name__ == '__main__':
get_originals(sys.argv[1])