Convert a NumPy image to a PyTorch tensor.
(images: np.ndarray)
| 130 | |
| 131 | @staticmethod |
| 132 | def numpy_to_pt(images: np.ndarray) -> torch.Tensor: |
| 133 | """ |
| 134 | Convert a NumPy image to a PyTorch tensor. |
| 135 | """ |
| 136 | if images.ndim == 3: |
| 137 | images = images[..., None] |
| 138 | |
| 139 | images = torch.from_numpy(images.transpose(0, 3, 1, 2)) |
| 140 | return images |
| 141 | |
| 142 | @staticmethod |
| 143 | def pt_to_numpy(images: torch.Tensor) -> np.ndarray: |
no outgoing calls