xcmyz/FastSpeech

RuntimeError: The size of tensor a (1248) must match the size of tensor b (156) at non-singleton dimension 1

cutekih opened this issue · 2 comments

Hi~ @xcmyz

I am using LJ data and using the default settings.
However, I get the following error.

My environment:
torch 1.1.0
torchvision 0.3.0
cuda 10.1

Error related to tensor shape.
Do you know the solution?


---Start New Training---

~/miniconda2/envs/data_fastspeech/lib/python3.6/site-packages/torch/nn/modules/loss.py:91: UserWarning: Using a target size (torch.Size([8, 156])) that is different to the input size (torch.Size([1248])). This will likely lead to incorrect results due to broadcasting. Please ensure they have the same size.
return F.l1_loss(input, target, reduction=self.reduction)
Traceback (most recent call last):
File "train.py", line 193, in
main(args)
File "train.py", line 112, in main
D)
File " ~/miniconda2/envs/data_fastspeech/lib/python3.6/site-packages/torch/nn/modules/module.py", line 493, in call
result = self.forward(*input, **kwargs)
File " ~/FastSpeech/loss.py", line 27, in forward
duration_predicted, duration_predictor_target.float())
File " ~/miniconda2/envs/data_fastspeech/lib/python3.6/site-packages/torch/nn/modules/module.py", line 493, in call
result = self.forward(*input, **kwargs)
File " ~/miniconda2/envs/data_fastspeech/lib/python3.6/site-packages/torch/nn/modules/loss.py", line 91, in forward
return F.l1_loss(input, target, reduction=self.reduction)
File " ~/miniconda2/envs/data_fastspeech/lib/python3.6/site-packages/torch/nn/functional.py", line 2230, in l1_loss
expanded_input, expanded_target = torch.broadcast_tensors(input, target)
File " ~/miniconda2/envs/data_fastspeech/lib/python3.6/site-packages/torch/functional.py", line 62, in broadcast_tensors
return torch._C._VariableFunctions.broadcast_tensors(tensors)
RuntimeError: The size of tensor a (1248) must match the size of tensor b (156) at non-singleton dimension 1

xcmyz commented

Hi~ @xcmyz

I am using LJ data and using the default settings.
However, I get the following error.

My environment:
torch 1.1.0
torchvision 0.3.0
cuda 10.1

Error related to tensor shape.
Do you know the solution?

---Start New Training---

~/miniconda2/envs/data_fastspeech/lib/python3.6/site-packages/torch/nn/modules/loss.py:91: UserWarning: Using a target size (torch.Size([8, 156])) that is different to the input size (torch.Size([1248])). This will likely lead to incorrect results due to broadcasting. Please ensure they have the same size.

return F.l1_loss(input, target, reduction=self.reduction)
Traceback (most recent call last):
File "train.py", line 193, in
main(args)
File "train.py", line 112, in main
D)
File " ~/miniconda2/envs/data_fastspeech/lib/python3.6/site-packages/torch/nn/modules/module.py", line 493, in call
result = self.forward(*input, **kwargs)
File " ~/FastSpeech/loss.py", line 27, in forward
duration_predicted, duration_predictor_target.float())
File " ~/miniconda2/envs/data_fastspeech/lib/python3.6/site-packages/torch/nn/modules/module.py", line 493, in call
result = self.forward(*input, **kwargs)
File " ~/miniconda2/envs/data_fastspeech/lib/python3.6/site-packages/torch/nn/modules/loss.py", line 91, in forward
return F.l1_loss(input, target, reduction=self.reduction)
File " ~/miniconda2/envs/data_fastspeech/lib/python3.6/site-packages/torch/nn/functional.py", line 2230, in l1_loss
expanded_input, expanded_target = torch.broadcast_tensors(input, target)
File " ~/miniconda2/envs/data_fastspeech/lib/python3.6/site-packages/torch/functional.py", line 62, in broadcast_tensors
return torch._C._VariableFunctions.broadcast_tensors(tensors)
RuntimeError: The size of tensor a (1248) must match the size of tensor b (156) at non-singleton dimension 1

the size of duration_predicted is different from duration_predictor_target's. Make sure your ljspeech have the same order as this repo's.

I fixed it by modifying below. @xcmyz

fastspeech.py : class FastSpeech(nn.Module):
duration_predictor_output = duration_predictor_output.view(-1, duration_predictor_output.size(0))