Skip to content

Commit

Permalink
send list (#176)
Browse files Browse the repository at this point in the history
* send list

* adapt test

* clip value

* fix type
  • Loading branch information
MateoLostanlen authored Oct 27, 2023
1 parent f01f2f3 commit 32f6ffb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pyroengine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def _update_states(self, frame: Image.Image, preds: np.ndarray, cam_key: str) ->
output_predictions = output_predictions[:5, :] # max 5 bbox

self._states[cam_key]["last_predictions"].append(
(frame, preds, json.dumps(output_predictions.tolist()), datetime.utcnow().isoformat(), False)
(frame, preds, output_predictions.tolist(), datetime.utcnow().isoformat(), False)
)

# update state
Expand Down Expand Up @@ -354,7 +354,7 @@ def _upload_frame(self, cam_id: str, media_data: bytes) -> Response:

return response

def _stage_alert(self, frame: Image.Image, cam_id: str, ts: int, localization: str) -> None:
def _stage_alert(self, frame: Image.Image, cam_id: str, ts: int, localization: list) -> None:
# Store information in the queue
self._alerts.append(
{
Expand All @@ -381,7 +381,7 @@ def _process_alerts(self) -> None:
# Media creation
if not isinstance(self._alerts[0]["media_id"], int):
self._alerts[0]["media_id"] = self.api_client[cam_id].create_media_from_device().json()["id"]

print(self._alerts[0])
# Alert creation
if not isinstance(self._alerts[0]["alert_id"], int):
self._alerts[0]["alert_id"] = (
Expand Down
2 changes: 1 addition & 1 deletion pyroengine/vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ def __call__(self, pil_img: Image.Image, occlusion_mask: Optional[np.ndarray] =

y = y[keep]

return y
return np.clip(y, 0, 1)
6 changes: 3 additions & 3 deletions tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ 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] == "[]"
assert engine._states["-1"]["last_predictions"][0][2] == []
assert engine._states["-1"]["last_predictions"][0][3] < datetime.utcnow().isoformat()
assert engine._states["-1"]["last_predictions"][0][4] is False

Expand All @@ -64,7 +64,7 @@ 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] == "[]"
assert engine._states["-1"]["last_predictions"][1][2] == []
assert engine._states["-1"]["last_predictions"][1][3] < datetime.utcnow().isoformat()
assert engine._states["-1"]["last_predictions"][1][4] is False

Expand All @@ -75,7 +75,7 @@ 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"][2][1].shape[0] > 0
assert engine._states["-1"]["last_predictions"][2][1].shape[1] == 5
assert len(engine._states["-1"]["last_predictions"][-1][2].split(" ")) == 5
assert len(engine._states["-1"]["last_predictions"][-1][2][0]) == 5
assert engine._states["-1"]["last_predictions"][2][3] < datetime.utcnow().isoformat()
assert engine._states["-1"]["last_predictions"][2][4] is False

Expand Down

0 comments on commit 32f6ffb

Please sign in to comment.