Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding integration test #23

Merged
merged 55 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
add347d
first try of test to refacto
nmathieufact Mar 21, 2024
cc2e60e
tried approach comparing df
nmathieufact Mar 22, 2024
da5cd48
revert change on notebook example
nmathieufact Mar 22, 2024
e3f660a
clean the python pytest script
nmathieufact Mar 22, 2024
ebb3e0e
generating all files and output for second video test
nmathieufact Mar 22, 2024
c876fee
added a new test and cleaned a bit
nmathieufact Mar 22, 2024
2c28500
added a new test and cleaned a bit
nmathieufact Mar 22, 2024
d453cc2
fix the name of notebook
nmathieufact Mar 22, 2024
bea827d
feat added output and input files
nmathieufact Mar 22, 2024
8b7092d
fix: path in python regression script
nmathieufact Mar 22, 2024
ac92605
fix paths in notebook
nmathieufact Mar 22, 2024
21904b8
fixed the path static variables
nmathieufact Mar 22, 2024
68d72a6
improved approach
nmathieufact Mar 22, 2024
1fa637f
fix readme adding relevant citation
nmathieufact Mar 22, 2024
2958fc6
Update README.md with common style
nmathieufact Mar 22, 2024
bcb9650
adjusted README.md citation style
nmathieufact Mar 22, 2024
5e707f1
adjusted a last output path
nmathieufact Mar 22, 2024
69f7565
simplified title
nmathieufact Mar 22, 2024
a8bba90
feat updating files
nmathieufact Mar 25, 2024
d7aa71b
feat: applied new columns schema
nmathieufact Mar 25, 2024
be0d84f
removed notebook generating the input and output
nmathieufact Mar 25, 2024
9f5b711
changed approach removing pandas
nmathieufact Mar 25, 2024
f6154de
fix the bytetracker fixture
nmathieufact Mar 25, 2024
5901a7f
fix corrected path
nmathieufact Mar 25, 2024
772e6be
removed pandas import and usage
nmathieufact Mar 25, 2024
df4be2d
feat tried approachh for reseting bt
nmathieufact Mar 25, 2024
5252cb1
fix the path and revert bytetracker reset
nmathieufact Mar 25, 2024
d14d5fb
fix the path and revert bytetracker reset
nmathieufact Mar 25, 2024
8d1ec82
updated docstring
nmathieufact Mar 25, 2024
b60bfa0
fix update docstring first function
nmathieufact Mar 25, 2024
f2dae3f
fix format of docstring
nmathieufact Mar 25, 2024
2a618e0
correcte output docstring
nmathieufact Mar 25, 2024
6ea4782
fix wording of read/reading
nmathieufact Mar 25, 2024
869425a
corrected typing from 1st function
nmathieufact Mar 25, 2024
e51fb1f
fix output path
nmathieufact Mar 25, 2024
f747f28
removed path being unuseful
nmathieufact Mar 25, 2024
d0f3a8c
added tests for CI
nmathieufact Mar 25, 2024
a7f6da0
introducing allclose assertion to make it pass
nmathieufact Mar 25, 2024
230c295
fix pytest command with poetry
nmathieufact Mar 25, 2024
e5e359e
fix CI trying another approach
nmathieufact Mar 26, 2024
8ec28b2
fix reverted ci
nmathieufact Mar 26, 2024
27c3a50
fix the frame unique sorted
nmathieufact Mar 26, 2024
2496abb
fix test results
nmathieufact Mar 26, 2024
7c7f963
fix the tests
nmathieufact Mar 26, 2024
7f5dd3e
fix output
nmathieufact Mar 26, 2024
b37f73d
fix the second video expected output
nmathieufact Mar 26, 2024
611a5de
fix the expected output with new env
nmathieufact Mar 26, 2024
5438b9a
corrected package
nmathieufact Mar 26, 2024
0c26c7f
revert change
nmathieufact Mar 26, 2024
fa57efb
feat other approach
nmathieufact Mar 26, 2024
fbd69ae
revert change
nmathieufact Mar 26, 2024
a8443a5
corrected format
nmathieufact Mar 26, 2024
12c6fde
fixed second format
nmathieufact Mar 26, 2024
d50f4b0
fix input format
nmathieufact Mar 26, 2024
e505751
fix removed print
nmathieufact Mar 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"),
nmathieufact marked this conversation as resolved.
Show resolved Hide resolved
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)
tristanpepinartefact marked this conversation as resolved.
Show resolved Hide resolved

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