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

Update dataframe creation #96

Open
wants to merge 115 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
2512781
Rewrite dataframe creation
zhong-al Jul 22, 2024
8703ace
Test install
zhong-al Oct 11, 2024
26ecd62
Start tracks extractor test
zhong-al Oct 11, 2024
309c15d
Add data for tracks extractor test
zhong-al Oct 11, 2024
1ae921a
Check test on any push
zhong-al Oct 11, 2024
6da7f18
Try to fix torch missing
zhong-al Oct 11, 2024
9ac0c76
Try to fix torch missing
zhong-al Oct 11, 2024
c38275f
Fix hatchling missing
zhong-al Oct 12, 2024
6f66453
Add miniscene2behavior test
zhong-al Oct 12, 2024
af28c4b
Update tests
zhong-al Oct 14, 2024
f9dd66b
Start test for cvat2ultralytics and detector2cvat
zhong-al Oct 14, 2024
98b2b76
Fix cvat2ultralytics, move detection test files
zhong-al Oct 14, 2024
3407f48
Add miniscene2behavior test
zhong-al Oct 14, 2024
4ee974d
Ignore tool outputs
zhong-al Oct 14, 2024
15d1316
Adjust path
zhong-al Oct 14, 2024
6aa96f2
Update path
zhong-al Oct 14, 2024
d313209
Add player test and fix player globals
zhong-al Oct 14, 2024
a3347c5
Add cvat2slowfast test
zhong-al Oct 14, 2024
08b3242
Type annotate miniscene2behavior
zhong-al Oct 16, 2024
d747a3e
Type annotate parse_args
zhong-al Oct 16, 2024
dc9d6ae
Annotate tracks extractor
zhong-al Oct 16, 2024
952cc40
Fix miniscene2behavior
zhong-al Oct 16, 2024
b78b85f
Type annotate cvat2slowfast
zhong-al Oct 16, 2024
1505841
Type annotate cvat2ultralytics
zhong-al Oct 16, 2024
5ca8c98
Type annotate detector2cvat
zhong-al Oct 16, 2024
a90608b
Type annotate player
zhong-al Oct 16, 2024
e53c6d8
Make imshow optional, update docs
zhong-al Oct 16, 2024
9405859
Find frames per track
zhong-al Oct 16, 2024
d61b06a
Account for track extraction
zhong-al Oct 16, 2024
a144cb1
Add check to miniscene2behavior
zhong-al Oct 17, 2024
2787bad
Print more debug
zhong-al Oct 17, 2024
488e0fe
Use index because track frames can be noncontiguous
zhong-al Oct 18, 2024
7076bb3
Comment out tests
zhong-al Oct 18, 2024
912d547
Add mocked tests
zhong-al Oct 18, 2024
06d01ee
Patch detector2cvat
zhong-al Oct 18, 2024
331ecc7
Patch player & add sample data
zhong-al Oct 18, 2024
1fe22af
Rename run functions
zhong-al Oct 18, 2024
869b17b
Test tracks extractor parser
zhong-al Oct 18, 2024
a25f893
Mock getTrackbarPos
zhong-al Oct 18, 2024
8b4c2c7
Test cvat2slowfast parser
zhong-al Oct 19, 2024
8308c60
Test cvat2ultralytics parsing
zhong-al Oct 19, 2024
c011e0e
Test detector2cvat parsing
zhong-al Oct 19, 2024
0348bd6
Test miniscene2behavior parsing
zhong-al Oct 19, 2024
ac12359
Test player parsing
zhong-al Oct 19, 2024
e761672
Update cvat2slowfast
zhong-al Oct 25, 2024
5a1478e
Update cvat2ultralytics
zhong-al Oct 25, 2024
656c40d
Update detector2cvat
zhong-al Oct 25, 2024
b55f1dc
Fix test
zhong-al Oct 25, 2024
520e1cc
Update miniscene2behavior
zhong-al Oct 25, 2024
316ab59
Update player
zhong-al Oct 25, 2024
9cfcfc0
Update tracks_extractor
zhong-al Oct 25, 2024
7606e6d
Extract model download + unzip
zhong-al Oct 25, 2024
da5b0b8
Fix spacing + tqdm bar
zhong-al Oct 25, 2024
b191425
Fix download
zhong-al Oct 25, 2024
7584e81
Download model at setup
zhong-al Oct 28, 2024
9ee7499
Add label2index json
zhong-al Oct 30, 2024
f2fdd85
Start testing detector2cvat
zhong-al Oct 31, 2024
b4d52a2
Mock yolo successfully
zhong-al Oct 31, 2024
72eb862
Update detector2cvat save directory
zhong-al Nov 2, 2024
87452bb
Check mocked output
zhong-al Nov 2, 2024
fdba887
Merge branch 'master' into enhancement/testing
zhong-al Nov 13, 2024
df3b7ba
Apply suggestions from code review
zhong-al Nov 13, 2024
3014480
Check tracks extractor output
zhong-al Nov 13, 2024
a0b6c8d
Add todos
zhong-al Nov 13, 2024
50feea9
Delete tracks_extractor output
zhong-al Nov 13, 2024
6a91fc2
Add clean up + runs
zhong-al Nov 13, 2024
da97183
Merge branch 'master' into enhancement/testing
zhong-al Nov 13, 2024
37dd750
Update arg parsing checks
zhong-al Nov 13, 2024
90481e5
Merge branch 'enhancement/testing' into enhancement/testing2
zhong-al Nov 14, 2024
47e453a
Check cvat2slowfast output
zhong-al Nov 21, 2024
508e86d
Remove detection example
zhong-al Nov 27, 2024
ff26f95
Update miniscene test to download data
zhong-al Nov 27, 2024
0d5587f
Add secret to workflow
zhong-al Nov 27, 2024
f212fc5
Update workflow
zhong-al Nov 29, 2024
cff01ab
Delete behavior example
zhong-al Nov 29, 2024
f41a476
Update cvat2slowfast
zhong-al Nov 29, 2024
b6aec69
Update comments
zhong-al Nov 29, 2024
e0c6d1d
Update test dir
zhong-al Nov 29, 2024
30c0b60
Update download call
zhong-al Nov 29, 2024
8f8c63f
Update detector2cvat
zhong-al Nov 29, 2024
910ebdf
Group downloads
zhong-al Nov 29, 2024
87bb223
Del unused consts
zhong-al Nov 29, 2024
00ffd73
Update player
zhong-al Nov 29, 2024
957b580
Update cvat2ultralytics
zhong-al Nov 29, 2024
def5702
Merge branch 'enhancement/testing' into enhancement/testing2
zhong-al Dec 4, 2024
57a1eb3
Fix syntax error
zhong-al Dec 4, 2024
2164d3b
Update folder path
zhong-al Dec 4, 2024
d36cc85
Check cvat2slowfast annotation
zhong-al Dec 4, 2024
7971085
Minor cleanup
zhong-al Dec 4, 2024
bfa7138
Minor update
zhong-al Dec 4, 2024
3005b4c
Check detector2cvat output
zhong-al Dec 4, 2024
4e7147b
Add param for cvat2slowfast image output
zhong-al Dec 4, 2024
8118539
Check tracks
zhong-al Dec 6, 2024
19a0145
Remove imshow
zhong-al Dec 6, 2024
82062dc
Check output video
zhong-al Dec 6, 2024
3baa1cd
Re-enable cleanup
zhong-al Dec 6, 2024
8c72518
Check player output
zhong-al Dec 6, 2024
dedc9aa
Check mocked output
zhong-al Dec 6, 2024
e738244
Merge branch 'bug/miniscene2behavior' into enhancement/testing2
zhong-al Dec 6, 2024
c47508b
Delete duplicate import
zhong-al Dec 6, 2024
8327c0f
Fix mock annotation test
zhong-al Dec 6, 2024
ff3d72e
Re-add annotation run
zhong-al Dec 6, 2024
3f06fc9
Test with mocked yolov8 data
zhong-al Dec 10, 2024
b04cf51
Improve miniscene test cleanup
zhong-al Dec 10, 2024
12d3f6d
Check cvat2slowfast images
zhong-al Dec 10, 2024
4b54332
Add detector test data
zhong-al Dec 10, 2024
7e56588
Merge branch 'bug/slowfast_image' into enhancement/testing2
zhong-al Dec 10, 2024
49c2f7f
Update arg parse tests
zhong-al Dec 10, 2024
aaf079e
Merge branch 'master' into enhancement/testing2
zhong-al Dec 10, 2024
32d2055
Start ultralytics testing
zhong-al Dec 10, 2024
37dc678
Check image and label
zhong-al Dec 11, 2024
f56b4cd
Re-add tearDown
zhong-al Dec 11, 2024
e552c6c
Merge branch 'master' into charades
zhong-al Dec 14, 2024
b44ad9e
Fix merge
zhong-al Dec 14, 2024
8fe4de0
Merge branch 'enhancement/testing2' into charades
zhong-al Dec 14, 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,6 @@ player --folder path_to_folder [--save] [--imshow]


