Skip to content

Commit

Permalink
fix default bbox
Browse files Browse the repository at this point in the history
  • Loading branch information
MateoLostanlen committed Jan 30, 2025
1 parent 2b2d219 commit 14f774f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 1 addition & 2 deletions pyroengine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ def _update_states(self, frame: Image.Image, preds: np.ndarray, cam_key: str) ->
# Add default bbox
if output_predictions.shape[0] == 0:
output_predictions = np.zeros((1, 5))
output_predictions[:, 2:4] += 0.0001

self._states[cam_key]["last_predictions"].append(
(frame, preds, output_predictions.tolist(), datetime.now(timezone.utc).isoformat(), False)
Expand Down Expand Up @@ -345,8 +346,6 @@ def _process_alerts(self) -> None:
frame_info["frame"].save(stream, format="JPEG", quality=self.jpeg_quality)
bboxes = self._alerts[0]["bboxes"]
bboxes = [tuple(bboxe) for bboxe in bboxes]
if len(bboxes) == 0:
bboxes = [()]
_, cam_azimuth = self.cam_creds[cam_id]
ip = cam_id.split("_")[0]
response = self.api_client[ip].create_detection(stream.getvalue(), cam_azimuth, bboxes)
Expand Down
10 changes: 6 additions & 4 deletions tests/test_engine.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os
import time
from datetime import datetime, timezone
from pathlib import Path

Expand Down Expand Up @@ -52,7 +53,6 @@ def test_engine_offline(tmpdir_factory, mock_wildfire_image, mock_forest_image):
assert isinstance(engine._states["-1"]["last_predictions"][0][0], Image.Image)
assert engine._states["-1"]["last_predictions"][0][1].shape[0] == 0
assert engine._states["-1"]["last_predictions"][0][1].shape[1] == 5
assert engine._states["-1"]["last_predictions"][0][2] == [[0.0, 0.0, 0.0, 0.0, 0.0]]
assert engine._states["-1"]["last_predictions"][0][3] < datetime.now().isoformat()
assert engine._states["-1"]["last_predictions"][0][4] is False

Expand All @@ -63,7 +63,6 @@ def test_engine_offline(tmpdir_factory, mock_wildfire_image, mock_forest_image):
assert isinstance(engine._states["-1"]["last_predictions"][0][0], Image.Image)
assert engine._states["-1"]["last_predictions"][1][1].shape[0] > 0
assert engine._states["-1"]["last_predictions"][1][1].shape[1] == 5
assert engine._states["-1"]["last_predictions"][1][2] == [[0.0, 0.0, 0.0, 0.0, 0.0]]
assert engine._states["-1"]["last_predictions"][1][3] < datetime.now().isoformat()
assert engine._states["-1"]["last_predictions"][1][4] is False

Expand Down Expand Up @@ -91,6 +90,7 @@ def test_engine_online(tmpdir_factory, mock_wildfire_stream, mock_wildfire_image
if isinstance(api_url, str):
engine = Engine(
api_url=api_url,
conf_thresh=0.01,
cam_creds=cam_creds,
nb_consecutive_frames=4,
frame_saving_period=3,
Expand All @@ -101,9 +101,11 @@ def test_engine_online(tmpdir_factory, mock_wildfire_stream, mock_wildfire_image
start_ts = datetime.now(timezone.utc).isoformat()
response = engine.heartbeat("dummy_cam")
assert response.status_code // 100 == 2
ts = datetime.now(timezone.utc).isoformat()
json_respone = response.json()
assert start_ts < json_respone["last_ping"] < ts
time.sleep(0.1)
ts = datetime.now(timezone.utc).isoformat()

assert start_ts < json_respone["last_active_at"] < ts
# Send an alert
engine.predict(mock_wildfire_image, "dummy_cam")
assert len(engine._states["dummy_cam"]["last_predictions"]) == 1
Expand Down

0 comments on commit 14f774f

Please sign in to comment.