非常优雅的两句话
编程的魅力
for i in range(hyperparameters['batch_size']):
img_gen = x_ba[i].cpu()
img_GT = x_a[i].cpu()
#img_GT = img_GT.numpy()
#print(img_GT.shape)
#img_GT.save("./output_GT.jpg")
#########unnormalize
mean = (0.5, 0.5, 0.5)
std = (0.5, 0.5, 0.5)
#t_mean = torch.FloatTensor(mean).view(3,1,1).expand(3,H,W).contiguous().view(1,3,H,W)
#t_std = torch.FloatTensor(std).view(3,1,1).expand(3,H,W).contiguous().view(1,3,H,W)
#x = y * t_std.expand(B,3,H,W) +t_mean.expand(B,3,H,W)
t_mean = torch.FloatTensor(mean).view(3,1,1).expand(3, 120, 120)
t_std = torch.FloatTensor(std).view(3,1,1).expand(3, 120, 120)
print(t_mean.shape)
print(t_std.shape)
print(img_GT.shape)
img_GT = img_GT * t_std +t_mean
img = torchvision.transforms.ToPILImage()(img_GT).convert('RGB')
img.save("./output_GT.jpg")