Skip to content

Register now for

# Reference for `ultralytics/__init__.py`

Note

This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/__init__.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!

## `` ultralytics.__getattr__

    __getattr__(name: str)

Lazy-import model classes on first access.

Source code in `ultralytics/__init__.py`

    30
    31
    32
    33
    34
    def __getattr__(name: str):
        """Lazy-import model classes on first access."""
        if name in MODELS:
            return getattr(importlib.import_module("ultralytics.models"), name)
        raise AttributeError(f"module {__name__} has no attribute {name}")

## `` ultralytics.__dir__

    __dir__()

Extend dir() to include lazily available model names for IDE autocompletion.

Source code in `ultralytics/__init__.py`

    37
    38
    39
    def __dir__():
        """Extend dir() to include lazily available model names for IDE autocompletion."""
        return sorted(set(globals()) | set(MODELS))

📅 Created 7 days ago ✏️ Updated 7 days ago