-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.py
41 lines (34 loc) · 1.53 KB
/
generate.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
from lib.model import Texture_generator
from lib.options import options
import torchvision.utils as vutils
import argparse
import json
import os
parser = argparse.ArgumentParser()
parser.add_argument("-o", "--output", help="output directory", metavar="Output", type=str, required=True)
parser.add_argument("-c", "--config", help="network config", metavar="Config", type=str, required=True)
parser.add_argument("-n", "--number", help="number of generated images", metavar ="Number", type=int, default=1)
parser.add_argument("-d", "--device", help="using device", metavar ="Device", type=str, choices=["cpu", "cuda"], default="cpu")
parser.add_argument("-s", "--spatial", help="spatial size", metavar ="Size", type=int, default=6)
parser.add_argument("--device_ids", help="device ids", metavar ="IDs", nargs='+', type=int, default=[0])
args = parser.parse_args()
with open(args.config, 'r') as config:
config_j = json.loads(config.read())
args = parser.parse_args()
opt = options(args)
opt.spatial_size = args.spatial
gen = Texture_generator(opt)
for b in range(args.number // opt.batch_size + 1):
img = gen.generate(opt.spatial_size)
i = 0
while i < opt.batch_size and i < args.number - b*opt.batch_size:
num = i+b*opt.batch_size
print(f"Generating image: {num+1:{len(str(args.number))}}/{args.number}")
vutils.save_image(
img[i],
os.path.join(args.output + f"{num}.png"),
padding=0,
nrow=1,
normalize=True,
)
i += 1