MCPcopy Create free account
hub / github.com/modelscope/modelscope / _collate_frames

Function _collate_frames

modelscope/preprocessors/ofa/utils/collate.py:153–166  ·  view source on GitHub ↗

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])

Source from the content-addressed store, hash-verified

151
152
153def _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

Callers 1

collate_fnFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…