| 936 | |
| 937 | |
| 938 | def to_list(batch, non_blocking=False) -> Union[List, Dict, np.ndarray]: # almost always exporting, should block |
| 939 | if isinstance(batch, (tuple, list)): |
| 940 | batch = [to_list(b, non_blocking) for b in batch] |
| 941 | elif isinstance(batch, dict): |
| 942 | batch = dotdict({k: to_list(v, non_blocking) for k, v in batch.items()}) |
| 943 | elif isinstance(batch, torch.Tensor): |
| 944 | batch = batch.detach().to('cpu', non_blocking=non_blocking).numpy().tolist() |
| 945 | elif isinstance(batch, torch.Tensor): |
| 946 | batch = batch.tolist() |
| 947 | else: # others, keep as is |
| 948 | pass |
| 949 | return batch |
| 950 | |
| 951 | |
| 952 | def to_cpu(batch, non_blocking=False, ignore_list: bool = False) -> torch.Tensor: |