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

cannot import name 'Metric' from partially initialized module 'ignite.metrics' #3319

Open
xiuguangLi opened this issue Jan 2, 2025 · 3 comments
Labels

Comments

@xiuguangLi
Copy link

from ignite.metrics import Metric
ImportError: cannot import name 'Metric' from partially initialized module 'ignite.metrics' (most likely due to a circular import)

/ignite/metrics/init.py)

I solved that by
def create_supervised_evaluator(
model: torch.nn.Module,
# metrics: Optional[Dict[str, Metric]] = None, #############this is the problem,i modify i by delete Optional[Dict[str, Metric]].
metrics = None,
device: Optional[Union[str, torch.device]] = None,
non_blocking: bool = False,
prepare_batch: Callable = _prepare_batch,
model_transform: Callable[[Any], Any] = lambda output: output,
output_transform: Callable[[Any, Any, Any], Any] = lambda x, y, y_pred: (y_pred, y),
amp_mode: Optional[str] = None,
model_fn: Callable[[torch.nn.Module, Any], Any] = lambda model, x: model(x),
) -> Engine:

Does have other ways to solve that?I dont want to modify source file.

@vfdev-5
Copy link
Collaborator

vfdev-5 commented Jan 2, 2025

@xiuguangLi can you provide a repro code?

Which python and ignite versions you are using?

We had a similar issue 3 years old: #1929 where it was a problem with user's python environment.

@xiuguangLi
Copy link
Author

my python version is 3.11.9, and ignite version is pytorch-ignite 0.5.1, which is the newest. it was my python version problem?

@xiuguangLi can you provide a repro code?

Which python and ignite versions you are using?

We had a similar issue 3 years old: #1929 where it was a problem with user's python environment.

@vfdev-5
Copy link
Collaborator

vfdev-5 commented Jan 2, 2025

it was my python version problem?

I do not know.

Can you try to create a clean python environment and install only torch and ignite and rerun your check ?

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

No branches or pull requests

2 participants