| 286 | """ |
| 287 | |
| 288 | def _img2tensor(img): |
| 289 | if img.ndim == 2: |
| 290 | tensor = torch.from_numpy(img[None, None,]).type(out_type) |
| 291 | elif img.ndim == 3: |
| 292 | tensor = torch.from_numpy(rearrange(img, 'h w c -> c h w')).type(out_type).unsqueeze(0) |
| 293 | else: |
| 294 | raise TypeError(f'2D or 3D numpy array expected, got{img.ndim}D array') |
| 295 | return tensor |
| 296 | |
| 297 | if not (isinstance(imgs, np.ndarray) or (isinstance(imgs, list) and all(isinstance(t, np.ndarray) for t in imgs))): |
| 298 | raise TypeError(f'Numpy array or list of numpy array expected, got {type(imgs)}') |