-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
612759e
commit cf95dde
Showing
23 changed files
with
3,314 additions
and
32 deletions.
There are no files selected for viewing
File renamed without changes.
1,595 changes: 1,595 additions & 0 deletions
1,595
tests/assets/integration_tests/data/tracker_output.txt
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
1,570 changes: 1,570 additions & 0 deletions
1,570
tests/assets/integration_tests/expected_outputs/corrected_tracks.txt
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
tests/assets/integration_tests/expected_outputs/tracked_object_1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"object_id": 1.0, "state": 0, "re_id_chain": [1.0, 33.0], "metadata": {"first_frame_id": 1, "last_frame_id": 363, "class_counts": {"0": 313}, "bbox": [729, 88, 888, 251], "confidence": 0.818931, "confidence_sum": 245.7679709999999, "observations": 313}} |
1 change: 1 addition & 0 deletions
1
tests/assets/integration_tests/expected_outputs/tracked_object_2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"object_id": 2.0, "state": 0, "re_id_chain": [2.0, 6.0, 10.0, 16.0], "metadata": {"first_frame_id": 1, "last_frame_id": 363, "class_counts": {"0": 320}, "bbox": [596, 100, 714, 218], "confidence": 0.631255, "confidence_sum": 224.94876499999998, "observations": 320}} |
1 change: 1 addition & 0 deletions
1
tests/assets/integration_tests/expected_outputs/tracked_object_3.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"object_id": 3.0, "state": 0, "re_id_chain": [3.0, 38.0, 41.0, 45.0], "metadata": {"first_frame_id": 1, "last_frame_id": 363, "class_counts": {"0": 314}, "bbox": [529, 471, 715, 605], "confidence": 0.756379, "confidence_sum": 229.919842, "observations": 314}} |
1 change: 1 addition & 0 deletions
1
tests/assets/integration_tests/expected_outputs/tracked_object_4.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"object_id": 4.0, "state": 0, "re_id_chain": [4.0, 43.0], "metadata": {"first_frame_id": 1, "last_frame_id": 363, "class_counts": {"0": 349}, "bbox": [464, 187, 886, 562], "confidence": 0.575016, "confidence_sum": 260.3729819999998, "observations": 349}} |
1 change: 1 addition & 0 deletions
1
tests/assets/integration_tests/expected_outputs/tracked_object_5.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"object_id": 5.0, "state": 1, "re_id_chain": [5.0, 17.0, 21.0, 23.0, 27.0], "metadata": {"first_frame_id": 1, "last_frame_id": 323, "class_counts": {"0": 422}, "bbox": [584, 260, 710, 477], "confidence": 0.728422, "confidence_sum": 322.0736030000005, "observations": 422}} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import json | ||
from pathlib import Path | ||
|
||
import numpy as np | ||
|
||
from tests.utils.file_utils import compare_files, reset_output_folder | ||
from trackreid.reid_processor import ReidProcessor | ||
from trackreid.tracked_object import TrackedObject | ||
|
||
INPUT_FOLDER = Path("tests/assets/integration_tests/data/") | ||
INPUT_FILE = "tracker_output.txt" | ||
|
||
OUTPUT_FOLDER = Path("tests/results/integration_tests/") | ||
OUTPUT_FILE = "corrected_tracks.txt" | ||
|
||
EXPECTED_OUTPUT_FOLDER = Path("tests/assets/integration_tests/expected_outputs") | ||
EXPECTED_OUTPUT_FILES = [ | ||
OUTPUT_FILE, | ||
"tracked_object_1.json", | ||
"tracked_object_2.json", | ||
"tracked_object_3.json", | ||
"tracked_object_4.json", | ||
"tracked_object_5.json", | ||
] | ||
|
||
|
||
def save_tracked_objects(reid_processor: ReidProcessor, file_path_folder: Path): | ||
for tracked_object in reid_processor.all_tracked_objects: | ||
file_path = file_path_folder / f"tracked_object_{int(tracked_object.object_id)}.json" | ||
with file_path.open("w") as file: | ||
json.dump(tracked_object.to_dict(), file) | ||
|
||
|
||
def test_full_correction(): | ||
# 1. Define dummy cost and selection functions | ||
def dummy_cost_function(candidate: TrackedObject, switcher: TrackedObject): # noqa: ARG001 | ||
return 0 | ||
|
||
def dummy_selection_function(candidate: TrackedObject, switcher: TrackedObject): # noqa: ARG001 | ||
return 1 | ||
|
||
# 2. Initialize ReidProcessor | ||
reid_processor = ReidProcessor( | ||
filter_confidence_threshold=0.1, | ||
filter_time_threshold=1, | ||
max_frames_to_rematch=100, | ||
max_attempt_to_match=5, | ||
cost_function=dummy_cost_function, | ||
selection_function=dummy_selection_function, | ||
save_to_txt=True, | ||
file_path=OUTPUT_FOLDER / OUTPUT_FILE, | ||
) | ||
|
||
# 3. Reset output folder, load data and group by frame_id | ||
|
||
reset_output_folder(output_folder=OUTPUT_FOLDER, create_folder=True) | ||
|
||
tracker_output = np.loadtxt(INPUT_FOLDER / INPUT_FILE) | ||
frame_ids, indexes = np.unique(tracker_output[:, 0], return_index=True) | ||
frame_tracker_outputs = np.split(tracker_output[:, 1:], indexes)[1:] | ||
|
||
# 4. perform reid process and save corrected objects | ||
|
||
for frame_id, frame_tracker_output in zip(frame_ids, frame_tracker_outputs): | ||
reid_processor.update(frame_id=frame_id, tracker_output=frame_tracker_output) | ||
|
||
save_tracked_objects(reid_processor=reid_processor, file_path_folder=OUTPUT_FOLDER) | ||
|
||
# 5. Perform evaluation and delete files if test succeed | ||
|
||
for expected_output_file in EXPECTED_OUTPUT_FILES: | ||
compare_files( | ||
EXPECTED_OUTPUT_FOLDER / expected_output_file, OUTPUT_FOLDER / expected_output_file | ||
) | ||
|
||
reset_output_folder(output_folder=OUTPUT_FOLDER, create_folder=False) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import filecmp | ||
import json | ||
import shutil | ||
from pathlib import Path | ||
|
||
|
||
def reset_output_folder(output_folder: Path, create_folder=True): | ||
""" | ||
Each test should start and end by deleting the output folder | ||
""" | ||
if output_folder.exists(): | ||
shutil.rmtree(output_folder, ignore_errors=True) | ||
|
||
if create_folder: | ||
output_folder.mkdir(parents=True, exist_ok=True) | ||
|
||
|
||
def _compare_txt_files(file1: Path, file2: Path): | ||
"""Compare two txt files line by line""" | ||
with file1.open("r") as f1: | ||
with file2.open("r") as f2: | ||
for line1, line2 in zip(f1, f2): | ||
assert line1.strip() == line2.strip(), (line1, line2) | ||
|
||
|
||
def _compare_json_files(file1: Path, file2: Path): | ||
with file1.open("r") as f1: | ||
json1 = json.load(f1) | ||
|
||
with file2.open("r") as f2: | ||
json2 = json.load(f2) | ||
|
||
# converting to string with same key order | ||
json1, json2 = json.dumps(json1, sort_keys=True), json.dumps(json2, sort_keys=True) | ||
assert json1 == json2, (json1, json2) | ||
|
||
|
||
def compare_files(file1: Path, file2: Path): | ||
""" | ||
Compare two files, regardless of their extension | ||
""" | ||
assert file1.exists(), f"file1 {file1} does not exist" | ||
assert file2.exists(), f"File {file2} does not exist" | ||
|
||
extension1 = file1.suffix | ||
extension2 = file2.suffix | ||
|
||
if extension1 != extension2: | ||
raise ValueError( | ||
f"Cannot compare {file1} and {file2} because they have different extensions" | ||
) | ||
|
||
if extension1 == ".json": | ||
return _compare_json_files(file1, file2) | ||
|
||
elif extension1 == ".txt": # we don't use filecmp to compare line by line | ||
return _compare_txt_files(file1, file2) | ||
|
||
else: | ||
assert filecmp.cmp(file1, file2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters