pyroengine.engine

The engine module contains everything to manage the whole Fire Detection process by capturing and saving the image and by predicting whether there is a fire on this image

class pyroengine.engine.Engine(model_path: str | None = None, conf_thresh: float = 0.35, model_conf_thresh: float = 0.05, max_bbox_size: float = 0.4, api_url: str | None = None, cam_creds: Dict[str, Dict[str, str]] | None = None, nb_consecutive_frames: int = 7, frame_size: Tuple[int, int] | None = None, cache_backup_period: int = 60, frame_saving_period: int | None = None, cache_size: int = 100, cache_folder: str = 'data/', backup_size: int = 30, jpeg_quality: int = 80, day_time_strategy: str | None = None, save_captured_frames: bool | None = False, save_detections_frames: bool | None = False, send_last_image_period: int = 3600, last_bbox_mask_fetch_period: int = 3600, **kwargs: Any)[source]

Manages predictions and API interactions for wildfire alerts.

Extends Predictor with pyroclient API integration: heartbeats, image uploads, alert staging and caching.

Parameters:
  • hub_repo – repository on HF Hub to load the ONNX model from

  • conf_thresh – confidence threshold to send an alert

  • api_url – url of the pyronear API

  • cam_creds – api credentials for each camera, the dictionary should be as the one in the example

  • alert_relaxation – number of consecutive positive detections required to send the first alert, and also the number of consecutive negative detections before stopping the alert

  • frame_size – Resize frame to frame_size before sending it to the api in order to save bandwidth (H, W)

  • cache_backup_period – number of minutes between each cache backup to disk

  • frame_saving_period – Send one frame over N to the api for our dataset

  • cache_size – maximum number of alerts to save in cache

  • day_time_strategy – strategy to define if it’s daytime

  • save_captured_frames – save all captured frames for debugging

  • save_detections_frames – Save all locally detection frames locally

  • kwargs – keyword args of Classifier

Examples

>>> from pyroengine import Engine
>>> cam_creds ={
>>> "cam_id_1": {'login':'log1', 'password':'pwd1'},
>>> "cam_id_2": {'login':'log2', 'password':'pwd2'},
>>> }
>>> pyroEngine = Engine(None, 0.25, 'https://api.pyronear.org', cam_creds, 48.88, 2.38)
predict(frame: Image, cam_id: str | None = None, occlusion_bboxes: Dict[Any, Any] | None = None, fake_pred: ndarray | None = None) float[source]

Computes the confidence that the image contains wildfire cues

Parameters:
  • frame – a PIL image

  • cam_id – the name of the camera that sent this image

  • occlusion_bboxes – ignored — Engine manages occlusion masks internally via URL fetch

  • fake_pred

    replace model prediction by another one for evaluation purposes, need to be given in onnx format: fake_pred = [[x1, x2]

    [y1, y2] [w1, w2] [h1, h2] [conf1, conf2]]

Returns:

the predicted confidence

heartbeat(cam_id: str) Response[source]

Updates last ping of device