awni / speech

A PyTorch Implementation of End-to-End Models for Speech-to-Text
Apache License 2.0
750 stars 176 forks source link

pytest failure #29

Closed JeremyCCHsu closed 6 years ago

JeremyCCHsu commented 6 years ago

Environment

Titan Xp CUDA 9.0 cnDNN 7.1.3

Ubuntu 16.04 Python 2.7 Pytorch 0.4.0

Code to reproduce the issue

git clone https://github.com/awni/speech.git
cd speech
conda create -n asr -y python=2.7
source activate asr
pip install -r requirements
pip install http://download.pytorch.org/whl/cu90/torch-0.4.0-cp27-cp27mu-linux_x86_64.whl 
pip install torchvision 
make
source setup.sh
cd test
pytest

when I was running the training on my own data (or with pytest), it fails with the following error:

ERROR: TypeError: activations must be <type 'torch.FloatTensor'>

Anyone has an idea what happens? This issue persists with or without GPU.

============================= test session starts ==============================
platform linux2 -- Python 2.7.15, pytest-3.2.3, py-1.4.34, pluggy-0.4.0
rootdir: /data2/colosseum/test-speech2/speech/tests, inifile:
collected 9 items

ctc_test.py F.
io_test.py .
loader_test.py ..
model_test.py .
seq2seq_test.py .
wave_test.py ..

=================================== FAILURES ===================================

________________________________ test_ctc_model ________________________________

    def test_ctc_model():
        freq_dim = 40
        vocab_size = 10

        batch = shared.gen_fake_data(freq_dim, vocab_size)
        batch_size = len(batch[0])

        model = CTC(freq_dim, vocab_size, shared.model_config)
        out = model(batch)

        assert out.size()[0] == batch_size

        # CTC model adds the blank token to the vocab
        assert out.size()[2] == (vocab_size + 1)

        assert len(out.size()) == 3

>       loss = model.loss(batch)

ctc_test.py:26:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../speech/models/ctc_model.py:39: in loss
    loss = loss_fn(out, y, x_lens, y_lens)
../libs/warp-ctc/pytorch_binding/functions/ctc.py:77: in forward
    costs = parent.forward(*args)
../libs/warp-ctc/pytorch_binding/functions/ctc.py:41: in forward
    certify_inputs(activations, labels, lengths, label_lengths)
../libs/warp-ctc/pytorch_binding/functions/ctc.py:107: in certify_inputs
    check_type(activations, torch.FloatTensor, "activations")
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

var = tensor([[[-0.0090,  0.4523,  0.0716,  ...,  0.0900, -0.0668,  0.1392],
       ...1443],
         [ 0.1413, -0.0695,  0.0591,  ..., -0.3491, -0.0151, -0.0068]]])
t = <type 'torch.FloatTensor'>, name = 'activations'

    def check_type(var, t, name):
        if type(var) is not t:
>           raise TypeError("{} must be {}".format(name, t))
E           TypeError: activations must be <type 'torch.FloatTensor'>

../libs/warp-ctc/pytorch_binding/functions/ctc.py:92: TypeError
====================== 1 failed, 8 passed in 3.60 seconds ======================
edchengg commented 6 years ago

I got the same error. I tried to change the type of activation to floatTensor but the type is still tensor. Have you fixed this error?

edchengg commented 6 years ago

Hi @JeremyCCHsu, I changed the check_type() function in /libs/warp-ctc/pytorch_binding/functions/ctc.py to

def check_type(var, t, name): if not isinstance(var, t): raise TypeError("{} must be {}".format(name, t))

`pytest ======================================= test session starts ======================================= platform darwin -- Python 2.7.15, pytest-3.2.3, py-1.4.34, pluggy-0.4.0 rootdir: /Users/edison/PycharmProjects/speech-master/tests, inifile: collected 9 items

ctc_test.py .. io_test.py . loader_test.py .. model_test.py . seq2seq_test.py . wave_test.py ..

==================================== 9 passed in 0.82 seconds ===================================== `

x.type() is the right way to show the type of a tensor ==> 'torch.FloatTensor' type(x) only returns torch.tensor.

JeremyCCHsu commented 6 years ago

@edchengg Thank you so much! I didn't realize this and what x.type() returned was a string...