forked from VIROBO-15/UDBNET
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVisulaizer.py
34 lines (25 loc) · 1.06 KB
/
Visulaizer.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
import numpy
import torch
import torchvision
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
from torch.utils.tensorboard import SummaryWriter
import os
import shutil
class Visualizer:
def __init__(self):
if os.path.exists('runs'):
shutil.rmtree('runs')
self.writer = SummaryWriter()
self.mean = torch.tensor([-1.0, -1.0, -1.0]).to(device)
self.std = torch.tensor([1 / 0.5, 1 / 0.5, 1 / 0.5]).to(device)
def vis_image(self, visularize, step):
for keys, value in visularize.items():
#print(keys,value.size())
""" Denormalization """
value.sub_(self.mean[None, :, None, None]).div_(self.std[None, :, None, None])
visularize[keys] = torchvision.utils.make_grid(value)
self.writer.add_image('{}'.format(keys), visularize[keys], step)
def plot_current_errors(self, iters, errors):
for keys, value in errors.items():
#print(keys,value.size())
self.writer.add_scalar('{}'.format(iters,keys), errors[keys])