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 yolo model param #94

Open
wants to merge 5 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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ statistics_all.png
statistics_g.png
statistics_zg.png
statistics_zp.png
yolov8x.pt
*.pt


*.mp4
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ You may use [YOLO](https://docs.ultralytics.com/) to automatically perform detec
Detect objects with Ultralytics YOLO detections, apply SORT tracking and convert tracks to CVAT format.

```
detector2cvat --video path_to_videos --save path_to_save [--imshow]
detector2cvat --video path_to_videos --save path_to_save [--yolo yolo_model] [--imshow]
```


Expand Down
13 changes: 10 additions & 3 deletions src/kabr_tools/detector2cvat.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
from kabr_tools.utils.draw import Draw


def detector2cvat(path_to_videos: str, path_to_save: str, show: bool) -> None:
def detector2cvat(path_to_videos: str, path_to_save: str, model: str, show: bool) -> None:
"""
Detect objects with Ultralytics YOLO detections, apply SORT tracking and convert tracks to CVAT format.

Parameters:
path_to_videos - str. Path to the folder containing videos.
path_to_save - str. Path to the folder to save output xml & mp4 files.
model - str. YOLO model to use with detections.
show - bool. Flag to display detector's visualization.
"""
videos = []
Expand All @@ -29,7 +30,7 @@ def detector2cvat(path_to_videos: str, path_to_save: str, show: bool) -> None:

videos.append(f"{root}/{file}")

yolo = YOLOv8(weights="yolov8x.pt", imgsz=3840, conf=0.5)
yolo = YOLOv8(weights=model, imgsz=3840, conf=0.5)

for i, video in enumerate(videos):
try:
Expand Down Expand Up @@ -120,6 +121,12 @@ def parse_args() -> argparse.Namespace:
help="path to save output xml & mp4 files",
required=True
)
local_parser.add_argument(
"--yolo",
type=str,
default="yolov8x.pt",
help="yolo model to use with detections"
)
local_parser.add_argument(
"--imshow",
action="store_true",
Expand All @@ -130,7 +137,7 @@ def parse_args() -> argparse.Namespace:

def main() -> None:
args = parse_args()
detector2cvat(args.video, args.save, args.imshow)
detector2cvat(args.video, args.save, args.yolo, args.imshow)


if __name__ == "__main__":
Expand Down
15 changes: 13 additions & 2 deletions tests/test_detector2cvat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
import sys
import os
from unittest.mock import patch
from kabr_tools import detector2cvat
from tests.utils import (
del_dir,
Expand Down Expand Up @@ -33,6 +34,7 @@ def setUp(self):
self.tool = "detector2cvat.py"
self.video = TestDetector2Cvat.dir
self.save = "tests/detector2cvat"
self.yolo = "yolov5s.pt"

def tearDown(self):
# delete outputs
Expand All @@ -55,17 +57,26 @@ def test_parse_arg_min(self):
# check parsed argument values
self.assertEqual(args.video, self.video)
self.assertEqual(args.save, self.save)
self.assertEqual(args.imshow, False)

def test_parse_arg_full(self):
# check default argument values
self.assertEqual(args.yolo, "yolov8x.pt")
self.assertEqual(args.imshow, False)

@patch('kabr_tools.detector2cvat.cv2.imshow')
def test_parse_arg_full(self, imshow):
# parse arguments
sys.argv = [self.tool,
"--video", self.video,
"--save", self.save,
"--yolo", self.yolo,
"--imshow"]
args = detector2cvat.parse_args()

# check parsed argument values
self.assertEqual(args.video, self.video)
self.assertEqual(args.save, self.save)
self.assertEqual(args.yolo, self.yolo)
self.assertEqual(args.imshow, True)

# run
run()
Loading