Fix batched inputs longer than target_length (clips mixed) and keep the last full segment

#2
by Wataru - opened
Files changed (1) hide show
  1. modeling_dasheng.py +3 -2
modeling_dasheng.py CHANGED
@@ -381,14 +381,15 @@ class AudioTransformerMAE_Encoder(nn.Module):
381
  else:
382
  splits = torch.stack(splits[:-1], dim=0)
383
  else:
384
- splits = torch.stack(splits[:-1], dim=0)
385
  n_splits = len(splits)
386
  x = torch.flatten(splits, 0, 1) # spl b c f t-> (spl b) c f t
387
  else:
388
  n_splits = 1
389
 
390
  x = self.forward_features(x)
391
- x = torch.reshape(x, (x.shape[0] // n_splits, -1, x.shape[-1]))
 
392
  if padding_start:
393
  x = x[:,:padding_start, :]
394
  return x
 
381
  else:
382
  splits = torch.stack(splits[:-1], dim=0)
383
  else:
384
+ splits = torch.stack(splits, dim=0)
385
  n_splits = len(splits)
386
  x = torch.flatten(splits, 0, 1) # spl b c f t-> (spl b) c f t
387
  else:
388
  n_splits = 1
389
 
390
  x = self.forward_features(x)
391
+ # (spl b) t c -> b (spl t) c: each clip's own segments, in time order
392
+ x = x.reshape(n_splits, -1, *x.shape[1:]).transpose(0, 1).flatten(1, 2)
393
  if padding_start:
394
  x = x[:,:padding_start, :]
395
  return x