Skip to content

Commit

Permalink
feat: adding integration test (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
nmathieufact authored Mar 26, 2024
1 parent 0f2f63b commit 95372b9
Show file tree
Hide file tree
Showing 7 changed files with 4,314 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ jobs:
poetry install
- name: Run Pre commit hooks
run: make format-code
run: make format-code

- name: Run Tests
run: poetry run pytest tests
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,10 @@ ByteTrack is licensed under the MIT License. See the [LICENSE](LICENSE) file and
year={2022}
}
```

```bibtex
@video{intel-iot-devkit,
author={Intel IoT},
title={Intel IoT Devkit Sample Videos(https://github.com/intel-iot-devkit/sample-videos)},
license={Creative Commons Attribution 4.0 International License(https://creativecommons.org/licenses/by/4.0/)}
```
1,782 changes: 1,782 additions & 0 deletions tests/expected_output/objects_detected_and_tracked_video1.txt

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions tests/expected_output/objects_detected_and_tracked_video2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
117 0.9745912458451594 0.5095593279999999 0.99959984 0.74230442 143 49 0.83191514
118 0.9723770479661737 0.5005956551190778 0.9995706489616996 0.7455164254441724 143 49 0.8575639
119 0.9692140420648577 0.49633454280262446 0.9995032670131737 0.7480595000990486 143 49 0.886084
120 0.9597182832171389 0.49863391199158746 0.995071975596858 0.7532388859200183 143 49 0.9059332
121 0.9137050982061102 0.4994814482436807 0.9549359765857107 0.7572477552931745 143 49 0.92144907
122 0.8638723820710912 0.49995341002499705 0.9114848787732324 0.760094310118092 143 49 0.9317426
123 0.8202442793180998 0.5008927419997994 0.8744436576830644 0.7617456794854497 143 49 0.9288402
124 0.7771121850468138 0.5003854964349163 0.8379277554269561 0.7611541282108044 143 49 0.92904073
125 0.7247772638550477 0.5017298388730855 0.7923321297682652 0.7630300613301431 143 49 0.9264275
126 0.667130285243915 0.5027124324340133 0.7416950322200128 0.7661639605174826 143 49 0.93153256
127 0.6166635597480964 0.5032080794919398 0.6977953131744735 0.7674052397214208 143 49 0.93632597
128 0.5704205015010184 0.5034447579718662 0.6576470415989151 0.7674597007527504 143 49 0.9300204
129 0.5200086616300771 0.5042046553066718 0.6129952681758294 0.7679312585911858 143 49 0.927421
130 0.4664305059695041 0.5047469069888177 0.5650968833550777 0.7687824626031954 143 49 0.92839193
131 0.41737613242284965 0.5047965654861531 0.5216674413663417 0.769888234103233 143 49 0.93056595
132 0.3695027147879381 0.5046674259906719 0.4789313778430711 0.7704542275124632 143 49 0.9226942
133 0.31862250657733115 0.5049336005081386 0.4326811327070279 0.7708076297478794 143 49 0.9281332
134 0.26800115344630543 0.5048401760421602 0.38642684109755293 0.7709889020420381 143 49 0.92945176
135 0.22018769086927653 0.5043750140688151 0.34284325134982213 0.7708960147555938 143 49 0.92946494
2,379 changes: 2,379 additions & 0 deletions tests/test_input/objects_detected_video1.txt

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions tests/test_input/objects_detected_video2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
40 0.21998224 0.5836777 0.3745204 0.7639922 0.16180652 49
116 0.9795788 0.53099704 0.9996632 0.7194981 0.51681966 49
117 0.95138013 0.5041999 0.999584 0.748006 0.83191514 49
118 0.9269222 0.49708003 0.9995592 0.7467762 0.8575639 49
119 0.88959634 0.49609375 0.9994829 0.7485177 0.886084 49
120 0.8366054 0.50106037 0.99332654 0.75461787 0.9059332 49
121 0.7823308 0.5008052 0.93827456 0.7578524 0.92144907 49
122 0.73994255 0.50089943 0.89590263 0.76007366 0.9317426 49
123 0.70718193 0.5019245 0.86416876 0.76115876 0.9288402 49
124 0.6728785 0.5005684 0.8293528 0.75955844 0.92904073 49
125 0.624425 0.50280184 0.78042 0.76286423 0.9264275 49
126 0.5726967 0.5034708 0.72873324 0.7666482 0.93153256 49
127 0.53285456 0.50363165 0.6897488 0.7668706 0.93632597 49
128 0.4952455 0.5036848 0.6524906 0.7663839 0.9300204 49
129 0.44878444 0.50468314 0.60615635 0.7671972 0.927421 49
130 0.39896855 0.5050585 0.5573927 0.76832783 0.92839193 49
131 0.35776815 0.5048203 0.51712275 0.76961535 0.93056595 49
132 0.31567994 0.5045963 0.4752435 0.7699328 0.9226942 49
133 0.26709083 0.5050746 0.4275921 0.7702349 0.9281332 49
134 0.22100373 0.5047798 0.3819117 0.77039224 0.92945176 49
135 0.17729278 0.5041295 0.3402054 0.77022386 0.92946494 49
102 changes: 102 additions & 0 deletions tests/test_model_regression.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
from pathlib import Path

import numpy as np
import pytest

# bytetracker
from bytetracker import BYTETracker

# static paths
OUTPUT_FOLDER = Path("tests/output")
TEST_INPUT_FOLDER = Path("tests/test_input")
EXPECTED_OUTPUT_FOLDER = Path("tests/expected_output")
OUTPUT_FOLDER = Path("tests/output")

OUTPUT_FOLDER.mkdir(parents=True, exist_ok=True)


def reading_detections_file(video_number):
"""Read the detections object file from a specific format
Args:
video_number (string): string representing the video name in folder
Returns:
df_detection (ndarray): A list of array of the tuples.
"""
df_detection = np.loadtxt(
TEST_INPUT_FOLDER / f"objects_detected_{video_number}.txt", delimiter=" "
)

return df_detection


def reading_expected_results_from_txt(video_number):
"""Read the detections and tracked objects frames from Yolo and Bytetrack models
Args:
video_number (str): Video title to import
Returns:
expected_results_df (ndarray): array of frames detection and tracking imported from expected results.
"""
expected_results_df = np.loadtxt(
EXPECTED_OUTPUT_FOLDER / f"objects_detected_and_tracked_{video_number}.txt"
)

return expected_results_df


@pytest.mark.parametrize(
"expected_results, test_input, video_number",
[
(
reading_expected_results_from_txt("video1"),
reading_detections_file("video1"),
"video1",
),
(
reading_expected_results_from_txt("video2"),
reading_detections_file("video2"),
"video2",
),
],
)
def test_video_prediction_tracking(expected_results, test_input, video_number):
"""Execute the integration test: performing the tracking of test_input,
whose output is to compare with expected_results
Args:
expected_result (DataFrame): the dataframe of the results expected to match the test result
test_input (array): dataframe that is the import of prediction frames in test_input folder
video_number (string): string component specific to a video
Returns:
Test assertion results
"""
tracker = BYTETracker(track_thresh=0.15, track_buffer=3, match_thresh=0.85, frame_rate=12)
# first column of test input is the frame id
frame_idx = sorted(np.unique(test_input[:, 0]))
test_results = []

for frame_id in frame_idx:
detections = test_input[test_input[:, 0] == frame_id][:, 1:]
tracked_objects = tracker.update(detections, frame_id)
if len(tracked_objects) > 0:
tracked_objects = np.insert(
tracked_objects, 0, np.full(len(tracked_objects), frame_id), axis=1
)
test_results.append(tracked_objects)

if test_results: # Ensure test_results is not empty to avoid errors
combined_array = np.concatenate(test_results)
else:
combined_array = np.array([]) # Or handle the empty case as needed

output_file_path = OUTPUT_FOLDER / f"{video_number}_test_results.txt"
np.savetxt(output_file_path, combined_array, delimiter=" ", fmt="%s")

assert np.allclose(expected_results, combined_array)

# Remove the file if the test is successful
output_file_path.unlink()

0 comments on commit 95372b9

Please sign in to comment.