MCPcopy Create free account
hub / github.com/NVIDIA/pix2pixHD / tensor2im

Function tensor2im

util/util.py:10–24  ·  view source on GitHub ↗
(image_tensor, imtype=np.uint8, normalize=True)

Source from the content-addressed store, hash-verified

8# Converts a Tensor into a Numpy array
9# |imtype|: the desired type of the converted numpy array
10def tensor2im(image_tensor, imtype=np.uint8, normalize=True):
11 if isinstance(image_tensor, list):
12 image_numpy = []
13 for i in range(len(image_tensor)):
14 image_numpy.append(tensor2im(image_tensor[i], imtype, normalize))
15 return image_numpy
16 image_numpy = image_tensor.cpu().float().numpy()
17 if normalize:
18 image_numpy = (np.transpose(image_numpy, (1, 2, 0)) + 1) / 2.0 * 255.0
19 else:
20 image_numpy = np.transpose(image_numpy, (1, 2, 0)) * 255.0
21 image_numpy = np.clip(image_numpy, 0, 255)
22 if image_numpy.shape[2] == 1 or image_numpy.shape[2] > 3:
23 image_numpy = image_numpy[:,:,0]
24 return image_numpy.astype(imtype)
25
26# Converts a one-hot tensor into a colorful label map
27def tensor2label(label_tensor, n_label, imtype=np.uint8):

Callers 1

tensor2labelFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected