forked from sancarlim/stylegan2-ada-pytorch
-
Notifications
You must be signed in to change notification settings - Fork 3
/
run_projector_generator.py
67 lines (58 loc) · 2.69 KB
/
run_projector_generator.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# last modified : 22.01.2022
# By : Sandra Carrasco <[email protected]>
import numpy as np
import os
from tqdm import tqdm
import random
import json
from argparse import ArgumentParser
if __name__ == "__main__":
random.seed(0)
os.environ['PYTHONHASHSEED'] = str(0)
np.random.seed(0)
parser = ArgumentParser()
parser.add_argument("--filename", type=str, default='dataset.json')
parser.add_argument("--directory", type=str,
help='path to directory with images resided to 256x256'
)
parser.add_argument('--initial_tqdm', type=int, help='Restart projection',
default=0)
parser.add_argument('--num_images', type=int,
help='Number of images to project', default=1000000)
parser.add_argument("--task", type=str, default='project',
help='Choose task project/generate',
choices=['generate', 'project'])
parser.add_argument('--network', help='Network pickle filename',
default=None)
parser.add_argument('--trunc', type=float, help='Truncation psi',
default=1)
parser.add_argument('--class_idx', type=int,
help='Class label (unconditional if not specified)')
parser.add_argument('--num_imgs', type=int)
parser.add_argument('--outdir', help='Where to save the output images',
type=str, default=None)
args = parser.parse_args()
filename = args.filename
directory = args.directory
if args.task == 'project':
with open(os.path.join(directory, filename)) as file:
data = json.load(file)['labels']
for img, label in tqdm(data, initial=args.initial_tqdm):
img_dir = os.path.join(directory, img)
execute = "python projector.py "
execute = execute + " --outdir=" + args.outdir
execute = execute + " --target=" + img_dir
execute = execute + " --network=" + args.network
execute = execute + " --class_label " + str(label)
execute = execute + " --num-steps 1000"
os.system(execute)
else:
execute = "python generate.py "
execute = execute + " --outdir=" + args.outdir
execute = execute + " --trunc=" + str(args.trunc)
execute = execute + " --network=" + args.network
execute = execute + " --class=" + str(args.class_idx)
execute = execute + " --seeds=" + str(
np.random.randint(0, args.num_images, args.num_imgs)).replace(
'[', '').replace(']', '').replace(' ', ',')
os.system(execute)