forked from ai-forever/ghost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanonymize_dataset.py
48 lines (38 loc) · 1.18 KB
/
anonymize_dataset.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import glob
import ntpath
import os
from anonymize_image import anonymize_image
from utils.startup import anon_parser
def main(args):
input_paths = glob.glob(f"{args.input_dir}//**//*.jpg", recursive=True)
src_paths, out_paths = [], []
for i_p in input_paths:
rel_path = i_p.split(args.input_dir)[1]
to_gen = f"{args.output_dir}{rel_path}"
os.makedirs(ntpath.dirname(to_gen), exist_ok=True)
src_paths.append(i_p)
out_paths.append(to_gen)
anonymize_image(src_paths, out_paths, args)
if __name__ == "__main__":
parser = anon_parser()
parser.add_argument(
"--grid",
default=[1, 1],
nargs="*", # 0 or more values expected => creates a list
type=int,
help="If specified, will render as a grid of generated samples.",
)
parser.add_argument(
"--input_dir",
type=str,
required=True,
help="Top-level directory to search for images to anonymize.",
)
parser.add_argument(
"--output_dir",
type=str,
required=True,
help="Top-level directory to place anonymized images.",
)
args = parser.parse_args()
main(args)