Convert a NumPy image to a PyTorch tensor.
(images: np.ndarray)
| 112 | |
| 113 | @staticmethod |
| 114 | def numpy_to_pt(images: np.ndarray) -> torch.FloatTensor: |
| 115 | """ |
| 116 | Convert a NumPy image to a PyTorch tensor. |
| 117 | """ |
| 118 | if images.ndim == 3: |
| 119 | images = images[..., None] |
| 120 | |
| 121 | images = torch.from_numpy(images.transpose(0, 3, 1, 2)) |
| 122 | return images |
| 123 | |
| 124 | @staticmethod |
| 125 | def pt_to_numpy(images: torch.FloatTensor) -> np.ndarray: |