()
| 28 | |
| 29 | cur_device = None |
| 30 | def get_device(): |
| 31 | global cur_device |
| 32 | if cur_device == None: |
| 33 | if torch.cuda.is_available(): |
| 34 | cur_device = torch.device('cuda') |
| 35 | print("Uses CUDA device.") |
| 36 | elif torch.backends.mps.is_available(): |
| 37 | cur_device = torch.device('mps') |
| 38 | print("Uses MPS device.") |
| 39 | else: |
| 40 | cur_device = torch.device('cpu') |
| 41 | print("Uses CPU device.") |
| 42 | return cur_device |
| 43 | |
| 44 | def tensor2pil(image): |
| 45 | return Image.fromarray(np.clip(255. * image.cpu().numpy().squeeze(), 0, 255).astype(np.uint8)) |
no outgoing calls
no test coverage detected