Convert strpath, PIL.Image.Image, numpy.ndarray, torch.Tensor image(s) to a torch.Tensor. Args: imgs (list[strpath] | list[PIL.Image.Image] | list[numpy.ndarray] | list[torch.Tensor] | strpath | PIL.Image.Image | numpy.ndarray | torch.Tensor): The input images. Returns: tor
(imgs)
| 34 | |
| 35 | |
| 36 | def any2tensor(imgs): |
| 37 | """Convert strpath, PIL.Image.Image, numpy.ndarray, torch.Tensor image(s) to a torch.Tensor. |
| 38 | |
| 39 | Args: |
| 40 | imgs (list[strpath] | list[PIL.Image.Image] | list[numpy.ndarray] | list[torch.Tensor] | strpath | PIL.Image.Image | numpy.ndarray | torch.Tensor): The input images. |
| 41 | |
| 42 | Returns: |
| 43 | torch.Tensor: The converted image(s). |
| 44 | """ |
| 45 | if isinstance(imgs, list): |
| 46 | return torch.stack([_any2tensor(img) for img in imgs], dim=0) |
| 47 | elif isinstance(imgs, (str, PIL.Image.Image, numpy.ndarray, torch.Tensor)): |
| 48 | return _any2tensor(imgs) |
| 49 | else: |
| 50 | raise TypeError('imgs is an unsupported type, imgs should be list[strpath] | list[PIL.Image.Image] | list[numpy.ndarray] | list[torch.Tensor] | strpath | PIL.Image.Image | numpy.ndarray | torch.Tensor. But got {}'.format(type(imgs))) |