(batch)
| 986 | |
| 987 | |
| 988 | def add_batch(batch) -> Union[torch.Tensor, np.ndarray]: |
| 989 | if isinstance(batch, (tuple, list)): |
| 990 | batch = [add_batch(b) for b in batch] |
| 991 | elif isinstance(batch, dict): |
| 992 | batch = dotdict({k: add_batch(v) for k, v in batch.items()}) |
| 993 | elif isinstance(batch, (torch.Tensor, np.ndarray)): # numpy and others |
| 994 | batch = batch[None] |
| 995 | else: |
| 996 | batch = torch.as_tensor(batch)[None] |
| 997 | return batch |
| 998 | |
| 999 | |
| 1000 | def add_iter(batch, iter, total) -> Union[torch.Tensor, np.ndarray]: |