altametris.sara.core.exceptions¶
Custom exceptions for Altametris libraries.
Provides a hierarchy of exceptions for different error scenarios: - AltametrisException: Base exception - ModelError: Model-related errors (loading, architecture, weights) - TrainingError: Training-related errors (dataset, convergence, OOM) - InferenceError: Inference-related errors (input format, device) - ExportError: Export-related errors (format, validation) - ConfigurationError: Configuration-related errors (invalid parameters)
Exceptions¶
Base exception for all Altametris libraries. |
|
Exception raised for model-related errors. |
|
Exception raised for training-related errors. |
|
Exception raised for inference-related errors. |
|
Exception raised for export-related errors. |
|
Exception raised for configuration-related errors. |
Functions¶
|
Validate a parameter and raise ConfigurationError if invalid. |
Module Contents¶
- exception altametris.sara.core.exceptions.AltametrisException(message: str, details: dict[str, Any] | None = None)¶
Bases:
ExceptionBase exception for all Altametris libraries.
All custom exceptions inherit from this base class to allow catching all Altametris-specific errors with a single except clause.
- Parameters:
message – Error message describing what went wrong
details – Optional dictionary with additional error context
Example
>>> try: ... raise AltametrisException("Something went wrong", {"code": 500}) ... except AltametrisException as e: ... print(e) ... print(e.details)
- message¶
- details¶
- __str__() str¶
Return string representation of exception.
- __repr__() str¶
Return repr representation of exception.
- exception altametris.sara.core.exceptions.ModelError(message: str, details: dict[str, Any] | None = None)¶
Bases:
AltametrisExceptionException raised for model-related errors.
Scenarios: - Failed to load model weights - Invalid model architecture - Corrupted checkpoint file - Incompatible model version - Missing required model files
Example
>>> raise ModelError( ... "Failed to load weights", ... {"path": "model.pt", "reason": "File not found"} ... )
- exception altametris.sara.core.exceptions.TrainingError(message: str, details: dict[str, Any] | None = None)¶
Bases:
AltametrisExceptionException raised for training-related errors.
Scenarios: - Dataset not found or invalid format - Training divergence (NaN loss) - Out of memory during training - Invalid hyperparameters - Checkpoint save failure
Example
>>> raise TrainingError( ... "Training diverged", ... {"epoch": 10, "loss": float('nan'), "lr": 0.001} ... )
- exception altametris.sara.core.exceptions.InferenceError(message: str, details: dict[str, Any] | None = None)¶
Bases:
AltametrisExceptionException raised for inference-related errors.
Scenarios: - Invalid input format (wrong shape, type) - Device mismatch (model on CUDA, input on CPU) - Prediction failure - Post-processing error - Batch size too large for memory
Example
>>> raise InferenceError( ... "Invalid input shape", ... {"expected": (3, 640, 640), "got": (640, 640)} ... )
- exception altametris.sara.core.exceptions.ExportError(message: str, details: dict[str, Any] | None = None)¶
Bases:
AltametrisExceptionException raised for export-related errors.
Scenarios: - Unsupported export format - Export validation failed - Missing export dependencies (onnx, tensorrt) - Dynamic shapes not supported - Export optimization failed
Example
>>> raise ExportError( ... "ONNX export failed", ... {"format": "onnx", "reason": "Dynamic axes not supported"} ... )
- exception altametris.sara.core.exceptions.ConfigurationError(message: str, details: dict[str, Any] | None = None)¶
Bases:
AltametrisExceptionException raised for configuration-related errors.
Scenarios: - Invalid configuration parameter - Missing required configuration key - Configuration validation failed - Incompatible configuration values - Invalid YAML/JSON format
Example
>>> raise ConfigurationError( ... "Invalid batch_size", ... {"parameter": "batch_size", "value": -1, "expected": "> 0"} ... )
- altametris.sara.core.exceptions.validate_param(condition: bool, param_name: str, value: Any, expected: str) None¶
Validate a parameter and raise ConfigurationError if invalid.
- Parameters:
condition – Condition that must be True (if False, raises exception)
param_name – Name of the parameter being validated
value – Current value of the parameter
expected – Description of expected value
- Raises:
ConfigurationError – If condition is False
Example
>>> validate_param(batch_size > 0, "batch_size", batch_size, "> 0") >>> validate_param(device in ["cpu", "cuda"], "device", device, "cpu or cuda")