Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name 'get_num_classes' from 'torchmetrics.utilities.data' #18

Closed
LittlePotatoChip opened this issue Apr 21, 2022 · 10 comments

Comments

@LittlePotatoChip
Copy link

there is something wrong with my machine and I reinstall my ubuntu. I re-gitclone the code and just keep the data.but when I follow the readme to do installation,it print:

(monoscene) potato@ubuntu-X299-UD4-Pro:/workplace/MonoScene$ pip install -e ./
Obtaining file:///home/potato/workplace/MonoScene
Installing collected packages: monoscene
Running setup.py develop for monoscene
Successfully installed monoscene-0.0.0
(monoscene) potato@ubuntu-X299-UD4-Pro:
/workplace/MonoScene$ python monoscene/scripts/train_monoscene.py dataset=kitti enable_log=true kitti_root=$KITTI_ROOT kitti_preprocess_root=$KITTI_PREPROCESS kitti_logdir=$KITTI_LOG n_gpus=1 batch_size=1 sem_scal_loss=False
Traceback (most recent call last):
File "monoscene/scripts/train_monoscene.py", line 1, in
from monoscene.data.semantic_kitti.kitti_dm import KittiDataModule
File "/home/potato/workplace/MonoScene/monoscene/data/semantic_kitti/kitti_dm.py", line 3, in
import pytorch_lightning as pl
File "/home/potato/anaconda3/envs/monoscene/lib/python3.7/site-packages/pytorch_lightning/init.py", line 20, in
from pytorch_lightning import metrics # noqa: E402
File "/home/potato/anaconda3/envs/monoscene/lib/python3.7/site-packages/pytorch_lightning/metrics/init.py", line 15, in
from pytorch_lightning.metrics.classification import ( # noqa: F401
File "/home/potato/anaconda3/envs/monoscene/lib/python3.7/site-packages/pytorch_lightning/metrics/classification/init.py", line 14, in
from pytorch_lightning.metrics.classification.accuracy import Accuracy # noqa: F401
File "/home/potato/anaconda3/envs/monoscene/lib/python3.7/site-packages/pytorch_lightning/metrics/classification/accuracy.py", line 18, in
from pytorch_lightning.metrics.utils import deprecated_metrics, void
File "/home/potato/anaconda3/envs/monoscene/lib/python3.7/site-packages/pytorch_lightning/metrics/utils.py", line 22, in
from torchmetrics.utilities.data import get_num_classes as _get_num_classes
ImportError: cannot import name 'get_num_classes' from 'torchmetrics.utilities.data' (/home/potato/anaconda3/envs/monoscene/lib/python3.7/site-packages/torchmetrics/utilities/data.py)

@LittlePotatoChip
Copy link
Author

I think maybe that "Successfully installed monoscene-0.0.0" ,the building process make wrongs?

@anhquancao
Copy link
Collaborator

This is the error in pytorch-lightning version. Could you verify that your pytorch-lightning version is "pytorch-lightning==1.4.0rc0"?

@LittlePotatoChip
Copy link
Author

This is the error in pytorch-lightning version. Could you verify that your pytorch-lightning version is "pytorch-lightning==1.4.0rc0"?

yes,I use the "pip install -r requirements.txt"

@anhquancao
Copy link
Collaborator

Could you try this?
NVIDIA/DeepLearningExamples#1113 (comment)

@LittlePotatoChip
Copy link
Author

Could you try this? NVIDIA/DeepLearningExamples#1113 (comment)

I tried to reinstall the pytorch-lightning of another version,but it just printed:
RuntimeError: SpatialClassNLLCriterion_updateOutput does not have a deterministic implementation, but you set 'torch.use_deterministic_algorithms(True)'. You can turn off determinism just for this operation if that's acceptable for your application. You can also file an issue at https://github.com/pytorch/pytorch/issues to help us prioritize adding deterministic support for this operation.

@anhquancao
Copy link
Collaborator

You can set deterministic to False on lines 145 and 159 in the following file
https://github.com/cv-rits/MonoScene/blob/master/monoscene/scripts/train_monoscene.py#L159

@LittlePotatoChip
Copy link
Author

You can set deterministic to False on lines 145 and 159 in the following file https://github.com/cv-rits/MonoScene/blob/master/monoscene/scripts/train_monoscene.py#L159

it works,thanks

@Nikithareddy2201
Copy link

ImportError: cannot import name 'get_num_classes' from 'torchmetrics.utilities.data' (C:\ProgramData\anaconda3\Lib\site-packages\torchmetrics\utilities\data.py)

@Lr-2002
Copy link

Lr-2002 commented Mar 11, 2024

@Nikithareddy2201 yes! i'm facing the same problem ,Have You Ever solve it ?

@anhquancao
Copy link
Collaborator

I think the error is because of newer torchmetrics version, could you downgrade it to 0.6.0 with
pip install torchmetrics==0.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants