Overview
TheModelLoader class handles the initialization and management of YOLO segmentation models. It loads the pre-trained trash classification model and assigns it to the specified PyTorch device for optimal performance.
Class Definition
Constructor
__init__(device: torch.device)
Initializes the ModelLoader with a specific device and loads the YOLO model.
The PyTorch device to load the model onto. Can be CPU, CUDA (GPU), or MPS (Apple Silicon).
Behavior
- Loads the YOLO model from the path specified in
trash_model_path - Transfers the model to the specified device
- The model path resolves to:
trash_classificator/segmentation/models/trash_segmentation_model_v2.pt
The model is automatically loaded from the
trash_model_path constant defined in trash_classificator.segmentation.models.trash_model.Methods
get_model() -> YOLO
Returns the loaded YOLO model instance.
The Ultralytics YOLO model instance configured for trash segmentation. This model can classify three categories: cardboard and paper, metal, and plastic.
Model Path Handling
The model path is dynamically constructed based on the package installation location:Usage Example
Basic Usage
Device-Specific Loading
Parameters and Return Types
| Method | Parameters | Return Type | Description |
|---|---|---|---|
__init__ | device: torch.device | None | Initializes and loads the model |
get_model | None | YOLO | Returns the loaded model instance |
Model Specifications
- Model Type: YOLOv8 Segmentation
- Model File:
trash_segmentation_model_v2.pt - Classes Detected:
- 0: cardboard and paper
- 1: metal
- 2: plastic
Source Reference
Implementation:trash_classificator/segmentation/model_loader.py:6-11