matrice 1.0.99159__py3-none-any.whl → 1.0.99161__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- matrice/deploy/utils/post_processing/usecases/fire_detection.py +64 -5
- {matrice-1.0.99159.dist-info → matrice-1.0.99161.dist-info}/METADATA +1 -1
- {matrice-1.0.99159.dist-info → matrice-1.0.99161.dist-info}/RECORD +6 -6
- {matrice-1.0.99159.dist-info → matrice-1.0.99161.dist-info}/WHEEL +0 -0
- {matrice-1.0.99159.dist-info → matrice-1.0.99161.dist-info}/licenses/LICENSE.txt +0 -0
- {matrice-1.0.99159.dist-info → matrice-1.0.99161.dist-info}/top_level.txt +0 -0
@@ -4,10 +4,11 @@ Fire and Smoke Detection use case implementation.
|
|
4
4
|
This module provides a structured implementation of fire and smoke detection
|
5
5
|
with counting, insights generation, alerting, and tracking.
|
6
6
|
"""
|
7
|
-
from datetime import datetime, timezone
|
7
|
+
from datetime import datetime, timezone, timedelta
|
8
8
|
from typing import Any, Dict, List, Optional
|
9
9
|
from dataclasses import dataclass, field
|
10
10
|
import time
|
11
|
+
import re
|
11
12
|
|
12
13
|
from ..core.base import (
|
13
14
|
BaseProcessor,
|
@@ -41,6 +42,9 @@ class FireSmokeConfig(BaseConfig):
|
|
41
42
|
fire_smoke_categories: List[str] = field(
|
42
43
|
default_factory=lambda: ["Fire", "Smoke"]
|
43
44
|
)
|
45
|
+
target_categories: List[str] = field(
|
46
|
+
default_factory=lambda: ['Fire']
|
47
|
+
)
|
44
48
|
|
45
49
|
alert_config: Optional[AlertConfig] = None
|
46
50
|
|
@@ -71,6 +75,8 @@ class FireSmokeConfig(BaseConfig):
|
|
71
75
|
self.fire_smoke_categories = [cat.lower() for cat in self.fire_smoke_categories]
|
72
76
|
if self.index_to_category:
|
73
77
|
self.index_to_category = {k: v.lower() for k, v in self.index_to_category.items()}
|
78
|
+
if self.target_categories:
|
79
|
+
self.target_categories = [cat.lower() for cat in self.target_categories]
|
74
80
|
|
75
81
|
|
76
82
|
|
@@ -86,6 +92,7 @@ class FireSmokeUseCase(BaseProcessor):
|
|
86
92
|
|
87
93
|
self.smoothing_tracker = None # Required for bbox smoothing
|
88
94
|
self._fire_smoke_recent_history = []
|
95
|
+
self.target_categories=['Fire']
|
89
96
|
|
90
97
|
self._ascending_alert_list: List[int] = []
|
91
98
|
self.current_incident_end_timestamp: str = "N/A"
|
@@ -131,6 +138,10 @@ class FireSmokeUseCase(BaseProcessor):
|
|
131
138
|
processed_data = apply_category_mapping(processed_data, config.index_to_category)
|
132
139
|
self.logger.debug("Applied category mapping")
|
133
140
|
|
141
|
+
if self.target_categories:
|
142
|
+
processed_data = [d for d in processed_data if d.get('category') in self.target_categories]
|
143
|
+
self.logger.debug(f"Applied category filtering")
|
144
|
+
|
134
145
|
# Step 3.5: BBox smoothing for fire/smoke
|
135
146
|
if config.enable_smoothing:
|
136
147
|
if self.smoothing_tracker is None:
|
@@ -363,10 +374,10 @@ class FireSmokeUseCase(BaseProcessor):
|
|
363
374
|
intensity_pct = min(100.0, (total_area / threshold_area) * 100)
|
364
375
|
|
365
376
|
if config.alert_config and config.alert_config.count_thresholds:
|
366
|
-
if intensity_pct >=
|
377
|
+
if intensity_pct >= 40:
|
367
378
|
level = "critical"
|
368
379
|
self._ascending_alert_list.append(3)
|
369
|
-
elif intensity_pct >=
|
380
|
+
elif intensity_pct >= 30:
|
370
381
|
level = "significant"
|
371
382
|
self._ascending_alert_list.append(2)
|
372
383
|
elif intensity_pct >= 5:
|
@@ -376,11 +387,11 @@ class FireSmokeUseCase(BaseProcessor):
|
|
376
387
|
level = "low"
|
377
388
|
self._ascending_alert_list.append(0)
|
378
389
|
else:
|
379
|
-
if intensity_pct >
|
390
|
+
if intensity_pct > 40:
|
380
391
|
level = "critical"
|
381
392
|
intensity = 10.0
|
382
393
|
self._ascending_alert_list.append(3)
|
383
|
-
elif intensity_pct >
|
394
|
+
elif intensity_pct > 30:
|
384
395
|
level = "significant"
|
385
396
|
intensity = 9.0
|
386
397
|
self._ascending_alert_list.append(2)
|
@@ -414,6 +425,7 @@ class FireSmokeUseCase(BaseProcessor):
|
|
414
425
|
severity_level=level, human_text=human_text, camera_info=camera_info, alerts=alerts, alert_settings=alert_settings,
|
415
426
|
start_time=start_timestamp, end_time=self.current_incident_end_timestamp,
|
416
427
|
level_settings= {"low": 1, "medium": 5, "significant":40, "critical": 60})
|
428
|
+
event['duration'] = self.get_duration_seconds(start_timestamp, self.current_incident_end_timestamp)
|
417
429
|
incidents.append(event)
|
418
430
|
|
419
431
|
else:
|
@@ -847,5 +859,52 @@ class FireSmokeUseCase(BaseProcessor):
|
|
847
859
|
dt = datetime.fromtimestamp(timestamp, tz=timezone.utc)
|
848
860
|
return dt.strftime('%Y:%m:%d %H:%M:%S')
|
849
861
|
|
862
|
+
def get_duration_seconds(self, start_time, end_time):
|
863
|
+
def parse_relative_time(t):
|
864
|
+
"""Parse HH:MM:SS(.f) manually into timedelta"""
|
865
|
+
try:
|
866
|
+
parts = t.strip().split(":")
|
867
|
+
if len(parts) != 3:
|
868
|
+
return None
|
869
|
+
hours = int(parts[0])
|
870
|
+
minutes = int(parts[1])
|
871
|
+
seconds = float(parts[2]) # works for 7.4
|
872
|
+
return timedelta(hours=hours, minutes=minutes, seconds=seconds)
|
873
|
+
except:
|
874
|
+
return None
|
875
|
+
|
876
|
+
def parse_time(t):
|
877
|
+
# Check for HH:MM:SS(.ms) format
|
878
|
+
if re.match(r'^\d{1,2}:\d{2}:\d{1,2}(\.\d+)?$', t):
|
879
|
+
return parse_relative_time(t)
|
880
|
+
|
881
|
+
# Check for full UTC format like 2025-08-01-14:23:45.123456 UTC
|
882
|
+
if "UTC" in t:
|
883
|
+
try:
|
884
|
+
return datetime.strptime(t, "%Y-%m-%d-%H:%M:%S.%f UTC")
|
885
|
+
except ValueError:
|
886
|
+
return None
|
887
|
+
|
888
|
+
return None
|
889
|
+
|
890
|
+
start_dt = parse_time(start_time)
|
891
|
+
end_dt = parse_time(end_time)
|
892
|
+
|
893
|
+
# Return None if invalid
|
894
|
+
if start_dt is None or end_dt is None:
|
895
|
+
print("Invalid timestamp(s). Ignoring.")
|
896
|
+
return 'N/A'
|
897
|
+
|
898
|
+
# If timedelta (relative time), subtract directly
|
899
|
+
if isinstance(start_dt, timedelta) and isinstance(end_dt, timedelta):
|
900
|
+
delta = end_dt - start_dt
|
901
|
+
elif isinstance(start_dt, datetime) and isinstance(end_dt, datetime):
|
902
|
+
delta = end_dt - start_dt
|
903
|
+
else:
|
904
|
+
print("Mismatched timestamp formats.")
|
905
|
+
return None
|
906
|
+
|
907
|
+
return delta.total_seconds()
|
908
|
+
|
850
909
|
|
851
910
|
|
@@ -175,7 +175,7 @@ matrice/deploy/utils/post_processing/usecases/emergency_vehicle_detection.py,sha
|
|
175
175
|
matrice/deploy/utils/post_processing/usecases/face_emotion.py,sha256=eRfqBdryB0uNoOlz_y-JMuZL1BhPWrI-odqgx_9LT7s,39132
|
176
176
|
matrice/deploy/utils/post_processing/usecases/fashion_detection.py,sha256=f9gpzMDhIW-gyn46k9jgf8nY7YeoqAnTxGOzksabFbE,40457
|
177
177
|
matrice/deploy/utils/post_processing/usecases/field_mapping.py,sha256=JDwYX8pd2W-waDvBh98Y_o_uchJu7wEYbFxOliA4Iq4,39822
|
178
|
-
matrice/deploy/utils/post_processing/usecases/fire_detection.py,sha256=
|
178
|
+
matrice/deploy/utils/post_processing/usecases/fire_detection.py,sha256=HKo7gyjeLiLJmzoOErT6vu7kmyPSpC5yKkXlveegJaQ,41759
|
179
179
|
matrice/deploy/utils/post_processing/usecases/flare_analysis.py,sha256=-egmS3Hs_iGOLeCMfapbkfQ04EWtZx97QRuUcDa-jMU,45340
|
180
180
|
matrice/deploy/utils/post_processing/usecases/flower_segmentation.py,sha256=4I7qMx9Ztxg_hy9KTVX-3qBhAN-QwDt_Yigf9fFjLus,52017
|
181
181
|
matrice/deploy/utils/post_processing/usecases/gender_detection.py,sha256=DEnCTRew6B7DtPcBQVCTtpd_IQMvMusBcu6nadUg2oM,40107
|
@@ -227,8 +227,8 @@ matrice/deployment/camera_manager.py,sha256=ReBZqm1CNXRImKcbcZ4uWAT3TUWkof1D28oB
|
|
227
227
|
matrice/deployment/deployment.py,sha256=PLIUD-PxTaC2Zxb3Y12wUddsryV-OJetjCjLoSUh7S4,48103
|
228
228
|
matrice/deployment/inference_pipeline.py,sha256=bXLgd29ViA7o0c7YWLFJl1otBUQfTPb61jS6VawQB0Y,37918
|
229
229
|
matrice/deployment/streaming_gateway_manager.py,sha256=w5swGsuFVfZIdOm2ZuBHRHlRdYYJMLopLsf2gb91lQ8,20946
|
230
|
-
matrice-1.0.
|
231
|
-
matrice-1.0.
|
232
|
-
matrice-1.0.
|
233
|
-
matrice-1.0.
|
234
|
-
matrice-1.0.
|
230
|
+
matrice-1.0.99161.dist-info/licenses/LICENSE.txt,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
|
231
|
+
matrice-1.0.99161.dist-info/METADATA,sha256=Tm5lKNPPf3l7BiTw05EGTX1k3lahlR2S9jRgA3CTfjo,14624
|
232
|
+
matrice-1.0.99161.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
233
|
+
matrice-1.0.99161.dist-info/top_level.txt,sha256=P97js8ur6o5ClRqMH3Cjoab_NqbJ6sOQ3rJmVzKBvMc,8
|
234
|
+
matrice-1.0.99161.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|