Convert a list of 2D frames into a padded 3D tensor Args: frames (list): list of 2D frames of size L[i]*f_dim. Where L[i] is length of i-th frame and f_dim is static dimension of features Returns: 3D tensor of size len(frames)*len_max*f_dim where len_max is m
(frames: List[torch.Tensor])
| 151 | |
| 152 | |
| 153 | def _collate_frames(frames: List[torch.Tensor]): |
| 154 | """ |
| 155 | Convert a list of 2D frames into a padded 3D tensor |
| 156 | Args: |
| 157 | frames (list): list of 2D frames of size L[i]*f_dim. Where L[i] is |
| 158 | length of i-th frame and f_dim is static dimension of features |
| 159 | Returns: |
| 160 | 3D tensor of size len(frames)*len_max*f_dim where len_max is max of L[i] |
| 161 | """ |
| 162 | max_len = max(frame.size(0) for frame in frames) |
| 163 | out = frames[0].new_zeros((len(frames), max_len, frames[0].size(1))) |
| 164 | for i, v in enumerate(frames): |
| 165 | out[i, :v.size(0)] = v |
| 166 | return out |
no test coverage detected
searching dependent graphs…