Vidhiwar / multimodule-ecg-classification

Multi-module Recurrent Convolutional Neural Network with Transformer Encoder for ECG Arrhythmia Classification
92 stars 20 forks source link

An Error: RuntimeError: 0D or 1D target tensor expected, multi-target not supported #4

Closed gredagger closed 1 year ago

gredagger commented 2 years ago

Traceback (most recent call last): File "ecg_mitbih.py", line 431, in main() File "ecg_mitbih.py", line 288, in main train_loss, train_acc = train(trainloader, model, criterion, optimizer, epoch, use_cuda) File "ecg_mitbih.py", line 337, in train loss = criterion(outputs, targets) File "D:\Miniconda3\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 1102, in _call_impl return forward_call(*input, **kwargs) File "D:\Miniconda3\envs\pytorch\lib\site-packages\torch\nn\modules\loss.py", line 1150, in forward return F.cross_entropy(input, target, weight=self.weight, File "D:\Miniconda3\envs\pytorch\lib\site-packages\torch\nn\functional.py", line 2846, in cross_entropy return torch._C._nn.cross_entropy_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index, label_smoothing) RuntimeError: 0D or 1D target tensor expected, multi-target not supported

I recived this error when I tried to run ecg_mitbih.py. I try to output the shape of outputs and targets, where cause the error. I found that outputs is batch_size 6 with targets is batch_size 10. (Before that, I follow the transform_data.ipynb, and get the dataset as ecg signal partitioned into 10 segments. Maybe the error is caused by that?)