-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathmulti_image.py
More file actions
executable file
·66 lines (56 loc) · 1.55 KB
/
Copy pathmulti_image.py
File metadata and controls
executable file
·66 lines (56 loc) · 1.55 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
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
import os
import math
import torch
import torch.nn.functional as F
from utils.file_utils import save_images
class Visualizer(object):
def __init__(self, args):
self.args = args
def visualize(self,
images,
model,
description: str,
save_dir: str,
step: int,
):
# Merge.
k = len(images)
assert k >= 2
bsz, c, h, w = images[0].shape
if k == 3:
bsz2, c2, h2, w2 = images[2].shape
assert bsz == bsz2 and c == c2
assert h2 == w2
assert h == w
if h == h2:
pass
else:
assert h2 < h
images = (
images[0],
images[1],
F.interpolate(images[2], size=(h, w), mode='nearest'),
)
images = torch.stack(images, dim=1).view(bsz * k, c, h, w)
# Just visualize the first 64 images.
images = images[:100 * k, :, :, :]
save_images(
images,
output_dir=save_dir,
file_prefix=description,
nrows=8,
iteration=step,
)
# Lower resolution
images_256 = F.interpolate(
images,
(256, 256),
mode='bicubic',
)
save_images(
images_256,
output_dir=save_dir,
file_prefix=f'{description}_256',
nrows=8,
iteration=step,
)