question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ImportError: cannot import name 'Metric' from 'ignite.metrics'

See original GitHub issue

🐛 Bug description

Unable to use Metric for calculating roc_auc_compute

Code that caused error:

from typing import Any, Callable, Tuple

import torch

from ignite.metrics import EpochMetric


def roc_auc_compute_fn(y_preds: torch.Tensor, y_targets: torch.Tensor) -> float:
    try:
        from sklearn.metrics import roc_auc_score
    except ImportError:
        raise RuntimeError("This contrib module requires sklearn to be installed.")

    y_true = y_targets.numpy()
    y_pred = y_preds.numpy()
    return roc_auc_score(y_true, y_pred)

ImportError Traceback (most recent call last) <ipython-input-25-eaec9c574c2d> in <module> 3 import torch 4 ----> 5 from ignite.metrics import EpochMetric 6 7

C:\Users\dayan\AppData\Roaming\Python\Python37\site-packages\ignite\metrics_init_.py in <module> ----> 1 from ignite.metrics.accumulation import Average, GeometricAverage, VariableAccumulation 2 from ignite.metrics.accuracy import Accuracy 3 from ignite.metrics.confusion_matrix import ConfusionMatrix, DiceCoefficient, IoU, mIoU 4 from ignite.metrics.epoch_metric import EpochMetric 5 from ignite.metrics.fbeta import Fbeta

C:\Users\dayan\AppData\Roaming\Python\Python37\site-packages\ignite\metrics\accumulation.py in <module> 5 6 from ignite.exceptions import NotComputableError ----> 7 from ignite.metrics.metric import Metric, reinit__is_reduced, sync_all_reduce 8 9 all = [“VariableAccumulation”, “GeometricAverage”, “Average”]

C:\Users\dayan\AppData\Roaming\Python\Python37\site-packages\ignite\metrics\metric.py in <module> 8 9 import ignite.distributed as idist —> 10 from ignite.engine import CallableEventWithFilter, Engine, Events 11 12 if TYPE_CHECKING:

C:\Users\dayan\AppData\Roaming\Python\Python37\site-packages\ignite\engine_init_.py in <module> 8 from ignite.engine.engine import Engine 9 from ignite.engine.events import CallableEventWithFilter, EventEnum, Events, EventsList, RemovableEventHandle, State —> 10 from ignite.metrics import Metric 11 from ignite.utils import convert_tensor 12

ImportError: cannot import name ‘Metric’ from ‘ignite.metrics’ (C:\Users\dayan\AppData\Roaming\Python\Python37\site-packages\ignite\metrics_init_.py)

I am trying to compute AUC ROC score. But error is occurring …

Environment

  • PyTorch Version : 1.8.1
  • Ignite Version : 0.4.4
  • OS : Windows
  • How you installed Ignite : pip
  • Python version: 3.7.7
  • Any other relevant information:

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
bennydayanacommented, Apr 15, 2021

I tried it in another system and the stable version is working there… So no issues now… Thanks!

1reaction
bennydayanacommented, Apr 11, 2021

Yes… in nightly version it is solved… Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

ImportError: cannot import name '...' from partially initialized ...
For example: I cannot have a file named retrying.py that is using the retrying package. A similar error with the message "most likely...
Read more >
ignite.engine — PyTorch-Ignite v0.4.10 Documentation
High-level library to help with training and evaluating neural networks in PyTorch flexibly and transparently.
Read more >
Source code for monai.utils.module
Source code for monai.utils.module ... [docs]class OptionalImportError(ImportError): """ Could not import APIs from an optional dependency. """.
Read more >
No module named ignite.engine 解决方案 - CSDN博客
他说他装了ignite后代码报错说No module named ignite.engine其实是这样的, ... No module named ignite.metrics No module named ignite.base No ...
Read more >
How to Fix : “ImportError: Cannot import name X” in Python?
You can solve the “ ImportError : Cannot import name X” Error by resolving the circular dependencies. You can do that either by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found