GeoCalib / siclib /models /__init__.py
veichta's picture
Upload folder using huggingface_hub
205a7af verified
raw
history blame contribute delete
804 Bytes
import importlib.util
from siclib.models.base_model import BaseModel
from siclib.utils.tools import get_class
def get_model(name):
import_paths = [
name,
f"{__name__}.{name}",
]
for path in import_paths:
try:
spec = importlib.util.find_spec(path)
except ModuleNotFoundError:
spec = None
if spec is not None:
try:
return get_class(path, BaseModel)
except AssertionError:
mod = __import__(path, fromlist=[""])
try:
return mod.__main_model__
except AttributeError as exc:
print(exc)
continue
raise RuntimeError(f'Model {name} not found in any of [{" ".join(import_paths)}]')