Skip to content
Merged
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
3 changes: 1 addition & 2 deletions .github/workflows/publish_image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive

- name: Get tools-cli version
id: commit
Expand All @@ -34,6 +32,7 @@ jobs:

- name: Publish latest
run: |
git submodule update --init --recursive
docker build -t $NAME:latest .
docker tag $NAME:latest ghcr.io/$NAME:latest
docker push ghcr.io/$NAME:latest
Expand Down
17 changes: 17 additions & 0 deletions tests/test_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ def test_yolov5n_automatic_version_detection():
_remove_file("tests/yolov5n.pt")


def test_yolov5nu_automatic_version_detection():
"""Test the YOLOv5nu autodetection of the model version."""
_download_file(
"https://github.com/ultralytics/assets/releases/download/v8.3.0/yolov5nu.pt"
)
assert detect_version("tests/yolov5nu.pt") == "yolov5u"
_remove_file("tests/yolov5nu.pt")


def test_yolov5nu_model_conversion():
"""Test the conversion of an YOLOv5nu model."""
_download_file(
"https://github.com/ultralytics/assets/releases/download/v8.3.0/yolov5nu.pt"
)
_test_model_conversion(YoloV8Exporter, "tests/yolov5nu.pt", (64, 64), True)


def test_yolov6nr1_automatic_version_detection():
"""Test the YOLOv6nr1 autodetection of the model version."""
_download_file(
Expand Down
16 changes: 14 additions & 2 deletions tools/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from tools.utils import (
GOLD_YOLO_CONVERSION,
YOLOV5_CONVERSION,
YOLOV5U_CONVERSION,
YOLOV6R1_CONVERSION,
YOLOV6R3_CONVERSION,
YOLOV6R4_CONVERSION,
Expand All @@ -34,6 +35,7 @@
YOLO_VERSIONS = [
GOLD_YOLO_CONVERSION,
YOLOV5_CONVERSION,
YOLOV5U_CONVERSION,
YOLOV6R1_CONVERSION,
YOLOV6R3_CONVERSION,
YOLOV6R4_CONVERSION,
Expand Down Expand Up @@ -111,7 +113,12 @@ def convert(

if version is None:
version = detect_version(str(model_path))
logger.info(f"Detected version: {version}")
version_note = (
"(This is an anchor-free version of the YOLOv5 model obtained by a more recent version of Ultralytics. Therefore, YOLOv8 conversion will be used instead of the standard YOLOv5 conversion)"
if version == YOLOV5U_CONVERSION
else ""
)
logger.info(f"Detected version: {version} {version_note}")

try:
# Create exporter
Expand Down Expand Up @@ -140,7 +147,12 @@ def convert(
from tools.yolov7.yolov7_exporter import YoloV7Exporter

exporter = YoloV7Exporter(str(model_path), config.imgsz, config.use_rvc2)
elif version in [YOLOV8_CONVERSION, YOLOV9_CONVERSION, YOLOV11_CONVERSION]:
elif version in [
YOLOV5U_CONVERSION,
YOLOV8_CONVERSION,
YOLOV9_CONVERSION,
YOLOV11_CONVERSION,
]:
from tools.yolo.yolov8_exporter import YoloV8Exporter

exporter = YoloV8Exporter(str(model_path), config.imgsz, config.use_rvc2)
Expand Down
2 changes: 2 additions & 0 deletions tools/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
GOLD_YOLO_CONVERSION,
UNRECOGNIZED,
YOLOV5_CONVERSION,
YOLOV5U_CONVERSION,
YOLOV6R1_CONVERSION,
YOLOV6R3_CONVERSION,
YOLOV6R4_CONVERSION,
Expand All @@ -27,6 +28,7 @@
"Config",
"detect_version",
"YOLOV5_CONVERSION",
"YOLOV5U_CONVERSION",
"YOLOV6R1_CONVERSION",
"YOLOV6R3_CONVERSION",
"YOLOV6R4_CONVERSION",
Expand Down
19 changes: 13 additions & 6 deletions tools/utils/version_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from os.path import exists, isdir, join

YOLOV5_CONVERSION = "yolov5"
YOLOV5U_CONVERSION = "yolov5u"
YOLOV6R1_CONVERSION = "yolov6r1"
YOLOV6R3_CONVERSION = "yolov6r3"
YOLOV6R4_CONVERSION = "yolov6r4"
Expand Down Expand Up @@ -53,7 +54,6 @@ def detect_version(path: str, debug: bool = False) -> str:
if debug:
print(data.decode(errors="replace"))
content = data.decode("latin1")

if "yolo11" in content:
return YOLOV11_CONVERSION
elif "yolov10" in content or "v10DetectLoss" in content:
Expand All @@ -63,9 +63,10 @@ def detect_version(path: str, debug: bool = False) -> str:
):
return YOLOV9_CONVERSION
elif (
"YOLOv5u" in content
or "YOLOv8" in content
or "yolov8" in content
"yolov8" in content
or (
"YOLOv8" in content and "yolov5" not in content
) # the second condition is to avoid yolov5u being detected as yolov8
or ("v8DetectionLoss" in content and "ultralytics" in content)
):
return YOLOV8_CONVERSION
Expand All @@ -79,9 +80,15 @@ def detect_version(path: str, debug: bool = False) -> str:
return YOLOV6R3_CONVERSION
elif "yolov7" in content:
return YOLOV7_CONVERSION
elif "yolov5u" in content or (
"yolov5" in content
and "ultralytics.nn.modules" in content
# the second condition checks if the new version of the Ultralytics package was used to build the model which signals the "u" variant
):
return YOLOV5U_CONVERSION
elif (
"SPPF" in content
or "yolov5" in content
"yolov5" in content
or "SPPF" in content
or (
"models.yolo.Detectr1" in content
and "models.common.SPPr" in content
Expand Down
Loading