pytorch_tabular icon indicating copy to clipboard operation
pytorch_tabular copied to clipboard

Import error

Open sonnguyen129 opened this issue 3 years ago • 4 comments

When I import

from pytorch_tabular import TabularModel

catch error

14 import random
     15 
---> 16 from pytorch_tabular import TabularModel
     17 from pytorch_tabular.models import CategoryEmbeddingModelConfig, NodeConfig, NODEModel
     18 from pytorch_tabular.config import DataConfig, OptimizerConfig, TrainerConfig, ExperimentConfig, ModelConfig


[/usr/local/lib/python3.7/dist-packages/pytorch_lightning/metrics/utils.py](https://localhost:8080/#) in <module>()
     20 from torchmetrics.utilities.data import dim_zero_mean as _dim_zero_mean
     21 from torchmetrics.utilities.data import dim_zero_sum as _dim_zero_sum
---> 22 from torchmetrics.utilities.data import get_num_classes as _get_num_classes
     23 from torchmetrics.utilities.data import select_topk as _select_topk
     24 from torchmetrics.utilities.data import to_categorical as _to_categorical

ImportError: cannot import name 'get_num_classes' from 'torchmetrics.utilities.data' (/usr/local/lib/python3.7/dist-packages/torchmetrics/utilities/data.py)

How can I fix it?

sonnguyen129 avatar Apr 17 '22 20:04 sonnguyen129

This looks like a version issue... What is the version of torchmetrics you have installed?

manujosephv avatar Apr 26 '22 05:04 manujosephv

I am facing the same issue, using torchmetrics version 0.8.2

sakshi-rai115 avatar May 06 '22 08:05 sakshi-rai115

Looks like an issue with PyTorch Lightning and torchmetrics version incompatibility... Until the lightning team fixes this (or I change the versions of both), downgrading to torchmetrics>=0.7.0,<=0.7.3 seems to work for some others who have faced similar issue.

This commit in another library which uses lightning and torchmetrics

manujosephv avatar May 07 '22 05:05 manujosephv

Yes I downgraded torchmetrics to 0.3.2 and it worked, thanks

sakshi-rai115 avatar May 07 '22 12:05 sakshi-rai115

Check out #84 also, as torchmetrics==0.5 also worked for some.

manujosephv avatar Aug 17 '22 05:08 manujosephv

pip install torchmetrics==0.5. I have done this, it worked for me

shankar1345 avatar Aug 17 '22 15:08 shankar1345

Since everyone has found a solution, I will close this issue. I will reopen if I have more questions in the future

sonnguyen129 avatar Aug 17 '22 15:08 sonnguyen129