Reference for ultralytics/nn/backends/axelera.py
Improvements
This page is sourced from https://github.com/ultralytics/ultralytics/blob/main/ultralytics/nn/backends/axelera.py. Have an improvement or example to add? Open a Pull Request — thank you! 🙏
class ultralytics.nn.backends.axelera.AxeleraBackend
AxeleraBackend()
Bases: BaseBackend
Axelera AI inference backend for Axelera Metis AI accelerators.
Loads compiled Axelera models (.axm files) and runs inference using the Axelera AI runtime SDK. Requires the Axelera runtime environment to be activated before use.
Methods
| Name | Description |
|---|---|
forward | Run inference on the Axelera hardware accelerator. |
load_model | Load an Axelera model from a directory containing a .axm file. |
method ultralytics.nn.backends.axelera.AxeleraBackend.forward
def forward(self, im: torch.Tensor) -> list
Run inference on the Axelera hardware accelerator.
Args
| Name | Type | Description | Default |
|---|---|---|---|
im | torch.Tensor | Input image tensor in BCHW format, normalized to [0, 1]. | required |
Returns
| Type | Description |
|---|---|
list | Model predictions as a list of output arrays. |
Source code in ultralytics/nn/backends/axelera.py
View on GitHubdef forward(self, im: torch.Tensor) -> list:
"""Run inference on the Axelera hardware accelerator.
Args:
im (torch.Tensor): Input image tensor in BCHW format, normalized to [0, 1].
Returns:
(list): Model predictions as a list of output arrays.
"""
return self.model(im.cpu())
method ultralytics.nn.backends.axelera.AxeleraBackend.load_model
def load_model(self, weight: str | Path) -> None
Load an Axelera model from a directory containing a .axm file.
Args
| Name | Type | Description | Default |
|---|---|---|---|
weight | str | Path | Path to the Axelera model directory containing the .axm binary. | required |
Source code in ultralytics/nn/backends/axelera.py
View on GitHubdef load_model(self, weight: str | Path) -> None:
"""Load an Axelera model from a directory containing a .axm file.
Args:
weight (str | Path): Path to the Axelera model directory containing the .axm binary.
"""
if not os.environ.get("AXELERA_RUNTIME_DIR"):
LOGGER.warning(
"Axelera runtime environment is not activated.\n"
"Please run: source /opt/axelera/sdk/latest/axelera_activate.sh\n\n"
"If this fails, verify driver installation: "
"https://docs.ultralytics.com/integrations/axelera/#axelera-driver-installation"
)
try:
from axelera.runtime import op
except ImportError:
check_requirements(
"axelera_runtime2==0.1.2",
cmds="--extra-index-url https://software.axelera.ai/artifactory/axelera-runtime-pypi",
)
from axelera.runtime import op
w = Path(weight)
found = next(w.rglob("*.axm"), None)
if found is None:
raise FileNotFoundError(f"No .axm file found in: {w}")
self.model = op.load(str(found))
# Load metadata
metadata_file = found.parent / "metadata.yaml"
if metadata_file.exists():
from ultralytics.utils import YAML
self.apply_metadata(YAML.load(metadata_file))
📅 Created 0 days ago ✏️ Updated 0 days ago