(img, bgr2rgb, float32)
| 95 | """ |
| 96 | |
| 97 | def _totensor(img, bgr2rgb, float32): |
| 98 | if img.shape[2] == 3 and bgr2rgb: |
| 99 | if img.dtype == 'float64': |
| 100 | img = img.astype('float32') |
| 101 | img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) |
| 102 | img = torch.from_numpy(img.transpose(2, 0, 1)) |
| 103 | if float32: |
| 104 | img = img.float() |
| 105 | return img |
| 106 | |
| 107 | if isinstance(imgs, list): |
| 108 | return [_totensor(img, bgr2rgb, float32) for img in imgs] |