Create a VarLenTensor from a list of tensors.
(tensor_list: List[torch.Tensor])
| 41 | |
| 42 | @staticmethod |
| 43 | def from_tensor_list(tensor_list: List[torch.Tensor]) -> 'VarLenTensor': |
| 44 | """ |
| 45 | Create a VarLenTensor from a list of tensors. |
| 46 | """ |
| 47 | feats = torch.cat(tensor_list, dim=0) |
| 48 | layout = [] |
| 49 | start = 0 |
| 50 | for tensor in tensor_list: |
| 51 | layout.append(slice(start, start + tensor.shape[0])) |
| 52 | start += tensor.shape[0] |
| 53 | return VarLenTensor(feats, layout) |
| 54 | |
| 55 | def to_tensor_list(self) -> List[torch.Tensor]: |
| 56 | """ |