Skip to main content
The classification pipeline processes each video frame through segmentation and visualization stages to detect and classify trash objects in real-time.

Pipeline Overview

The TrashClassificator class in processor.py:7 orchestrates the entire classification workflow through its frame_processing() method.
from trash_classificator.processor import TrashClassificator

classificator = TrashClassificator()
processed_image, status = classificator.frame_processing(image)

Processing Steps

1

Initialize Components

The classifier initializes two main components:
self.segmentation = SegmentationModel()
self.draw_detections = Drawing()
  • SegmentationModel: Handles trash detection and tracking
  • Drawing: Manages visualization of detections
2

Trash Segmentation

The input image is copied and passed to the segmentation model:
trash_image = image.copy()
trash_track, trash_classes, device = self.segmentation.inference(trash_image)
Returns:
  • trash_track: Detection results with boxes, masks, and tracking IDs
  • trash_classes: Dictionary mapping class IDs to names
  • device: PyTorch device used for inference
See Segmentation Model for details.
3

Detection Validation

The pipeline checks if any tracked objects were detected:
for trash in trash_track:
    if trash.boxes.id is None:
        return image, 'No trash detected'
If no boxes have tracking IDs, the original unmodified image is returned.
4

Draw Detections

For each detected object, visualizations are added:
image_draw = image.copy()
image_draw = self.draw_detections.draw(image_draw, trash, trash_classes, device)
return image_draw, 'Trash detected'
This includes masks, bounding boxes, class labels, and tracking paths.

Input/Output Specifications

def frame_processing(self, image: np.ndarray):
    """
    Args:
        image: NumPy array in BGR format (OpenCV convention)
               Shape: (height, width, 3)
               Dtype: uint8
    
    Returns:
        Tuple[np.ndarray, str]:
            - Processed image with visualizations
            - Status message: 'Trash detected' or 'No trash detected'
    """

Processing Flow Diagram

Error Handling

The pipeline implements graceful degradation:
No Detection HandlingWhen trash.boxes.id is None, the pipeline returns the original image unchanged with status 'No trash detected'. This prevents visualization errors when no objects are tracked.

Common Issues

IssueCauseSolution
Empty tracking IDsNo objects meet confidence thresholdLower conf parameter in segmentation
Processing lagHigh resolution inputReduce imgsz parameter or input size
Memory errorsLarge batch of framesProcess frames individually

Performance Considerations

The pipeline creates multiple image copies to preserve the original:
trash_image = image.copy()  # For segmentation
image_draw = image.copy()   # For drawing
This adds memory overhead but ensures the input remains unchanged.

Configuration Parameters

The segmentation inference in segmentation/main.py:24 accepts these parameters:
results = model.track(
    image, 
    conf=0.55,        # Confidence threshold (0-1)
    verbose=False,    # Suppress console output
    persist=True,     # Maintain tracking across frames
    imgsz=640,        # Input image size
    stream=True       # Enable streaming mode
)

Parameter Tuning

  • conf: Lower values detect more objects but increase false positives
  • imgsz: Larger sizes improve accuracy but reduce speed
  • persist: Must be True for consistent object tracking

Next Steps

Video Processing

Learn how to process video streams in real-time

Drawing Detections

Customize visualization of detected trash

Build docs developers (and LLMs) love