```
cvat2slowfast --miniscene path_to_mini_scenes --dataset dataset_name --classes path_to_classes_json [--old2new path_to_old2new_json]
cvat2slowfast --miniscene path_to_mini_scenes --dataset dataset_name --classes path_to_classes_json [--old2new path_to_old2new_json] [--no_images]
```

33 changes: 20 additions & 13 deletions src/kabr_tools/cvat2slowfast.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


def cvat2slowfast(path_to_mini_scenes: str, path_to_new_dataset: str,
label2number: dict, old2new: Optional[dict]) -> None:
label2number: dict, old2new: Optional[dict], no_images: bool) -> None:
"""
Convert CVAT annotations to the dataset in Charades format.

Expand All @@ -20,6 +20,7 @@ def cvat2slowfast(path_to_mini_scenes: str, path_to_new_dataset: str,
path_to_new_dataset - str. Path to the folder to output dataset files.
label2number - dict. Mapping of ethogram labels to integers.
old2new - dict [optional]. Mapping of old ethogram labels to new ethogram labels.
no_images - bool. Flag to stop image output.
"""
if not os.path.exists(path_to_new_dataset):
os.makedirs(path_to_new_dataset)
Expand All @@ -33,12 +34,13 @@ def cvat2slowfast(path_to_mini_scenes: str, path_to_new_dataset: str,
with open(f"{path_to_new_dataset}/annotation/classes.json", "w") as file:
json.dump(label2number, file)

headers = {"original_vido_id": [], "video_id": pd.Series(dtype="int"), "frame_id": pd.Series(dtype="int"),
"path": [], "labels": []}
headers = ["original_vido_id", "video_id", "frame_id", "path", "labels"]
charades_data = []

charades_df = pd.DataFrame(data=headers)
video_id = 1
folder_name = 1
flag = False
flag = not no_images

for i, folder in enumerate(natsorted(os.listdir(path_to_mini_scenes))):
if os.path.exists(f"{path_to_mini_scenes}/{folder}/actions"):
Expand Down Expand Up @@ -127,13 +129,11 @@ def cvat2slowfast(path_to_mini_scenes: str, path_to_new_dataset: str,
if flag:
cv2.imwrite(f"{output_folder}/{adjusted_index}.jpg", frame)

# TODO: Major slow down here. Add to a list rather than dataframe,
# and create dataframe at the end.
charades_df.loc[len(charades_df.index)] = [f"{folder_code}",
video_id,
adjusted_index,
f"{folder_code}/{adjusted_index}.jpg",
str(label2number[behavior])]
charades_data.append([f"{folder_code}",
video_id,
adjusted_index,
f"{folder_code}/{adjusted_index}.jpg",
str(label2number[behavior])])

adjusted_index += 1

Expand All @@ -145,9 +145,11 @@ def cvat2slowfast(path_to_mini_scenes: str, path_to_new_dataset: str,
video_id += 1

if video_id % 10 == 0:
charades_df = pd.DataFrame(charades_data, columns=headers)
charades_df.to_csv(
f"{path_to_new_dataset}/annotation/data.csv", sep=" ", index=False)

charades_df = pd.DataFrame(charades_data, columns=headers)
charades_df.to_csv(
f"{path_to_new_dataset}/annotation/data.csv", sep=" ", index=False)

Expand Down Expand Up @@ -178,6 +180,11 @@ def parse_args() -> argparse.Namespace:
help="path to old to new ethogram labels json",
required=False
)
local_parser.add_argument(
"--no_images",
action="store_true",
help="flag to stop image output"
)
return local_parser.parse_args()


Expand All @@ -194,8 +201,8 @@ def main() -> None:
else:
old2new = None

cvat2slowfast(args.miniscene, args.dataset, label2number, old2new)
cvat2slowfast(args.miniscene, args.dataset, label2number, old2new, args.no_images)


if __name__ == "__main__":
main()
main()
29 changes: 19 additions & 10 deletions src/kabr_tools/miniscene2behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ def get_input_clip(cap: cv2.VideoCapture, cfg: CfgNode, keyframe_idx: int) -> li
# https://github.com/facebookresearch/SlowFast/blob/bac7b672f40d44166a84e8c51d1a5ba367ace816/slowfast/visualization/ava_demo_precomputed_boxes.py
seq_length = cfg.DATA.NUM_FRAMES * cfg.DATA.SAMPLING_RATE
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
assert keyframe_idx < total_frames, f"keyframe_idx: {keyframe_idx}" \
f" >= total_frames: {total_frames}"
seq = get_sequence(
keyframe_idx,
seq_length // 2,
cfg.DATA.SAMPLING_RATE,
total_frames,
)

clip = []
for frame_idx in seq:
cap.set(cv2.CAP_PROP_POS_FRAMES, frame_idx)
Expand Down Expand Up @@ -124,29 +127,34 @@ def annotate_miniscene(cfg: CfgNode, model: torch.nn.Module,

# find all tracks
tracks = []
frames = {}
for track in root.iterfind("track"):
track_id = track.attrib["id"]
tracks.append(track_id)
frames[track_id] = []

# find all frames
# TODO: rewrite - some tracks may have different frames
assert len(tracks) > 0, "No tracks found in track file"
frames = []
for box in track.iterfind("box"):
frames.append(int(box.attrib["frame"]))
# find all frames
for box in track.iterfind("box"):
frames[track_id].append(int(box.attrib["frame"]))

# run model on miniscene
for track in tracks:
video_file = f"{miniscene_path}/{track}.mp4"
cap = cv2.VideoCapture(video_file)
for frame in tqdm(frames, desc=f"{track} frames"):
inputs = get_input_clip(cap, cfg, frame)
index = 0
for frame in tqdm(frames[track], desc=f"{track} frames"):
try:
inputs = get_input_clip(cap, cfg, index)
except AssertionError as e:
print(e)
break
index += 1

if cfg.NUM_GPUS:
# transfer the data to the current GPU device.
if isinstance(inputs, (list,)):
for i in range(len(inputs)):
inputs[i] = inputs[i].cuda(non_blocking=True)
for i, input_clip in enumerate(inputs):
inputs[i] = input_clip.cuda(non_blocking=True)
else:
inputs = inputs.cuda(non_blocking=True)

Expand All @@ -163,6 +171,7 @@ def annotate_miniscene(cfg: CfgNode, model: torch.nn.Module,
if frame % 20 == 0:
pd.DataFrame(label_data).to_csv(
output_path, sep=" ", index=False)
cap.release()
pd.DataFrame(label_data).to_csv(output_path, sep=" ", index=False)


Expand Down
49 changes: 49 additions & 0 deletions tests/examples/DETECTOR1/DJI_tracks.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version='1.0' encoding='UTF-8'?>
<annotations>
<track id="0" label="Grevy" source="manual">
<box frame="0" outside="0" occluded="0" keyframe="1" xtl="2011.00" ytl="1883.00" xbr="2133.00" ybr="1978.00" z_order="0"/>
<box frame="1" outside="0" occluded="0" keyframe="0" xtl="2011.00" ytl="1883.00" xbr="2133.00" ybr="1978.00" z_order="0"/>
<box frame="2" outside="0" occluded="0" keyframe="0" xtl="2011.00" ytl="1883.00" xbr="2133.00" ybr="1978.00" z_order="0"/>
<box frame="3" outside="0" occluded="0" keyframe="0" xtl="2011.00" ytl="1883.00" xbr="2133.00" ybr="1978.00" z_order="0"/>
<box frame="4" outside="0" occluded="0" keyframe="0" xtl="2011.00" ytl="1883.00" xbr="2134.00" ybr="1978.00" z_order="0"/>
<box frame="5" outside="0" occluded="0" keyframe="0" xtl="2011.00" ytl="1883.00" xbr="2134.00" ybr="1978.00" z_order="0"/>
<box frame="6" outside="0" occluded="0" keyframe="0" xtl="2011.00" ytl="1883.00" xbr="2134.00" ybr="1978.00" z_order="0"/>
<box frame="7" outside="0" occluded="0" keyframe="0" xtl="2012.00" ytl="1883.00" xbr="2134.00" ybr="1978.00" z_order="0"/>
<box frame="8" outside="0" occluded="0" keyframe="0" xtl="2012.00" ytl="1883.00" xbr="2134.00" ybr="1978.00" z_order="0"/>
<box frame="9" outside="0" occluded="0" keyframe="0" xtl="2012.00" ytl="1883.00" xbr="2134.00" ybr="1978.00" z_order="0"/>
<box frame="10" outside="0" occluded="0" keyframe="0" xtl="2012.00" ytl="1882.00" xbr="2134.00" ybr="1978.00" z_order="0"/>
<box frame="21" outside="0" occluded="0" keyframe="0" xtl="2012.00" ytl="1882.00" xbr="2134.00" ybr="1978.00" z_order="0"/>
<box frame="22" outside="0" occluded="0" keyframe="0" xtl="2012.00" ytl="1882.00" xbr="2134.00" ybr="1978.00" z_order="0"/>
<box frame="23" outside="0" occluded="0" keyframe="0" xtl="2012.00" ytl="1882.00" xbr="2135.00" ybr="1978.00" z_order="0"/>
<box frame="24" outside="0" occluded="0" keyframe="0" xtl="2012.00" ytl="1882.00" xbr="2135.00" ybr="1977.00" z_order="0"/>
<box frame="25" outside="0" occluded="0" keyframe="0" xtl="2012.00" ytl="1882.00" xbr="2135.00" ybr="1977.00" z_order="0"/>
<box frame="26" outside="0" occluded="0" keyframe="0" xtl="2013.00" ytl="1882.00" xbr="2135.00" ybr="1977.00" z_order="0"/>
<box frame="27" outside="0" occluded="0" keyframe="0" xtl="2013.00" ytl="1882.00" xbr="2135.00" ybr="1977.00" z_order="0"/>
<box frame="28" outside="0" occluded="0" keyframe="0" xtl="2013.00" ytl="1882.00" xbr="2135.00" ybr="1977.00" z_order="0"/>
<box frame="29" outside="0" occluded="0" keyframe="0" xtl="2013.00" ytl="1882.00" xbr="2135.00" ybr="1977.00" z_order="0"/>
<box frame="30" outside="0" occluded="0" keyframe="0" xtl="2013.00" ytl="1882.00" xbr="2135.00" ybr="1977.00" z_order="0"/>
</track>
<track id="1" label="Grevy" source="manual">
<box frame="0" outside="0" occluded="0" keyframe="1" xtl="2513.00" ytl="1921.00" xbr="2615.00" ybr="1991.00" z_order="0"/>
<box frame="1" outside="0" occluded="0" keyframe="0" xtl="2513.00" ytl="1921.00" xbr="2615.00" ybr="1991.00" z_order="0"/>
<box frame="2" outside="0" occluded="0" keyframe="0" xtl="2512.00" ytl="1921.00" xbr="2614.00" ybr="1991.00" z_order="0"/>
<box frame="3" outside="0" occluded="0" keyframe="0" xtl="2512.00" ytl="1921.00" xbr="2613.00" ybr="1991.00" z_order="0"/>
<box frame="4" outside="0" occluded="0" keyframe="0" xtl="2511.00" ytl="1921.00" xbr="2613.00" ybr="1991.00" z_order="0"/>
<box frame="5" outside="0" occluded="0" keyframe="0" xtl="2510.00" ytl="1921.00" xbr="2612.00" ybr="1991.00" z_order="0"/>
<box frame="6" outside="0" occluded="0" keyframe="0" xtl="2510.00" ytl="1921.00" xbr="2612.00" ybr="1991.00" z_order="0"/>
<box frame="7" outside="0" occluded="0" keyframe="0" xtl="2509.00" ytl="1921.00" xbr="2611.00" ybr="1991.00" z_order="0"/>
<box frame="8" outside="0" occluded="0" keyframe="0" xtl="2508.00" ytl="1921.00" xbr="2610.00" ybr="1991.00" z_order="0"/>
<box frame="9" outside="0" occluded="0" keyframe="0" xtl="2508.00" ytl="1921.00" xbr="2610.00" ybr="1991.00" z_order="0"/>
<box frame="10" outside="0" occluded="0" keyframe="0" xtl="2507.00" ytl="1921.00" xbr="2609.00" ybr="1991.00" z_order="0"/>
<box frame="11" outside="0" occluded="0" keyframe="0" xtl="2507.00" ytl="1921.00" xbr="2608.00" ybr="1991.00" z_order="0"/>
<box frame="12" outside="0" occluded="0" keyframe="0" xtl="2506.00" ytl="1921.00" xbr="2608.00" ybr="1991.00" z_order="0"/>
<box frame="13" outside="0" occluded="0" keyframe="0" xtl="2505.00" ytl="1921.00" xbr="2607.00" ybr="1991.00" z_order="0"/>
<box frame="14" outside="0" occluded="0" keyframe="0" xtl="2505.00" ytl="1921.00" xbr="2607.00" ybr="1991.00" z_order="0"/>
<box frame="15" outside="0" occluded="0" keyframe="0" xtl="2504.00" ytl="1920.00" xbr="2606.00" ybr="1991.00" z_order="0"/>
<box frame="16" outside="0" occluded="0" keyframe="0" xtl="2503.00" ytl="1920.00" xbr="2605.00" ybr="1991.00" z_order="0"/>
<box frame="17" outside="0" occluded="0" keyframe="0" xtl="2503.00" ytl="1920.00" xbr="2605.00" ybr="1991.00" z_order="0"/>
<box frame="18" outside="0" occluded="0" keyframe="0" xtl="2502.00" ytl="1920.00" xbr="2604.00" ybr="1991.00" z_order="0"/>
<box frame="19" outside="0" occluded="0" keyframe="0" xtl="2502.00" ytl="1920.00" xbr="2603.00" ybr="1990.00" z_order="0"/>
<box frame="20" outside="0" occluded="0" keyframe="0" xtl="2501.00" ytl="1920.00" xbr="2603.00" ybr="1990.00" z_order="0"/>
</track>
</annotations>
58 changes: 49 additions & 9 deletions tests/test_cvat2slowfast.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import unittest
import sys
import os
import json
import pandas as pd
import cv2
from kabr_tools import cvat2slowfast
from tests.test_tracks_extractor import (
scene_width,
scene_height
)
from tests.utils import (
get_behavior,
del_dir,
del_file
del_file,
dir_exists,
file_exists,
get_behavior
)


Expand Down Expand Up @@ -50,6 +59,40 @@ def test_run(self):
"--classes", self.classes]
run()

# check output dirs
self.assertTrue(dir_exists(self.dataset))
self.assertTrue(dir_exists(f"{self.dataset}/annotation"))
self.assertTrue(dir_exists(f"{self.dataset}/dataset/image"))
self.assertTrue(file_exists(f"{self.dataset}/annotation/classes.json"))
self.assertTrue(file_exists(f"{self.dataset}/annotation/data.csv"))

# check classes.json
with open(f"{self.dataset}/annotation/classes.json", "r", encoding="utf-8") as f:
classes = json.load(f)
with open(self.classes, "r", encoding="utf-8") as f:
ethogram = json.load(f)
self.assertEqual(classes, ethogram)

# check data.csv
with open(f"{self.dataset}/annotation/data.csv", "r", encoding="utf-8") as f:
df = pd.read_csv(f, sep=" ")

video_id = 1
for i, row in df.iterrows():
self.assertEqual(row["original_vido_id"], f"Z{video_id:04d}")
self.assertEqual(row["video_id"], video_id)
self.assertEqual(row["frame_id"], i+1)
self.assertEqual(row["path"], f"Z{video_id:04d}/{i+1}.jpg")
self.assertEqual(row["labels"], 1)
self.assertEqual(i, 90)

# check dataset
for i in range(1, 92):
data_im = f"{self.dataset}/dataset/image/Z{video_id:04d}/{i}.jpg"
self.assertTrue(file_exists(data_im))
data_im = cv2.imread(data_im)
self.assertEqual(data_im.shape, (scene_height, scene_width, 3))

def test_parse_arg_min(self):
# parse arguments
sys.argv = [self.tool,
Expand All @@ -65,24 +108,21 @@ def test_parse_arg_min(self):

# check default argument values
self.assertEqual(args.old2new, None)

# run cvat2slowfast
run()
self.assertTrue(not args.no_images)

def test_parse_arg_full(self):
# parse arguments
sys.argv = ["cvat2slowfast.py",
"--miniscene", self.miniscene,
"--dataset", self.dataset,
"--classes", self.classes,
"--old2new", self.old2new]
"--old2new", self.old2new,
"--no_images"]
args = cvat2slowfast.parse_args()

# check parsed argument values
self.assertEqual(args.miniscene, self.miniscene)
self.assertEqual(args.dataset, self.dataset)
self.assertEqual(args.classes, self.classes)
self.assertEqual(args.old2new, self.old2new)

# run cvat2slowfast
run()
self.assertTrue(args.no_images)
Loading
Loading