MCPcopy Create free account
hub / github.com/thygate/stable-diffusion-webui-depthmap-script / tensor2im

Function tensor2im

pix2pix/util/util.py:9–25  ·  view source on GitHub ↗

Converts a Tensor array into a numpy image array. Parameters: input_image (tensor) -- the input image tensor array imtype (type) -- the desired type of the converted numpy array

(input_image, imtype=np.uint16)

Source from the content-addressed store, hash-verified

7
8
9def tensor2im(input_image, imtype=np.uint16):
10 """"Converts a Tensor array into a numpy image array.
11
12 Parameters:
13 input_image (tensor) -- the input image tensor array
14 imtype (type) -- the desired type of the converted numpy array
15 """
16 if not isinstance(input_image, np.ndarray):
17 if isinstance(input_image, torch.Tensor): # get the data from a variable
18 image_tensor = input_image.data
19 else:
20 return input_image
21 image_numpy = torch.squeeze(image_tensor).cpu().numpy() # convert it into a numpy array
22 image_numpy = (image_numpy + 1) / 2.0 * (2**16-1) #
23 else: # if it is a numpy array, do nothing
24 image_numpy = input_image
25 return image_numpy.astype(imtype)
26
27
28def diagnose_network(net, name='network'):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected