Fix detectron2 import (#41510)

* fix

* fix

* typo
This commit is contained in:
Cyril Vallez
2025-10-10 13:33:47 +02:00
committed by GitHub
parent f9f8bf5a10
commit 60f6ec438a

View File

@ -724,7 +724,15 @@ def is_datasets_available() -> bool:
@lru_cache
def is_detectron2_available() -> bool:
return _is_package_available("detectron2")
# We need this try/except block because otherwise after uninstalling the library, it stays available for some reason
# i.e. `import detectron2` and `import detectron2.modeling` still work, even though the library is uninstalled
# (the package exists but the objects are not reachable) - so here we explicitly try to import an object from it
try:
from detectron2.modeling import META_ARCH_REGISTRY # noqa
return True
except Exception:
return False
@lru_cache