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)
| 7 | |
| 8 | |
| 9 | def 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 | |
| 28 | def diagnose_network(net, name='network'): |
nothing calls this directly
no outgoing calls
no test coverage detected