def denorm(x):
"""Convert the range from [-1, 1] to [0, 1]."""
out = (x + 1) / 2
return out.clamp_(0, 1)
def tensor2img(x_data, fname, nrow, paddoing=0):
save_image(denorm(x_data.cpu()), fname, nrow=nrow, padding=0)
方法2:
n_show_images = 4
def imshow(img: torch.Tensor):
"""
Display a single image.
"""
img = img /