SIP Finetune on CheXpert - Validation sanity check error - target has to be an integer tensor
See original GitHub issueHello, I am trying to finetune with train_sip.py and the public dataset CheXpert. At the moment, I simply launched the training by specifying one of the pretrained model available online and the dataset name and directory. Is there any other configuration step that should be made?
At the moment, i am getting the error “target has to be an integer tensor” during _basic_input_validation (see log below). When going back to the function validation_epoch_end (“sip_finetune.py”, line 213), i noticed that “targets” is defined as a Tensor - dtype = float32 , while “logits” values are in the range [-1,1]. I was expecting them to be between 0 and 1… is that right? What could I do to fix this?
Thank you in advance! Silvia
LOG: _Validation sanity check: 50%|█████ | 1/2 [00:00<00:00, 1.40it/s]path: Atelectasis, len: 64 Traceback (most recent call last):
File “/Facebook_NYU/CovidPrognosis-master/cp_examples/sip_finetune/train_sip.py”, line 205, in <module> cli_main(args)
[…] File “/Facebook_NYU/CovidPrognosis-master/cp_examples/sip_finetune/sip_finetune.py”, line 231, in validation_epoch_end self.val_acc[i](logits, targets)
File “/home/anaconda3/envs/facebook/lib/python3.9/site-packages/torch/nn/modules/module.py”, line 889, in _call_impl result = self.forward(*input, **kwargs)
File “/home/anaconda3/envs/facebook/lib/python3.9/site-packages/torchmetrics/metric.py”, line 152, in forward self.update(*args, **kwargs)
File “/home/anaconda3/envs/facebook/lib/python3.9/site-packages/torchmetrics/metric.py”, line 199, in wrapped_func return update(*args, **kwargs)
File “/home/anaconda3/envs/facebook/lib/python3.9/site-packages/pytorch_lightning/metrics/classification/accuracy.py”, line 138, in update correct, total = _accuracy_update(
File “/home/anaconda3/envs/facebook/lib/python3.9/site-packages/pytorch_lightning/metrics/functional/accuracy.py”, line 25, in _accuracy_update preds, target, mode = _input_format_classification(preds, target, threshold=threshold, top_k=top_k)
File “/home/anaconda3/envs/facebook/lib/python3.9/site-packages/pytorch_lightning/metrics/classification/helpers.py”, line 433, in _input_format_classification case = _check_classification_inputs(
File “/home/anaconda3/envs/facebook/lib/python3.9/site-packages/pytorch_lightning/metrics/classification/helpers.py”, line 296, in _check_classification_inputs _basic_input_validation(preds, target, threshold, is_multiclass)
File “/home/anaconda3/envs/facebook/lib/python3.9/site-packages/pytorch_lightning/metrics/classification/helpers.py”, line 62, in _basic_input_validation
raise ValueError(“The target
has to be an integer tensor.”)
ValueError: The target
has to be an integer tensor._
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
Hello @mmuckley , I am a colleague of @silgonel .
Thank you very much for your help. After the answer you gave us yesterday, we realized that even if we used the file “requirements” to create a new conda environment, conda didn’t install the required versions of the packages. We created a new conda environment manually installing the required packages, and fortunately, the problem is gone and the training is working. Thank you very much for your help!
@silgonel What version of PyTorch and PyTorch Lightning are you running? It looks like this error was thrown by Lightning. I was on 1.7.1 and 1.0.8.
EDIT: much apologies - I see you matched what is in the requirements.txt. I’ll try to match with the small version of CheXpert. Yes, you’re right, we use the large one.