This implementation is slightly faster than tensor2img. It now only supports torch tensor with shape (1, c, h, w). Args: tensor (Tensor): Now only support torch tensor with (1, c, h, w). rgb2bgr (bool): Whether to change rgb to bgr. Default: True. min_max (tuple[int]
(tensor, rgb2bgr=True, min_max=(0, 1))
| 95 | |
| 96 | |
| 97 | def tensor2img_fast(tensor, rgb2bgr=True, min_max=(0, 1)): |
| 98 | """This implementation is slightly faster than tensor2img. |
| 99 | It now only supports torch tensor with shape (1, c, h, w). |
| 100 | |
| 101 | Args: |
| 102 | tensor (Tensor): Now only support torch tensor with (1, c, h, w). |
| 103 | rgb2bgr (bool): Whether to change rgb to bgr. Default: True. |
| 104 | min_max (tuple[int]): min and max values for clamp. |
| 105 | """ |
| 106 | output = tensor.squeeze(0).detach().clamp_(*min_max).permute(1, 2, 0) |
| 107 | output = (output - min_max[0]) / (min_max[1] - min_max[0]) * 255 |
| 108 | output = output.type(torch.uint8).cpu().numpy() |
| 109 | if rgb2bgr: |
| 110 | output = cv2.cvtColor(output, cv2.COLOR_RGB2BGR) |
| 111 | return output |
| 112 | |
| 113 | |
| 114 | def imfrombytes(content, flag='color', float32=False): |
nothing calls this directly
no outgoing calls
no test coverage detected