From fc57d677b42083d868e643f4b52fe89a47e65c15 Mon Sep 17 00:00:00 2001 From: Oleksandr Bezdieniezhnykh Date: Mon, 30 Mar 2026 06:17:16 +0300 Subject: [PATCH] Refactor type casting in Cython files for improved clarity and consistency - Updated various Cython files to explicitly cast types, enhancing type safety and readability. - Adjusted the `engine_name` property in `InferenceEngine` and its subclasses to be set directly in the constructor. - Modified the `request` method in `_SessionWithBase` to accept `*args` for better flexibility. - Ensured proper type casting for return values in methods across multiple classes, including `Inference`, `CoreMLEngine`, and `TensorRTEngine`. These changes aim to streamline the codebase and improve maintainability by enforcing consistent type usage. --- Logs/log_inference_20260330.txt | 618 ++++++++++++++++++++++++++++++++ ai_availability_status.pyx | 2 +- annotation.pyx | 4 +- constants_inf.pxd | 2 +- constants_inf.pyx | 2 +- e2e/conftest.py | 4 +- engines/__init__.py | 2 +- engines/coreml_engine.pyx | 9 +- engines/inference_engine.pxd | 7 +- engines/inference_engine.pyx | 7 +- engines/onnx_engine.pyx | 8 +- engines/tensorrt_engine.pxd | 2 +- engines/tensorrt_engine.pyx | 26 +- inference.pyx | 41 +-- run-tests.sh | 3 + setup.py | 2 +- 16 files changed, 676 insertions(+), 63 deletions(-) diff --git a/Logs/log_inference_20260330.txt b/Logs/log_inference_20260330.txt index a2f03c4..c3ace18 100644 --- a/Logs/log_inference_20260330.txt +++ b/Logs/log_inference_20260330.txt @@ -3677,3 +3677,621 @@ [01:17:38 INFO] Video batch 50: 1 detections from postprocess [01:17:38 INFO] Video frame video_test01_000079: 1 dets, valid=False [01:17:38 INFO] Video done: 200 frames read, 50 batches processed +[06:14:20 INFO] init AI... +[06:14:20 INFO] Downloading +[06:14:23 INFO] CoreML model: 1280x1280 +[06:14:23 INFO] Enabled +[06:14:23 INFO] init AI... +[06:14:24 INFO] init AI... +[06:14:24 INFO] init AI... +[06:14:24 INFO] run inference on /Users/obezdienie001/dev/azaion/suite/detections/e2e/fixtures/image_small.jpg... +[06:14:24 INFO] ground sampling distance: 0.3059895833333333 +[06:14:24 INFO] Initial ann: image_small_000000: class: 0 77.0% (0.47, 0.21) (0.14, 0.19) +[06:14:24 INFO] Removed (53.80277931690216 42.89022199809551) > 8. class: ArmorVehicle +[06:14:25 INFO] init AI... +[06:14:25 INFO] run inference on /Users/obezdienie001/dev/azaion/suite/detections/e2e/fixtures/video_test01.mp4... +[06:14:25 INFO] Video: 200 frames, 25.0 fps, 2560x1440 +[06:14:25 INFO] Video batch 1: frame 4/200 (2%) +[06:14:25 INFO] Video batch 2: frame 8/200 (4%) +[06:14:25 INFO] Video batch 3: frame 12/200 (6%) +[06:14:25 INFO] Video batch 4: frame 16/200 (8%) +[06:14:25 INFO] Video batch 4: 1 detections from postprocess +[06:14:25 INFO] Video frame video_test01_000006: 1 dets, valid=True +[06:14:25 INFO] Video batch 5: frame 20/200 (10%) +[06:14:25 INFO] Video batch 5: 1 detections from postprocess +[06:14:25 INFO] Video frame video_test01_000007: 1 dets, valid=True +[06:14:25 INFO] Video batch 6: frame 24/200 (12%) +[06:14:26 INFO] Video batch 6: 1 detections from postprocess +[06:14:26 INFO] Video frame video_test01_000009: 1 dets, valid=True +[06:14:26 INFO] Video batch 7: frame 28/200 (14%) +[06:14:26 INFO] Video batch 7: 1 detections from postprocess +[06:14:26 INFO] Video frame video_test01_000010: 1 dets, valid=True +[06:14:26 INFO] Video batch 8: frame 32/200 (16%) +[06:14:26 INFO] Video batch 8: 1 detections from postprocess +[06:14:26 INFO] Video frame video_test01_000012: 1 dets, valid=True +[06:14:26 INFO] Video batch 9: frame 36/200 (18%) +[06:14:26 INFO] Video batch 9: 1 detections from postprocess +[06:14:26 INFO] Video frame video_test01_000014: 1 dets, valid=True +[06:14:26 INFO] Video batch 10: frame 40/200 (20%) +[06:14:26 INFO] Video batch 10: 1 detections from postprocess +[06:14:26 INFO] Video frame video_test01_000015: 1 dets, valid=True +[06:14:26 INFO] Video batch 11: frame 44/200 (22%) +[06:14:26 INFO] Video batch 11: 1 detections from postprocess +[06:14:26 INFO] Video frame video_test01_000017: 1 dets, valid=True +[06:14:26 INFO] Video batch 12: frame 48/200 (24%) +[06:14:26 INFO] Video batch 12: 1 detections from postprocess +[06:14:26 INFO] Video frame video_test01_000018: 1 dets, valid=True +[06:14:26 INFO] Video batch 13: frame 52/200 (26%) +[06:14:27 INFO] Video batch 13: 1 detections from postprocess +[06:14:27 INFO] Video frame video_test01_000020: 1 dets, valid=True +[06:14:27 INFO] Video batch 14: frame 56/200 (28%) +[06:14:27 INFO] Video batch 14: 1 detections from postprocess +[06:14:27 INFO] Video frame video_test01_000022: 1 dets, valid=True +[06:14:27 INFO] Video batch 15: frame 60/200 (30%) +[06:14:27 INFO] Video batch 15: 1 detections from postprocess +[06:14:27 INFO] Video frame video_test01_000023: 1 dets, valid=True +[06:14:27 INFO] Video batch 16: frame 64/200 (32%) +[06:14:27 INFO] Video batch 16: 1 detections from postprocess +[06:14:27 INFO] Video frame video_test01_000025: 1 dets, valid=True +[06:14:27 INFO] Video batch 17: frame 68/200 (34%) +[06:14:27 INFO] Video batch 17: 1 detections from postprocess +[06:14:27 INFO] Video frame video_test01_000026: 1 dets, valid=True +[06:14:27 INFO] Video batch 18: frame 72/200 (36%) +[06:14:27 INFO] Video batch 18: 1 detections from postprocess +[06:14:27 INFO] Video frame video_test01_000028: 1 dets, valid=True +[06:14:27 INFO] Video batch 19: frame 76/200 (38%) +[06:14:28 INFO] Video batch 19: 1 detections from postprocess +[06:14:28 INFO] Video frame video_test01_000030: 1 dets, valid=True +[06:14:28 INFO] Video batch 20: frame 80/200 (40%) +[06:14:28 INFO] Video batch 20: 1 detections from postprocess +[06:14:28 INFO] Video frame video_test01_000031: 1 dets, valid=True +[06:14:28 INFO] Video batch 21: frame 84/200 (42%) +[06:14:28 INFO] Video batch 21: 1 detections from postprocess +[06:14:28 INFO] Video frame video_test01_000033: 1 dets, valid=True +[06:14:28 INFO] Video batch 22: frame 88/200 (44%) +[06:14:28 INFO] Video batch 22: 1 detections from postprocess +[06:14:28 INFO] Video frame video_test01_000034: 1 dets, valid=True +[06:14:28 INFO] Video batch 23: frame 92/200 (46%) +[06:14:28 INFO] Video batch 24: frame 96/200 (48%) +[06:14:28 INFO] Video batch 25: frame 100/200 (50%) +[06:14:28 INFO] Video batch 26: frame 104/200 (52%) +[06:14:29 INFO] Video batch 26: 1 detections from postprocess +[06:14:29 INFO] Video frame video_test01_000041: 1 dets, valid=True +[06:14:29 INFO] Video batch 27: frame 108/200 (54%) +[06:14:29 INFO] Video batch 27: 1 detections from postprocess +[06:14:29 INFO] Video frame video_test01_000042: 1 dets, valid=True +[06:14:29 INFO] Video batch 28: frame 112/200 (56%) +[06:14:29 INFO] Video batch 28: 1 detections from postprocess +[06:14:29 INFO] Video frame video_test01_000044: 1 dets, valid=True +[06:14:29 INFO] Video batch 29: frame 116/200 (58%) +[06:14:29 INFO] Video batch 29: 1 detections from postprocess +[06:14:29 INFO] Video frame video_test01_000046: 1 dets, valid=True +[06:14:29 INFO] Video batch 30: frame 120/200 (60%) +[06:14:29 INFO] Video batch 30: 1 detections from postprocess +[06:14:29 INFO] Video frame video_test01_000047: 1 dets, valid=True +[06:14:29 INFO] Video batch 31: frame 124/200 (62%) +[06:14:29 INFO] Video batch 31: 1 detections from postprocess +[06:14:29 INFO] Video frame video_test01_000049: 1 dets, valid=True +[06:14:29 INFO] Video batch 32: frame 128/200 (64%) +[06:14:29 INFO] Video batch 32: 1 detections from postprocess +[06:14:29 INFO] Video frame video_test01_000050: 1 dets, valid=True +[06:14:29 INFO] Video batch 33: frame 132/200 (66%) +[06:14:30 INFO] Video batch 33: 1 detections from postprocess +[06:14:30 INFO] Video frame video_test01_000052: 1 dets, valid=True +[06:14:30 INFO] Video batch 34: frame 136/200 (68%) +[06:14:30 INFO] Video batch 34: 1 detections from postprocess +[06:14:30 INFO] Video frame video_test01_000054: 1 dets, valid=True +[06:14:30 INFO] Video batch 35: frame 140/200 (70%) +[06:14:30 INFO] Video batch 35: 1 detections from postprocess +[06:14:30 INFO] Video frame video_test01_000055: 1 dets, valid=True +[06:14:30 INFO] Video batch 36: frame 144/200 (72%) +[06:14:30 INFO] Video batch 36: 1 detections from postprocess +[06:14:30 INFO] Video frame video_test01_000057: 1 dets, valid=True +[06:14:30 INFO] Video batch 37: frame 148/200 (74%) +[06:14:30 INFO] Video batch 38: frame 152/200 (76%) +[06:14:30 INFO] Video batch 39: frame 156/200 (78%) +[06:14:30 INFO] Video batch 40: frame 160/200 (80%) +[06:14:30 INFO] Video batch 41: frame 164/200 (82%) +[06:14:31 INFO] Video batch 42: frame 168/200 (84%) +[06:14:31 INFO] Video batch 42: 1 detections from postprocess +[06:14:31 INFO] Video frame video_test01_000066: 1 dets, valid=True +[06:14:31 INFO] Video batch 43: frame 172/200 (86%) +[06:14:31 INFO] Video batch 43: 1 detections from postprocess +[06:14:31 INFO] Video frame video_test01_000068: 1 dets, valid=True +[06:14:31 INFO] Video batch 44: frame 176/200 (88%) +[06:14:31 INFO] Video batch 45: frame 180/200 (90%) +[06:14:31 INFO] Video batch 46: frame 184/200 (92%) +[06:14:31 INFO] Video batch 46: 1 detections from postprocess +[06:14:31 INFO] Video frame video_test01_000073: 1 dets, valid=True +[06:14:31 INFO] Video batch 47: frame 188/200 (94%) +[06:14:31 INFO] Video batch 47: 1 detections from postprocess +[06:14:31 INFO] Video frame video_test01_000074: 1 dets, valid=True +[06:14:31 INFO] Video batch 48: frame 192/200 (96%) +[06:14:32 INFO] Video batch 48: 1 detections from postprocess +[06:14:32 INFO] Video frame video_test01_000076: 1 dets, valid=True +[06:14:32 INFO] Video batch 49: frame 196/200 (98%) +[06:14:32 INFO] Video batch 49: 1 detections from postprocess +[06:14:32 INFO] Video frame video_test01_000078: 1 dets, valid=True +[06:14:32 INFO] Video batch 50: frame 200/200 (100%) +[06:14:32 INFO] Video batch 50: 1 detections from postprocess +[06:14:32 INFO] Video frame video_test01_000079: 1 dets, valid=True +[06:14:32 INFO] Video done: 200 frames read, 50 batches processed +[06:14:32 INFO] init AI... +[06:14:32 INFO] run inference on /Users/obezdienie001/dev/azaion/suite/detections/e2e/fixtures/image_small.jpg... +[06:14:32 INFO] init AI... +[06:14:32 INFO] ground sampling distance: 0.3059895833333333 +[06:14:32 INFO] Initial ann: image_small_000000: class: 0 77.0% (0.47, 0.21) (0.14, 0.19) +[06:14:32 INFO] Removed (53.80277931690216 42.89022199809551) > 8. class: ArmorVehicle +[06:14:32 INFO] init AI... +[06:14:32 INFO] init AI... +[06:14:32 INFO] init AI... +[06:14:32 INFO] init AI... +[06:14:33 INFO] init AI... +[06:14:33 INFO] init AI... +[06:14:33 INFO] init AI... +[06:14:33 INFO] init AI... +[06:14:33 INFO] init AI... +[06:14:33 INFO] init AI... +[06:14:33 INFO] init AI... +[06:14:34 INFO] init AI... +[06:14:34 INFO] init AI... +[06:14:34 INFO] init AI... +[06:14:34 INFO] init AI... +[06:14:34 INFO] init AI... +[06:14:34 INFO] init AI... +[06:14:35 INFO] init AI... +[06:14:35 INFO] init AI... +[06:14:35 INFO] init AI... +[06:14:35 INFO] init AI... +[06:14:35 INFO] init AI... +[06:14:35 INFO] init AI... +[06:14:36 INFO] init AI... +[06:14:36 INFO] init AI... +[06:14:36 INFO] init AI... +[06:14:36 INFO] init AI... +[06:14:37 INFO] init AI... +[06:14:37 INFO] init AI... +[06:14:37 INFO] init AI... +[06:14:37 INFO] init AI... +[06:14:37 INFO] init AI... +[06:14:37 INFO] init AI... +[06:14:38 INFO] init AI... +[06:14:38 INFO] init AI... +[06:14:38 INFO] init AI... +[06:14:39 INFO] init AI... +[06:14:39 INFO] run inference on /Users/obezdienie001/dev/azaion/suite/detections/e2e/fixtures/video_test01.mp4... +[06:14:39 INFO] Video: 200 frames, 25.0 fps, 2560x1440 +[06:14:39 INFO] Video batch 1: frame 4/200 (2%) +[06:14:39 INFO] Video batch 2: frame 8/200 (4%) +[06:14:39 INFO] Video batch 3: frame 12/200 (6%) +[06:14:39 INFO] Video batch 4: frame 16/200 (8%) +[06:14:39 INFO] Video batch 4: 1 detections from postprocess +[06:14:39 INFO] Video frame video_test01_000006: 1 dets, valid=True +[06:14:39 INFO] Video batch 5: frame 20/200 (10%) +[06:14:40 INFO] Video batch 5: 1 detections from postprocess +[06:14:40 INFO] Video frame video_test01_000007: 1 dets, valid=False +[06:14:40 INFO] Video batch 6: frame 24/200 (12%) +[06:14:40 INFO] Video batch 6: 1 detections from postprocess +[06:14:40 INFO] Video frame video_test01_000009: 1 dets, valid=False +[06:14:40 INFO] Video batch 7: frame 28/200 (14%) +[06:14:40 INFO] Video batch 7: 1 detections from postprocess +[06:14:40 INFO] Video frame video_test01_000010: 1 dets, valid=False +[06:14:40 INFO] Video batch 8: frame 32/200 (16%) +[06:14:40 INFO] Video batch 8: 1 detections from postprocess +[06:14:40 INFO] Video frame video_test01_000012: 1 dets, valid=False +[06:14:40 INFO] Video batch 9: frame 36/200 (18%) +[06:14:40 INFO] Video batch 9: 1 detections from postprocess +[06:14:40 INFO] Video frame video_test01_000014: 1 dets, valid=False +[06:14:40 INFO] Video batch 10: frame 40/200 (20%) +[06:14:40 INFO] Video batch 10: 1 detections from postprocess +[06:14:40 INFO] Video frame video_test01_000015: 1 dets, valid=False +[06:14:40 INFO] Video batch 11: frame 44/200 (22%) +[06:14:40 INFO] Video batch 11: 1 detections from postprocess +[06:14:40 INFO] Video frame video_test01_000017: 1 dets, valid=False +[06:14:40 INFO] Video batch 12: frame 48/200 (24%) +[06:14:41 INFO] Video batch 12: 1 detections from postprocess +[06:14:41 INFO] Video frame video_test01_000018: 1 dets, valid=False +[06:14:41 INFO] Video batch 13: frame 52/200 (26%) +[06:14:41 INFO] Video batch 13: 1 detections from postprocess +[06:14:41 INFO] Video frame video_test01_000020: 1 dets, valid=False +[06:14:41 INFO] Video batch 14: frame 56/200 (28%) +[06:14:41 INFO] Video batch 14: 1 detections from postprocess +[06:14:41 INFO] Video frame video_test01_000022: 1 dets, valid=False +[06:14:41 INFO] Video batch 15: frame 60/200 (30%) +[06:14:41 INFO] Video batch 15: 1 detections from postprocess +[06:14:41 INFO] Video frame video_test01_000023: 1 dets, valid=False +[06:14:41 INFO] Video batch 16: frame 64/200 (32%) +[06:14:41 INFO] Video batch 16: 1 detections from postprocess +[06:14:41 INFO] Video frame video_test01_000025: 1 dets, valid=False +[06:14:41 INFO] Video batch 17: frame 68/200 (34%) +[06:14:41 INFO] Video batch 17: 1 detections from postprocess +[06:14:41 INFO] Video frame video_test01_000026: 1 dets, valid=True +[06:14:41 INFO] Video batch 18: frame 72/200 (36%) +[06:14:41 INFO] Video batch 18: 1 detections from postprocess +[06:14:41 INFO] Video frame video_test01_000028: 1 dets, valid=False +[06:14:41 INFO] Video batch 19: frame 76/200 (38%) +[06:14:42 INFO] Video batch 19: 1 detections from postprocess +[06:14:42 INFO] Video frame video_test01_000030: 1 dets, valid=False +[06:14:42 INFO] Video batch 20: frame 80/200 (40%) +[06:14:42 INFO] Video batch 20: 1 detections from postprocess +[06:14:42 INFO] Video frame video_test01_000031: 1 dets, valid=False +[06:14:42 INFO] Video batch 21: frame 84/200 (42%) +[06:14:42 INFO] Video batch 21: 1 detections from postprocess +[06:14:42 INFO] Video frame video_test01_000033: 1 dets, valid=False +[06:14:42 INFO] Video batch 22: frame 88/200 (44%) +[06:14:42 INFO] Video batch 22: 1 detections from postprocess +[06:14:42 INFO] Video frame video_test01_000034: 1 dets, valid=False +[06:14:42 INFO] Video batch 23: frame 92/200 (46%) +[06:14:42 INFO] Video batch 24: frame 96/200 (48%) +[06:14:42 INFO] Video batch 25: frame 100/200 (50%) +[06:14:42 INFO] Video batch 26: frame 104/200 (52%) +[06:14:43 INFO] Video batch 26: 1 detections from postprocess +[06:14:43 INFO] Video frame video_test01_000041: 1 dets, valid=False +[06:14:43 INFO] Video batch 27: frame 108/200 (54%) +[06:14:43 INFO] Video batch 27: 1 detections from postprocess +[06:14:43 INFO] Video frame video_test01_000042: 1 dets, valid=False +[06:14:43 INFO] Video batch 28: frame 112/200 (56%) +[06:14:43 INFO] Video batch 28: 1 detections from postprocess +[06:14:43 INFO] Video frame video_test01_000044: 1 dets, valid=False +[06:14:43 INFO] Video batch 29: frame 116/200 (58%) +[06:14:43 INFO] Video batch 29: 1 detections from postprocess +[06:14:43 INFO] Video frame video_test01_000046: 1 dets, valid=False +[06:14:43 INFO] Video batch 30: frame 120/200 (60%) +[06:14:43 INFO] Video batch 30: 1 detections from postprocess +[06:14:43 INFO] Video frame video_test01_000047: 1 dets, valid=True +[06:14:43 INFO] Video batch 31: frame 124/200 (62%) +[06:14:43 INFO] Video batch 31: 1 detections from postprocess +[06:14:43 INFO] Video frame video_test01_000049: 1 dets, valid=False +[06:14:43 INFO] Video batch 32: frame 128/200 (64%) +[06:14:43 INFO] Video batch 32: 1 detections from postprocess +[06:14:43 INFO] Video frame video_test01_000050: 1 dets, valid=False +[06:14:44 INFO] Video batch 33: frame 132/200 (66%) +[06:14:44 INFO] Video batch 33: 1 detections from postprocess +[06:14:44 INFO] Video frame video_test01_000052: 1 dets, valid=False +[06:14:44 INFO] Video batch 34: frame 136/200 (68%) +[06:14:44 INFO] Video batch 34: 1 detections from postprocess +[06:14:44 INFO] Video frame video_test01_000054: 1 dets, valid=False +[06:14:44 INFO] Video batch 35: frame 140/200 (70%) +[06:14:44 INFO] Video batch 35: 1 detections from postprocess +[06:14:44 INFO] Video frame video_test01_000055: 1 dets, valid=False +[06:14:44 INFO] Video batch 36: frame 144/200 (72%) +[06:14:44 INFO] Video batch 36: 1 detections from postprocess +[06:14:44 INFO] Video frame video_test01_000057: 1 dets, valid=False +[06:14:44 INFO] Video batch 37: frame 148/200 (74%) +[06:14:44 INFO] Video batch 38: frame 152/200 (76%) +[06:14:44 INFO] Video batch 39: frame 156/200 (78%) +[06:14:45 INFO] Video batch 40: frame 160/200 (80%) +[06:14:45 INFO] Video batch 41: frame 164/200 (82%) +[06:14:45 INFO] Video batch 42: frame 168/200 (84%) +[06:14:45 INFO] Video batch 42: 1 detections from postprocess +[06:14:45 INFO] Video frame video_test01_000066: 1 dets, valid=False +[06:14:45 INFO] Video batch 43: frame 172/200 (86%) +[06:14:45 INFO] Video batch 43: 1 detections from postprocess +[06:14:45 INFO] Video frame video_test01_000068: 1 dets, valid=True +[06:14:45 INFO] Video batch 44: frame 176/200 (88%) +[06:14:45 INFO] Video batch 45: frame 180/200 (90%) +[06:14:45 INFO] Video batch 46: frame 184/200 (92%) +[06:14:46 INFO] Video batch 46: 1 detections from postprocess +[06:14:46 INFO] Video frame video_test01_000073: 1 dets, valid=True +[06:14:46 INFO] Video batch 47: frame 188/200 (94%) +[06:14:46 INFO] Video batch 47: 1 detections from postprocess +[06:14:46 INFO] Video frame video_test01_000074: 1 dets, valid=False +[06:14:46 INFO] Video batch 48: frame 192/200 (96%) +[06:14:46 INFO] Video batch 48: 1 detections from postprocess +[06:14:46 INFO] Video frame video_test01_000076: 1 dets, valid=False +[06:14:46 INFO] Video batch 49: frame 196/200 (98%) +[06:14:46 INFO] Video batch 49: 1 detections from postprocess +[06:14:46 INFO] Video frame video_test01_000078: 1 dets, valid=False +[06:14:46 INFO] Video batch 50: frame 200/200 (100%) +[06:14:46 INFO] Video batch 50: 1 detections from postprocess +[06:14:46 INFO] Video frame video_test01_000079: 1 dets, valid=False +[06:14:46 INFO] Video done: 200 frames read, 50 batches processed +[06:15:26 INFO] init AI... +[06:15:26 INFO] Downloading +[06:15:29 INFO] CoreML model: 1280x1280 +[06:15:29 INFO] Enabled +[06:15:29 INFO] init AI... +[06:15:29 INFO] init AI... +[06:15:29 INFO] init AI... +[06:15:29 INFO] run inference on /Users/obezdienie001/dev/azaion/suite/detections/e2e/fixtures/image_small.jpg... +[06:15:29 INFO] ground sampling distance: 0.3059895833333333 +[06:15:29 INFO] Initial ann: image_small_000000: class: 0 77.0% (0.47, 0.21) (0.14, 0.19) +[06:15:29 INFO] Removed (53.80277931690216 42.89022199809551) > 8. class: ArmorVehicle +[06:15:30 INFO] init AI... +[06:15:30 INFO] run inference on /Users/obezdienie001/dev/azaion/suite/detections/e2e/fixtures/video_test01.mp4... +[06:15:30 INFO] Video: 200 frames, 25.0 fps, 2560x1440 +[06:15:30 INFO] Video batch 1: frame 4/200 (2%) +[06:15:30 INFO] Video batch 2: frame 8/200 (4%) +[06:15:30 INFO] Video batch 3: frame 12/200 (6%) +[06:15:30 INFO] Video batch 4: frame 16/200 (8%) +[06:15:30 INFO] Video batch 4: 1 detections from postprocess +[06:15:30 INFO] Video frame video_test01_000006: 1 dets, valid=True +[06:15:30 INFO] Video batch 5: frame 20/200 (10%) +[06:15:31 INFO] Video batch 5: 1 detections from postprocess +[06:15:31 INFO] Video frame video_test01_000007: 1 dets, valid=True +[06:15:31 INFO] Video batch 6: frame 24/200 (12%) +[06:15:31 INFO] Video batch 6: 1 detections from postprocess +[06:15:31 INFO] Video frame video_test01_000009: 1 dets, valid=True +[06:15:31 INFO] Video batch 7: frame 28/200 (14%) +[06:15:31 INFO] Video batch 7: 1 detections from postprocess +[06:15:31 INFO] Video frame video_test01_000010: 1 dets, valid=True +[06:15:31 INFO] Video batch 8: frame 32/200 (16%) +[06:15:31 INFO] Video batch 8: 1 detections from postprocess +[06:15:31 INFO] Video frame video_test01_000012: 1 dets, valid=True +[06:15:31 INFO] Video batch 9: frame 36/200 (18%) +[06:15:31 INFO] Video batch 9: 1 detections from postprocess +[06:15:31 INFO] Video frame video_test01_000014: 1 dets, valid=True +[06:15:31 INFO] Video batch 10: frame 40/200 (20%) +[06:15:31 INFO] Video batch 10: 1 detections from postprocess +[06:15:31 INFO] Video frame video_test01_000015: 1 dets, valid=True +[06:15:31 INFO] Video batch 11: frame 44/200 (22%) +[06:15:32 INFO] Video batch 11: 1 detections from postprocess +[06:15:32 INFO] Video frame video_test01_000017: 1 dets, valid=True +[06:15:32 INFO] Video batch 12: frame 48/200 (24%) +[06:15:32 INFO] Video batch 12: 1 detections from postprocess +[06:15:32 INFO] Video frame video_test01_000018: 1 dets, valid=True +[06:15:32 INFO] Video batch 13: frame 52/200 (26%) +[06:15:32 INFO] Video batch 13: 1 detections from postprocess +[06:15:32 INFO] Video frame video_test01_000020: 1 dets, valid=True +[06:15:32 INFO] Video batch 14: frame 56/200 (28%) +[06:15:32 INFO] Video batch 14: 1 detections from postprocess +[06:15:32 INFO] Video frame video_test01_000022: 1 dets, valid=True +[06:15:32 INFO] Video batch 15: frame 60/200 (30%) +[06:15:32 INFO] Video batch 15: 1 detections from postprocess +[06:15:32 INFO] Video frame video_test01_000023: 1 dets, valid=True +[06:15:32 INFO] Video batch 16: frame 64/200 (32%) +[06:15:32 INFO] Video batch 16: 1 detections from postprocess +[06:15:32 INFO] Video frame video_test01_000025: 1 dets, valid=True +[06:15:32 INFO] Video batch 17: frame 68/200 (34%) +[06:15:33 INFO] Video batch 17: 1 detections from postprocess +[06:15:33 INFO] Video frame video_test01_000026: 1 dets, valid=True +[06:15:33 INFO] Video batch 18: frame 72/200 (36%) +[06:15:33 INFO] Video batch 18: 1 detections from postprocess +[06:15:33 INFO] Video frame video_test01_000028: 1 dets, valid=True +[06:15:33 INFO] Video batch 19: frame 76/200 (38%) +[06:15:33 INFO] Video batch 19: 1 detections from postprocess +[06:15:33 INFO] Video frame video_test01_000030: 1 dets, valid=True +[06:15:33 INFO] Video batch 20: frame 80/200 (40%) +[06:15:33 INFO] Video batch 20: 1 detections from postprocess +[06:15:33 INFO] Video frame video_test01_000031: 1 dets, valid=True +[06:15:33 INFO] Video batch 21: frame 84/200 (42%) +[06:15:33 INFO] Video batch 21: 1 detections from postprocess +[06:15:33 INFO] Video frame video_test01_000033: 1 dets, valid=True +[06:15:33 INFO] Video batch 22: frame 88/200 (44%) +[06:15:33 INFO] Video batch 22: 1 detections from postprocess +[06:15:33 INFO] Video frame video_test01_000034: 1 dets, valid=True +[06:15:33 INFO] Video batch 23: frame 92/200 (46%) +[06:15:33 INFO] Video batch 24: frame 96/200 (48%) +[06:15:34 INFO] Video batch 25: frame 100/200 (50%) +[06:15:34 INFO] Video batch 26: frame 104/200 (52%) +[06:15:34 INFO] Video batch 26: 1 detections from postprocess +[06:15:34 INFO] Video frame video_test01_000041: 1 dets, valid=True +[06:15:34 INFO] Video batch 27: frame 108/200 (54%) +[06:15:34 INFO] Video batch 27: 1 detections from postprocess +[06:15:34 INFO] Video frame video_test01_000042: 1 dets, valid=True +[06:15:34 INFO] Video batch 28: frame 112/200 (56%) +[06:15:34 INFO] Video batch 28: 1 detections from postprocess +[06:15:34 INFO] Video frame video_test01_000044: 1 dets, valid=True +[06:15:34 INFO] Video batch 29: frame 116/200 (58%) +[06:15:34 INFO] Video batch 29: 1 detections from postprocess +[06:15:34 INFO] Video frame video_test01_000046: 1 dets, valid=True +[06:15:34 INFO] Video batch 30: frame 120/200 (60%) +[06:15:34 INFO] Video batch 30: 1 detections from postprocess +[06:15:34 INFO] Video frame video_test01_000047: 1 dets, valid=True +[06:15:34 INFO] Video batch 31: frame 124/200 (62%) +[06:15:34 INFO] Video batch 31: 1 detections from postprocess +[06:15:34 INFO] Video frame video_test01_000049: 1 dets, valid=True +[06:15:34 INFO] Video batch 32: frame 128/200 (64%) +[06:15:35 INFO] Video batch 32: 1 detections from postprocess +[06:15:35 INFO] Video frame video_test01_000050: 1 dets, valid=True +[06:15:35 INFO] Video batch 33: frame 132/200 (66%) +[06:15:35 INFO] Video batch 33: 1 detections from postprocess +[06:15:35 INFO] Video frame video_test01_000052: 1 dets, valid=True +[06:15:35 INFO] Video batch 34: frame 136/200 (68%) +[06:15:35 INFO] Video batch 34: 1 detections from postprocess +[06:15:35 INFO] Video frame video_test01_000054: 1 dets, valid=True +[06:15:35 INFO] Video batch 35: frame 140/200 (70%) +[06:15:35 INFO] Video batch 35: 1 detections from postprocess +[06:15:35 INFO] Video frame video_test01_000055: 1 dets, valid=True +[06:15:35 INFO] Video batch 36: frame 144/200 (72%) +[06:15:35 INFO] Video batch 36: 1 detections from postprocess +[06:15:35 INFO] Video frame video_test01_000057: 1 dets, valid=True +[06:15:35 INFO] Video batch 37: frame 148/200 (74%) +[06:15:35 INFO] Video batch 38: frame 152/200 (76%) +[06:15:35 INFO] Video batch 39: frame 156/200 (78%) +[06:15:36 INFO] Video batch 40: frame 160/200 (80%) +[06:15:36 INFO] Video batch 41: frame 164/200 (82%) +[06:15:36 INFO] Video batch 42: frame 168/200 (84%) +[06:15:36 INFO] Video batch 42: 1 detections from postprocess +[06:15:36 INFO] Video frame video_test01_000066: 1 dets, valid=True +[06:15:36 INFO] Video batch 43: frame 172/200 (86%) +[06:15:36 INFO] Video batch 43: 1 detections from postprocess +[06:15:36 INFO] Video frame video_test01_000068: 1 dets, valid=True +[06:15:36 INFO] Video batch 44: frame 176/200 (88%) +[06:15:36 INFO] Video batch 45: frame 180/200 (90%) +[06:15:36 INFO] Video batch 46: frame 184/200 (92%) +[06:15:36 INFO] Video batch 46: 1 detections from postprocess +[06:15:36 INFO] Video frame video_test01_000073: 1 dets, valid=True +[06:15:36 INFO] Video batch 47: frame 188/200 (94%) +[06:15:37 INFO] Video batch 47: 1 detections from postprocess +[06:15:37 INFO] Video frame video_test01_000074: 1 dets, valid=True +[06:15:37 INFO] Video batch 48: frame 192/200 (96%) +[06:15:37 INFO] Video batch 48: 1 detections from postprocess +[06:15:37 INFO] Video frame video_test01_000076: 1 dets, valid=True +[06:15:37 INFO] Video batch 49: frame 196/200 (98%) +[06:15:37 INFO] Video batch 49: 1 detections from postprocess +[06:15:37 INFO] Video frame video_test01_000078: 1 dets, valid=True +[06:15:37 INFO] Video batch 50: frame 200/200 (100%) +[06:15:37 INFO] Video batch 50: 1 detections from postprocess +[06:15:37 INFO] Video frame video_test01_000079: 1 dets, valid=True +[06:15:37 INFO] Video done: 200 frames read, 50 batches processed +[06:15:37 INFO] init AI... +[06:15:37 INFO] run inference on /Users/obezdienie001/dev/azaion/suite/detections/e2e/fixtures/image_small.jpg... +[06:15:37 INFO] ground sampling distance: 0.3059895833333333 +[06:15:37 INFO] init AI... +[06:15:37 INFO] Initial ann: image_small_000000: class: 0 77.0% (0.47, 0.21) (0.14, 0.19) +[06:15:37 INFO] Removed (53.80277931690216 42.89022199809551) > 8. class: ArmorVehicle +[06:15:37 INFO] init AI... +[06:15:37 INFO] init AI... +[06:15:38 INFO] init AI... +[06:15:38 INFO] init AI... +[06:15:38 INFO] init AI... +[06:15:38 INFO] init AI... +[06:15:38 INFO] init AI... +[06:15:38 INFO] init AI... +[06:15:38 INFO] init AI... +[06:15:38 INFO] init AI... +[06:15:39 INFO] init AI... +[06:15:39 INFO] init AI... +[06:15:39 INFO] init AI... +[06:15:39 INFO] init AI... +[06:15:39 INFO] init AI... +[06:15:39 INFO] init AI... +[06:15:40 INFO] init AI... +[06:15:40 INFO] init AI... +[06:15:40 INFO] init AI... +[06:15:40 INFO] init AI... +[06:15:40 INFO] init AI... +[06:15:40 INFO] init AI... +[06:15:40 INFO] init AI... +[06:15:41 INFO] init AI... +[06:15:41 INFO] init AI... +[06:15:41 INFO] init AI... +[06:15:41 INFO] init AI... +[06:15:41 INFO] init AI... +[06:15:42 INFO] init AI... +[06:15:42 INFO] init AI... +[06:15:42 INFO] init AI... +[06:15:42 INFO] init AI... +[06:15:42 INFO] init AI... +[06:15:42 INFO] init AI... +[06:15:43 INFO] init AI... +[06:15:43 INFO] init AI... +[06:15:43 INFO] init AI... +[06:15:43 INFO] run inference on /Users/obezdienie001/dev/azaion/suite/detections/e2e/fixtures/video_test01.mp4... +[06:15:43 INFO] Video: 200 frames, 25.0 fps, 2560x1440 +[06:15:43 INFO] Video batch 1: frame 4/200 (2%) +[06:15:44 INFO] Video batch 2: frame 8/200 (4%) +[06:15:44 INFO] Video batch 3: frame 12/200 (6%) +[06:15:44 INFO] Video batch 4: frame 16/200 (8%) +[06:15:44 INFO] Video batch 4: 1 detections from postprocess +[06:15:44 INFO] Video frame video_test01_000006: 1 dets, valid=True +[06:15:44 INFO] Video batch 5: frame 20/200 (10%) +[06:15:44 INFO] Video batch 5: 1 detections from postprocess +[06:15:44 INFO] Video frame video_test01_000007: 1 dets, valid=False +[06:15:44 INFO] Video batch 6: frame 24/200 (12%) +[06:15:44 INFO] Video batch 6: 1 detections from postprocess +[06:15:44 INFO] Video frame video_test01_000009: 1 dets, valid=False +[06:15:44 INFO] Video batch 7: frame 28/200 (14%) +[06:15:44 INFO] Video batch 7: 1 detections from postprocess +[06:15:44 INFO] Video frame video_test01_000010: 1 dets, valid=False +[06:15:44 INFO] Video batch 8: frame 32/200 (16%) +[06:15:45 INFO] Video batch 8: 1 detections from postprocess +[06:15:45 INFO] Video frame video_test01_000012: 1 dets, valid=False +[06:15:45 INFO] Video batch 9: frame 36/200 (18%) +[06:15:45 INFO] Video batch 9: 1 detections from postprocess +[06:15:45 INFO] Video frame video_test01_000014: 1 dets, valid=False +[06:15:45 INFO] Video batch 10: frame 40/200 (20%) +[06:15:45 INFO] Video batch 10: 1 detections from postprocess +[06:15:45 INFO] Video frame video_test01_000015: 1 dets, valid=False +[06:15:45 INFO] Video batch 11: frame 44/200 (22%) +[06:15:45 INFO] Video batch 11: 1 detections from postprocess +[06:15:45 INFO] Video frame video_test01_000017: 1 dets, valid=False +[06:15:45 INFO] Video batch 12: frame 48/200 (24%) +[06:15:45 INFO] Video batch 12: 1 detections from postprocess +[06:15:45 INFO] Video frame video_test01_000018: 1 dets, valid=False +[06:15:45 INFO] Video batch 13: frame 52/200 (26%) +[06:15:45 INFO] Video batch 13: 1 detections from postprocess +[06:15:45 INFO] Video frame video_test01_000020: 1 dets, valid=False +[06:15:45 INFO] Video batch 14: frame 56/200 (28%) +[06:15:45 INFO] Video batch 14: 1 detections from postprocess +[06:15:45 INFO] Video frame video_test01_000022: 1 dets, valid=False +[06:15:45 INFO] Video batch 15: frame 60/200 (30%) +[06:15:45 INFO] Video batch 15: 1 detections from postprocess +[06:15:45 INFO] Video frame video_test01_000023: 1 dets, valid=False +[06:15:45 INFO] Video batch 16: frame 64/200 (32%) +[06:15:46 INFO] Video batch 16: 1 detections from postprocess +[06:15:46 INFO] Video frame video_test01_000025: 1 dets, valid=False +[06:15:46 INFO] Video batch 17: frame 68/200 (34%) +[06:15:46 INFO] Video batch 17: 1 detections from postprocess +[06:15:46 INFO] Video frame video_test01_000026: 1 dets, valid=True +[06:15:46 INFO] Video batch 18: frame 72/200 (36%) +[06:15:46 INFO] Video batch 18: 1 detections from postprocess +[06:15:46 INFO] Video frame video_test01_000028: 1 dets, valid=False +[06:15:46 INFO] Video batch 19: frame 76/200 (38%) +[06:15:46 INFO] Video batch 19: 1 detections from postprocess +[06:15:46 INFO] Video frame video_test01_000030: 1 dets, valid=False +[06:15:46 INFO] Video batch 20: frame 80/200 (40%) +[06:15:46 INFO] Video batch 20: 1 detections from postprocess +[06:15:46 INFO] Video frame video_test01_000031: 1 dets, valid=False +[06:15:46 INFO] Video batch 21: frame 84/200 (42%) +[06:15:46 INFO] Video batch 21: 1 detections from postprocess +[06:15:46 INFO] Video frame video_test01_000033: 1 dets, valid=False +[06:15:46 INFO] Video batch 22: frame 88/200 (44%) +[06:15:46 INFO] Video batch 22: 1 detections from postprocess +[06:15:46 INFO] Video frame video_test01_000034: 1 dets, valid=False +[06:15:46 INFO] Video batch 23: frame 92/200 (46%) +[06:15:46 INFO] Video batch 24: frame 96/200 (48%) +[06:15:47 INFO] Video batch 25: frame 100/200 (50%) +[06:15:47 INFO] Video batch 26: frame 104/200 (52%) +[06:15:47 INFO] Video batch 26: 1 detections from postprocess +[06:15:47 INFO] Video frame video_test01_000041: 1 dets, valid=False +[06:15:47 INFO] Video batch 27: frame 108/200 (54%) +[06:15:47 INFO] Video batch 27: 1 detections from postprocess +[06:15:47 INFO] Video frame video_test01_000042: 1 dets, valid=False +[06:15:47 INFO] Video batch 28: frame 112/200 (56%) +[06:15:47 INFO] Video batch 28: 1 detections from postprocess +[06:15:47 INFO] Video frame video_test01_000044: 1 dets, valid=False +[06:15:47 INFO] Video batch 29: frame 116/200 (58%) +[06:15:47 INFO] Video batch 29: 1 detections from postprocess +[06:15:47 INFO] Video frame video_test01_000046: 1 dets, valid=False +[06:15:47 INFO] Video batch 30: frame 120/200 (60%) +[06:15:47 INFO] Video batch 30: 1 detections from postprocess +[06:15:47 INFO] Video frame video_test01_000047: 1 dets, valid=True +[06:15:47 INFO] Video batch 31: frame 124/200 (62%) +[06:15:47 INFO] Video batch 31: 1 detections from postprocess +[06:15:47 INFO] Video frame video_test01_000049: 1 dets, valid=False +[06:15:47 INFO] Video batch 32: frame 128/200 (64%) +[06:15:48 INFO] Video batch 32: 1 detections from postprocess +[06:15:48 INFO] Video frame video_test01_000050: 1 dets, valid=False +[06:15:48 INFO] Video batch 33: frame 132/200 (66%) +[06:15:48 INFO] Video batch 33: 1 detections from postprocess +[06:15:48 INFO] Video frame video_test01_000052: 1 dets, valid=False +[06:15:48 INFO] Video batch 34: frame 136/200 (68%) +[06:15:48 INFO] Video batch 34: 1 detections from postprocess +[06:15:48 INFO] Video frame video_test01_000054: 1 dets, valid=False +[06:15:48 INFO] Video batch 35: frame 140/200 (70%) +[06:15:48 INFO] Video batch 35: 1 detections from postprocess +[06:15:48 INFO] Video frame video_test01_000055: 1 dets, valid=False +[06:15:48 INFO] Video batch 36: frame 144/200 (72%) +[06:15:48 INFO] Video batch 36: 1 detections from postprocess +[06:15:48 INFO] Video frame video_test01_000057: 1 dets, valid=False +[06:15:48 INFO] Video batch 37: frame 148/200 (74%) +[06:15:48 INFO] Video batch 38: frame 152/200 (76%) +[06:15:49 INFO] Video batch 39: frame 156/200 (78%) +[06:15:49 INFO] Video batch 40: frame 160/200 (80%) +[06:15:49 INFO] Video batch 41: frame 164/200 (82%) +[06:15:49 INFO] Video batch 42: frame 168/200 (84%) +[06:15:49 INFO] Video batch 42: 1 detections from postprocess +[06:15:49 INFO] Video frame video_test01_000066: 1 dets, valid=False +[06:15:49 INFO] Video batch 43: frame 172/200 (86%) +[06:15:49 INFO] Video batch 43: 1 detections from postprocess +[06:15:49 INFO] Video frame video_test01_000068: 1 dets, valid=True +[06:15:49 INFO] Video batch 44: frame 176/200 (88%) +[06:15:49 INFO] Video batch 45: frame 180/200 (90%) +[06:15:50 INFO] Video batch 46: frame 184/200 (92%) +[06:15:50 INFO] Video batch 46: 1 detections from postprocess +[06:15:50 INFO] Video frame video_test01_000073: 1 dets, valid=True +[06:15:50 INFO] Video batch 47: frame 188/200 (94%) +[06:15:50 INFO] Video batch 47: 1 detections from postprocess +[06:15:50 INFO] Video frame video_test01_000074: 1 dets, valid=False +[06:15:50 INFO] Video batch 48: frame 192/200 (96%) +[06:15:50 INFO] Video batch 48: 1 detections from postprocess +[06:15:50 INFO] Video frame video_test01_000076: 1 dets, valid=False +[06:15:50 INFO] Video batch 49: frame 196/200 (98%) +[06:15:50 INFO] Video batch 49: 1 detections from postprocess +[06:15:50 INFO] Video frame video_test01_000078: 1 dets, valid=False +[06:15:50 INFO] Video batch 50: frame 200/200 (100%) +[06:15:50 INFO] Video batch 50: 1 detections from postprocess +[06:15:50 INFO] Video frame video_test01_000079: 1 dets, valid=False +[06:15:50 INFO] Video done: 200 frames read, 50 batches processed diff --git a/ai_availability_status.pyx b/ai_availability_status.pyx index 274324b..f72931c 100644 --- a/ai_availability_status.pyx +++ b/ai_availability_status.pyx @@ -25,7 +25,7 @@ cdef class AIAvailabilityStatus: cdef bytes serialize(self): with self._lock: - return msgpack.packb({ + return msgpack.packb({ "s": self.status, "m": self.error_message }) diff --git a/annotation.pyx b/annotation.pyx index 67d1ef2..bd73537 100644 --- a/annotation.pyx +++ b/annotation.pyx @@ -3,7 +3,7 @@ cimport constants_inf cdef class Detection: def __init__(self, double x, double y, double w, double h, int cls, double confidence): - self.annotation_name = None + self.annotation_name = "" self.x = x self.y = y self.w = w @@ -54,7 +54,7 @@ cdef class Annotation: return f"{self.name}: {detections_str}" cdef bytes serialize(self): - return msgpack.packb({ + return msgpack.packb({ "n": self.name, "mn": self.original_media_name, "i": self.image, # "i" = image diff --git a/constants_inf.pxd b/constants_inf.pxd index f5573eb..02b7977 100644 --- a/constants_inf.pxd +++ b/constants_inf.pxd @@ -19,7 +19,7 @@ cdef int METERS_IN_TILE cdef log(str log_message) cdef logerror(str error) -cdef format_time(int ms) +cdef format_time(long ms) cdef dict[int, AnnotationClass] annotations_dict diff --git a/constants_inf.pyx b/constants_inf.pyx index 2743a91..195457a 100644 --- a/constants_inf.pyx +++ b/constants_inf.pyx @@ -81,7 +81,7 @@ cdef log(str log_message): cdef logerror(str error): logger.error(error) -cdef format_time(int ms): +cdef format_time(long ms): # Calculate hours, minutes, seconds, and hundreds of milliseconds. h = ms // 3600000 # Total full hours. ms_remaining = ms % 3600000 diff --git a/e2e/conftest.py b/e2e/conftest.py index c5f8f27..cc4260a 100644 --- a/e2e/conftest.py +++ b/e2e/conftest.py @@ -35,14 +35,14 @@ class _SessionWithBase(requests.Session): self._base = base.rstrip("/") self._default_timeout = default_timeout - def request(self, method, url, **kwargs): + def request(self, method, url, *args, **kwargs): if url.startswith("http://") or url.startswith("https://"): full = url else: path = url if url.startswith("/") else f"/{url}" full = f"{self._base}{path}" kwargs.setdefault("timeout", self._default_timeout) - return super().request(method, full, **kwargs) + return super().request(method, full, *args, **kwargs) @pytest.fixture(scope="session") diff --git a/engines/__init__.py b/engines/__init__.py index 856610f..c1b7a4e 100644 --- a/engines/__init__.py +++ b/engines/__init__.py @@ -40,7 +40,7 @@ tensor_gpu_index = _check_tensor_gpu_index() def _select_engine_class(): if tensor_gpu_index > -1: - from engines.tensorrt_engine import TensorRTEngine + from engines.tensorrt_engine import TensorRTEngine # pyright: ignore[reportMissingImports] return TensorRTEngine if _is_apple_silicon(): from engines.coreml_engine import CoreMLEngine diff --git a/engines/coreml_engine.pyx b/engines/coreml_engine.pyx index 710139b..359a981 100644 --- a/engines/coreml_engine.pyx +++ b/engines/coreml_engine.pyx @@ -28,10 +28,7 @@ cdef class CoreMLEngine(InferenceEngine): self.batch_size = 1 constants_inf.log(f'CoreML model: {self.img_width}x{self.img_height}') - - @property - def engine_name(self): - return "coreml" + self.engine_name = "coreml" @staticmethod def get_engine_filename(): @@ -49,10 +46,10 @@ cdef class CoreMLEngine(InferenceEngine): raise ValueError("No .mlpackage or .mlmodel found in zip") cdef tuple get_input_shape(self): - return self.img_height, self.img_width + return (self.img_height, self.img_width) cdef int get_batch_size(self): - return 1 + return 1 cdef run(self, input_data): cdef int w = self.img_width diff --git a/engines/inference_engine.pxd b/engines/inference_engine.pxd index 73680d6..3ff040b 100644 --- a/engines/inference_engine.pxd +++ b/engines/inference_engine.pxd @@ -4,6 +4,7 @@ import numpy as np cdef class InferenceEngine: cdef public int batch_size - cdef tuple get_input_shape(self) - cdef int get_batch_size(self) - cdef run(self, input_data) + cdef public str engine_name + cdef tuple get_input_shape(self) # type: ignore + cdef int get_batch_size(self) # type: ignore + cdef run(self, input_data) # type: ignore diff --git a/engines/inference_engine.pyx b/engines/inference_engine.pyx index 2268a66..e30d56f 100644 --- a/engines/inference_engine.pyx +++ b/engines/inference_engine.pyx @@ -1,10 +1,7 @@ cdef class InferenceEngine: def __init__(self, model_bytes: bytes, batch_size: int = 1, **kwargs): self.batch_size = batch_size - - @property - def engine_name(self): - return "onnx" + self.engine_name = "onnx" @staticmethod def get_engine_filename(): @@ -22,7 +19,7 @@ cdef class InferenceEngine: raise NotImplementedError("Subclass must implement get_input_shape") cdef int get_batch_size(self): - return self.batch_size + return self.batch_size cdef run(self, input_data): raise NotImplementedError("Subclass must implement run") diff --git a/engines/onnx_engine.pyx b/engines/onnx_engine.pyx index 5a58390..9770008 100644 --- a/engines/onnx_engine.pyx +++ b/engines/onnx_engine.pyx @@ -36,15 +36,15 @@ cdef class OnnxEngine(InferenceEngine): cdef tuple get_input_shape(self): shape = self.input_shape - return shape[2], shape[3] + return (shape[2], shape[3]) cdef int get_batch_size(self): - return self.batch_size + return self.batch_size cdef run(self, input_data): try: - return self.session.run(None, {self.input_name: input_data}) + return self.session.run(None, {self.input_name: input_data}) # type: ignore[attr-defined] except Exception: if self._cpu_session is not None: - return self._cpu_session.run(None, {self.input_name: input_data}) + return self._cpu_session.run(None, {self.input_name: input_data}) # type: ignore[attr-defined] raise \ No newline at end of file diff --git a/engines/tensorrt_engine.pxd b/engines/tensorrt_engine.pxd index 856e9f4..53237ab 100644 --- a/engines/tensorrt_engine.pxd +++ b/engines/tensorrt_engine.pxd @@ -8,7 +8,7 @@ cdef class TensorRTEngine(InferenceEngine): cdef public object d_input cdef public object d_output cdef str input_name - cdef object input_shape + cdef list input_shape cdef object h_output cdef str output_name diff --git a/engines/tensorrt_engine.pyx b/engines/tensorrt_engine.pyx index cbfb5b7..575f6b5 100644 --- a/engines/tensorrt_engine.pyx +++ b/engines/tensorrt_engine.pyx @@ -1,7 +1,7 @@ from engines.inference_engine cimport InferenceEngine -import tensorrt as trt -import pycuda.driver as cuda -import pycuda.autoinit # required for automatically initialize CUDA, do not remove. +import tensorrt as trt # pyright: ignore[reportMissingImports] +import pycuda.driver as cuda # pyright: ignore[reportMissingImports] +import pycuda.autoinit # pyright: ignore[reportMissingImports] # required for automatically initialize CUDA, do not remove. import pynvml import numpy as np cimport constants_inf @@ -54,6 +54,7 @@ cdef class TensorRTEngine(InferenceEngine): except Exception as e: raise RuntimeError(f"Failed to initialize TensorRT engine: {str(e)}") + self.engine_name = "tensorrt" @staticmethod def get_gpu_memory_bytes(int device_id): @@ -72,10 +73,6 @@ cdef class TensorRTEngine(InferenceEngine): pass return 2 * 1024 * 1024 * 1024 if total_memory is None else total_memory # default 2 Gb - @property - def engine_name(self): - return "tensorrt" - @staticmethod def get_engine_filename(): try: @@ -123,23 +120,22 @@ cdef class TensorRTEngine(InferenceEngine): return bytes(plan) cdef tuple get_input_shape(self): - return self.input_shape[2], self.input_shape[3] + return (self.input_shape[2], self.input_shape[3]) cdef int get_batch_size(self): - return self.batch_size + return self.batch_size cdef run(self, input_data): try: cuda.memcpy_htod_async(self.d_input, input_data, self.stream) - self.context.set_tensor_address(self.input_name, int(self.d_input)) # input buffer - self.context.set_tensor_address(self.output_name, int(self.d_output)) # output buffer + self.context.set_tensor_address(self.input_name, int(self.d_input)) # type: ignore + self.context.set_tensor_address(self.output_name, int(self.d_output)) # type: ignore - self.context.execute_async_v3(stream_handle=self.stream.handle) - self.stream.synchronize() + self.context.execute_async_v3(stream_handle=self.stream.handle) # type: ignore + self.stream.synchronize() # type: ignore - # Fix: Remove the stream parameter from memcpy_dtoh cuda.memcpy_dtoh(self.h_output, self.d_output) - output = self.h_output.reshape(self.output_shape) + output = self.h_output.reshape(self.output_shape) # type: ignore return [output] except Exception as e: diff --git a/inference.pyx b/inference.pyx index 7374f93..c4b6ef5 100644 --- a/inference.pyx +++ b/inference.pyx @@ -63,7 +63,7 @@ cdef class Inference: res = self.loader_client.load_big_small_resource(filename, models_dir) if res.err is not None: raise Exception(res.err) - return res.data + return res.data cdef convert_and_upload_model(self, bytes source_bytes, str engine_filename): try: @@ -120,7 +120,7 @@ cdef class Inference: return self.ai_availability_status.set_status(AIAvailabilityEnum.WARNING, str(e)) source_bytes = self.download_model(source_filename) - self.is_building_engine = True + self.is_building_engine = True thread = Thread(target=self.convert_and_upload_model, args=(source_bytes, engine_filename)) thread.daemon = True @@ -129,12 +129,12 @@ cdef class Inference: else: self.engine = EngineClass(self.download_model(constants_inf.AI_ONNX_MODEL_FILE)) self.ai_availability_status.set_status(AIAvailabilityEnum.ENABLED) - self.is_building_engine = False + self.is_building_engine = False self.model_height, self.model_width = self.engine.get_input_shape() except Exception as e: self.ai_availability_status.set_status(AIAvailabilityEnum.ERROR, str(e)) - self.is_building_engine = False + self.is_building_engine = False cdef preprocess(self, frames): @@ -171,7 +171,7 @@ cdef class Inference: w = x2 - x1 h = y2 - y1 if conf >= ai_config.probability_threshold: - detections.append(Detection(x, y, w, h, class_id, conf)) + detections.append(Detection(x, y, w, h, class_id, conf)) # type: ignore[call-arg] filtered_detections = self.remove_overlapping_detections(detections, ai_config.tracking_intersection_threshold) results.append(filtered_detections) return results @@ -320,7 +320,7 @@ cdef class Inference: original_media_name = Path(video_name).stem.replace(" ", "") name = f'{original_media_name}_{constants_inf.format_time(batch_timestamps[i])}' - annotation = Annotation(name, original_media_name, batch_timestamps[i], detections) + annotation = Annotation(name, original_media_name, batch_timestamps[i], detections) # type: ignore[call-arg] if detections: valid = self.is_valid_video_annotation(annotation, ai_config) @@ -348,6 +348,7 @@ cdef class Inference: cdef _process_images(self, AIRecognitionConfig ai_config, list[str] image_paths): cdef list frame_data + cdef double ground_sampling_distance self._tile_detections = {} for path in image_paths: frame_data = [] @@ -423,7 +424,7 @@ cdef class Inference: list_detections = self.postprocess(outputs, ai_config) for i in range(len(list_detections)): - annotation = Annotation(names[i], original_media_names[i], 0, list_detections[i]) + annotation = Annotation(names[i], original_media_names[i], 0, list_detections[i]) # type: ignore[call-arg] if self.is_valid_image_annotation(annotation, ground_sampling_distance, frames[i].shape): constants_inf.log( f'Detected {annotation}') _, image = cv2.imencode('.jpg', frames[i]) @@ -431,7 +432,7 @@ cdef class Inference: self.on_annotation(annotation) cpdef stop(self): - self.stop_signal = True + self.stop_signal = True cdef remove_tiled_duplicates(self, Annotation annotation): right = annotation.name.rindex('!') @@ -448,7 +449,7 @@ cdef class Inference: for det in annotation.detections: x1 = det.x * tile_size y1 = det.y * tile_size - det_abs = Detection(x + x1, y + y1, det.w * tile_size, det.h * tile_size, det.cls, det.confidence) + det_abs = Detection(x + x1, y + y1, det.w * tile_size, det.h * tile_size, det.cls, det.confidence) # type: ignore[call-arg] if det_abs not in existing_abs_detections: unique_detections.append(det) @@ -478,23 +479,23 @@ cdef class Inference: annotation.detections = valid_detections if not annotation.detections: - return False - return True + return False + return True cdef bint is_valid_video_annotation(self, Annotation annotation, AIRecognitionConfig ai_config): if constants_inf.SPLIT_SUFFIX in annotation.name: self.remove_tiled_duplicates(annotation) if not annotation.detections: - return False + return False if self._previous_annotation is None: - return True + return True if annotation.time >= self._previous_annotation.time + (ai_config.frame_recognition_seconds * 1000): - return True + return True if len(annotation.detections) > len(self._previous_annotation.detections): - return True + return True cdef: Detection current_det, prev_det @@ -502,8 +503,8 @@ cdef class Inference: Detection closest_det for current_det in annotation.detections: - min_distance_sq = 1e18 - closest_det = None + min_distance_sq = 1e18 + closest_det = None for prev_det in self._previous_annotation.detections: dx = current_det.x - prev_det.x @@ -517,9 +518,9 @@ cdef class Inference: dist_px = ai_config.tracking_distance_confidence * self.model_width dist_px_sq = dist_px * dist_px if min_distance_sq > dist_px_sq: - return True + return True if current_det.confidence >= closest_det.confidence + ai_config.tracking_probability_increase: - return True + return True - return False + return False diff --git a/run-tests.sh b/run-tests.sh index fbb793c..3dad4ff 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -17,6 +17,9 @@ cleanup() { } trap cleanup EXIT +echo "Building Cython extensions ..." +python setup.py build_ext --inplace + for port in $LOADER_PORT $ANNOTATIONS_PORT $DETECTIONS_PORT; do if lsof -ti :"$port" >/dev/null 2>&1; then echo "ERROR: port $port is already in use" >&2 diff --git a/setup.py b/setup.py index 556e216..118594d 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ extensions = [ ] try: - import tensorrt + import tensorrt # pyright: ignore[reportMissingImports] extensions.append( Extension('engines.tensorrt_engine', ['engines/tensorrt_engine.pyx'], include_dirs=[np.get_include()]) )