(ftensor, true_shape=None)
| 43 | |
| 44 | |
| 45 | def rgb(ftensor, true_shape=None): |
| 46 | if isinstance(ftensor, list): |
| 47 | return [rgb(x, true_shape=true_shape) for x in ftensor] |
| 48 | if isinstance(ftensor, torch.Tensor): |
| 49 | ftensor = ftensor.detach().cpu().numpy() # H,W,3 |
| 50 | if ftensor.ndim == 3 and ftensor.shape[0] == 3: |
| 51 | ftensor = ftensor.transpose(1, 2, 0) |
| 52 | elif ftensor.ndim == 4 and ftensor.shape[1] == 3: |
| 53 | ftensor = ftensor.transpose(0, 2, 3, 1) |
| 54 | if true_shape is not None: |
| 55 | H, W = true_shape |
| 56 | ftensor = ftensor[:H, :W] |
| 57 | if ftensor.dtype == np.uint8: |
| 58 | img = np.float32(ftensor) / 255 |
| 59 | else: |
| 60 | img = (ftensor * 0.5) + 0.5 |
| 61 | return img.clip(min=0, max=1) |
| 62 | |
| 63 | |
| 64 | def _resize_pil_image(img, long_edge_size): |
no outgoing calls
no test coverage detected