I was writing a speech recognition code, but he got -inf for some values in the mel spectrum
I identified that it was caused by the extension part filled with 0 to align with the batch
So if you reset -inf to 0 with masked_fill as shown below, it should be restored.But it doesn’t work.Why is this? ?
model=VQVAE(hp).to("cuda")
inp=torch.randn(32,96000)
melns=torch.tensor([376,370,376,376,
280,270,300,260]).to("cuda")
inp[7][90000:]*=0
inp=inp.masked_fill(float('-inf') == inp,0.)
inpspec = spectrogram(inp).log2().to("cuda")
print(inpspec.size(),inpspec[7])
result
tensor([[ 9.2075, 7.7891, 5.3404, ..., -inf, -inf, -inf],
[ 9.1560, 7.3915, 5.9799, ..., -inf, -inf, -inf],
[ 9.0153, 5.9043, 6.7280, ..., -inf, -inf, -inf],
...,
[ 9.5787, 9.9251, 10.2523, ..., -inf, -inf, -inf],
[ 8.1497, 10.1253, 10.8566, ..., -inf, -inf, -inf],
[ 9.8009, 10.7202, 11.2168, ..., -inf, -inf, -inf]],
device='cuda:0')
Also, if you try float(‘-inf’) != inp,0., everything will be -inf