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

Add param for cvat2slowfast image output #84

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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]
```

12 changes: 9 additions & 3 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 @@ -38,7 +39,7 @@ def cvat2slowfast(path_to_mini_scenes: str, path_to_new_dataset: str,
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 @@ -178,6 +179,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,7 +200,7 @@ 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__":
Expand Down
5 changes: 4 additions & 1 deletion tests/test_cvat2slowfast.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def test_parse_arg_min(self):

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

# run cvat2slowfast
run()
Expand All @@ -75,14 +76,16 @@ def test_parse_arg_full(self):
"--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)
self.assertTrue(args.no_images)

# run cvat2slowfast
run()
Loading