flinkerlab / neural_speech_decoding

GNU General Public License v3.0
89 stars 11 forks source link

STOI_Loss calculation issue #1

Closed pshepelenko closed 5 months ago

pshepelenko commented 6 months ago

Hi! When I try to launch the script on a GPU using python train_a2a.py --OUTPUT_DIR output/a2a/HB02 --trainsubject HB02 --testsubject HB02 --param_file configs/a2a_production.yaml --batch_size 16 --reshape 1 --DENSITY "HB" --wavebased 1 --n_filter_samples 80 --n_fft 256 --formant_supervision 1 --intensity_thres -1 --epoch_num 60 I face this error: Traceback (most recent call last):

  File "C:\Users\User\Documents\HSE\BCI\neural_speech_decoding-main\train_a2a.py", line 947, in <module>
    run(
  File "C:\Users\User\Documents\HSE\BCI\neural_speech_decoding-main\utils\launcher.py", line 174, in run
    _run(0, world_size, fn, defaults, write_log, no_cuda, args_)
  File "C:\Users\User\Documents\HSE\BCI\neural_speech_decoding-main\utils\launcher.py", line 158, in _run
    fn(**matching_args_)
  File "C:\Users\User\Documents\HSE\BCI\neural_speech_decoding-main\train_a2a.py", line 291, in train
    model = Model(
  File "C:\Users\User\Documents\HSE\BCI\neural_speech_decoding-main\model.py", line 382, in __init__
    self.stoi_loss_female = STOI_Loss(extended=False, plus=True, FFT_size=256)
  File "C:\Users\User\Documents\HSE\BCI\neural_speech_decoding-main\model.py", line 178, in __init__
    self.loss_func = NegSTOILoss(
  File "C:\Users\User\Documents\HSE\BCI\neural_speech_decoding-main\metrics\torch_stoi.py", line 78, in __init__
    self.resample = torchaudio.transforms.Resample(
  File "C:\Users\User\anaconda3\lib\site-packages\torchaudio\transforms\_transforms.py", line 957, in __init__
    kernel, self.width = _get_sinc_resample_kernel(
  File "C:\Users\User\anaconda3\lib\site-packages\torchaudio\functional\functional.py", line 1432, in _get_sinc_resample_kernel
    window = torch.i0(beta_tensor * torch.sqrt(1 - (t / lowpass_filter_width) ** 2)) / torch.i0(beta_tensor)
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!

I tried to add .to('cuda') in a model description, but that didn't work. Could you please help me to solve this issue.

pshepelenko commented 5 months ago

Moving a Resample method to a separate file into the same folder as torch_stoi.py solved the issue

james20141606 commented 5 months ago

Hi thanks for the solution. another solution is manually add device information to the variable