cargan icon indicating copy to clipboard operation
cargan copied to clipboard

TypeError: can't convert np.ndarray of type numpy.uint16.

Open zerlinwang opened this issue 2 years ago • 3 comments

When I ran the code with my own dataset python -m cargan.preprocess --dataset ljspeech An error occured

Traceback (most recent call last):
File "XX/anaconda3/envs/cargan/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "XX/anaconda3/envs/cargan/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "XX/models/cargan/cargan/preprocess/main.py", line 26, in
cargan.preprocess.datasets(**vars(parse_args()))
File "XX/models/cargan/cargan/preprocess/core.py", line 37, in datasets
mels, pitch, periodicity = from_audio(audio, gpu=gpu)
File "XX/models/cargan/cargan/preprocess/core.py", line 62, in from_audio
pitch, periodicity = cargan.preprocess.pitch.from_audio(
File "XX/models/cargan/cargan/preprocess/pitch.py", line 38, in from_audio
pitch, periodicity = torchcrepe.predict(
File "XX/anaconda3/envs/cargan/lib/python3.8/site-packages/torchcrepe-0.0.15-py3.8.egg/torchcrepe/core.py", line 127, in predict
result = postprocess(probabilities,
File "XX/anaconda3/envs/cargan/lib/python3.8/site-packages/torchcrepe-0.0.15-py3.8.egg/torchcrepe/core.py", line 605, in postprocess
bins, pitch = decoder(probabilities)
File "XX/anaconda3/envs/cargan/lib/python3.8/site-packages/torchcrepe-0.0.15-py3.8.egg/torchcrepe/decode.py", line 76, in viterbi
bins = torch.tensor(bins, device=probs.device)
TypeError: can't convert np.ndarray of type numpy.uint16. The only supported types are: float64, float32, float16, complex64, complex128, int64, int32, int16, int8, uint8, and bool.

I guess it is cause by

  # Perform viterbi decoding
    bins = [librosa.sequence.viterbi(sequence, viterbi.transition)
            for sequence in sequences]
    # Convert to pytorch
    bins = torch.tensor(bins, device=probs.device)

in torchcrepe\decode.py

The datatype of bins is numpy.unint 16. Whether I need to modify the code in torchcrepe ?

zerlinwang avatar Mar 11 '22 07:03 zerlinwang

You do not need to modify torchcrepe. ljspeech is not a dataset that I implemented. You should check how you setup that dataset and compare it to the examples provided in cargan/data/download.py.

maxrmorrison avatar Mar 17 '22 18:03 maxrmorrison

Have the same issue, looks like librosa.sequence.viterbi returns np.uint16 values which is unsupported by torch.tensor

daniil-lyakhov avatar Apr 02 '22 09:04 daniil-lyakhov

Yep, you were both correct. librosa updated the return type of librosa.sequence.viterbi from np.int64 to np.uint16. Fixed in torchcrepe version 0.0.16.

maxrmorrison avatar Apr 03 '22 22:04 maxrmorrison