Skip to content
Closed
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
1 change: 1 addition & 0 deletions tests/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
{"name": "yolo26x", "version": "v26"},
{"name": "yolo26n-seg", "version": "v26"},
{"name": "yolo26n-pose", "version": "v26"},
{"name": "yolo26n", "version": "v26_nms", "cli_version": "yolov26_nms"},
{"name": "yolov8n-cls", "version": "v8"},
{"name": "yolov8n-seg", "version": "v8"},
{"name": "yolov8n-pose", "version": "v8"},
Expand Down
9 changes: 8 additions & 1 deletion tests/test_end2end.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
@pytest.mark.parametrize(
"model",
TEST_MODELS,
ids=[model["name"] for model in TEST_MODELS],
ids=[
model.get("cli_version", model["name"])
if model.get("cli_version")
else model["name"]
for model in TEST_MODELS
],
)
def test_cli_conversion(model: dict, test_config: dict, subtests):
"""Tests the whole CLI conversion flow with no extra params specified."""
Expand Down Expand Up @@ -50,6 +55,8 @@ def test_cli_conversion(model: dict, test_config: dict, subtests):
pytest.skip("Weights not present and `download_weights` not set")

command = ["tools", model_path]
if model.get("cli_version"):
command += ["--version", model.get("cli_version")]
if model.get("size"): # edge case when stride=64 is needed
command += ["--imgsz", model.get("size")]

Expand Down
3 changes: 3 additions & 0 deletions tools/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
YOLOV11_CONVERSION,
YOLOV12_CONVERSION,
YOLOV26_CONVERSION,
YOLOV26_NMS_CONVERSION,
detect_version,
)

Expand All @@ -50,6 +51,7 @@
YOLOV11_CONVERSION,
YOLOV12_CONVERSION,
YOLOV26_CONVERSION,
YOLOV26_NMS_CONVERSION,
]


Expand Down Expand Up @@ -176,6 +178,7 @@ def convert(
YOLOV9_CONVERSION,
YOLOV11_CONVERSION,
YOLOV12_CONVERSION,
YOLOV26_NMS_CONVERSION,
]:
from tools.yolo.yolov8_exporter import YoloV8Exporter

Expand Down
23 changes: 15 additions & 8 deletions tools/modules/heads.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,17 @@ def __init__(self, old_detect, use_rvc2: bool):

self.use_rvc2 = use_rvc2

self.proj_conv = nn.Conv2d(old_detect.dfl.c1, 1, 1, bias=False).requires_grad_(
False
)
x = torch.arange(old_detect.dfl.c1, dtype=torch.float)
self.proj_conv.weight.data[:] = nn.Parameter(x.view(1, old_detect.dfl.c1, 1, 1))
# yolo26: dfl will be nn.Identity(), we set proj_conv = None and skip the DFL block in forward
if hasattr(old_detect.dfl, "c1"):
self.proj_conv = nn.Conv2d(
old_detect.dfl.c1, 1, 1, bias=False
).requires_grad_(False)
x = torch.arange(old_detect.dfl.c1, dtype=torch.float)
self.proj_conv.weight.data[:] = nn.Parameter(
x.view(1, old_detect.dfl.c1, 1, 1)
)
else:
self.proj_conv = None

def forward(self, x):
bs = x[0].shape[0] # batch size
Expand All @@ -382,9 +388,10 @@ def forward(self, x):

# ------------------------------
# DFL PART
box = box.view(bs, 4, self.reg_max, h * w).permute(0, 2, 1, 3)
box = self.proj_conv(F.softmax(box, dim=1))[:, 0]
box = box.reshape([bs, 4, h, w])
if self.proj_conv is not None:
box = box.view(bs, 4, self.reg_max, h * w).permute(0, 2, 1, 3)
box = self.proj_conv(F.softmax(box, dim=1))[:, 0]
box = box.reshape([bs, 4, h, w])
# ------------------------------

cls = self.cv3[i](x[i])
Expand Down
2 changes: 2 additions & 0 deletions tools/version_detection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
YOLOV11_CONVERSION,
YOLOV12_CONVERSION,
YOLOV26_CONVERSION,
YOLOV26_NMS_CONVERSION,
detect_version,
)

Expand All @@ -30,6 +31,7 @@
"YOLOV11_CONVERSION",
"YOLOV12_CONVERSION",
"YOLOV26_CONVERSION",
"YOLOV26_NMS_CONVERSION",
"GOLD_YOLO_CONVERSION",
"UNRECOGNIZED",
]
1 change: 1 addition & 0 deletions tools/version_detection/version_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
YOLOV11_CONVERSION = "yolov11"
YOLOV12_CONVERSION = "yolov12"
YOLOV26_CONVERSION = "yolov26"
YOLOV26_NMS_CONVERSION = "yolov26_nms"
GOLD_YOLO_CONVERSION = "goldyolo"
UNRECOGNIZED = "none"

Expand All @@ -33,7 +34,7 @@
"""
# Try tar first
if tarfile.is_tarfile(archive_path):
with tarfile.open(archive_path, "r:*") as tar:

Check failure on line 37 in tools/version_detection/version_detection.py

View workflow job for this annotation

GitHub Actions / semgrep/ci

Semgrep Issue

Possible path traversal through `tarfile.open($PATH).extractall()` if the source tar is controlled by an attacker
tar.extractall(path=extract_to)
return

Expand Down
9 changes: 8 additions & 1 deletion tools/yolo/yolov8_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,16 @@ def __init__(
def load_model(self):
# load the model
model, _ = load_checkpoint(
self.model_path, device="cpu", inplace=True, fuse=True
self.model_path, device="cpu", inplace=True, fuse=False
)

# for yolo26 end2end has to be disabled before fusing
# otherwise cv2/cv3 are removed in the fuse process
head = model.model[-1]
if getattr(head, "end2end", False):
head.end2end = False
model.fuse()

self.mode = -1
if isinstance(model.model[-1], (Segment)) or isinstance(
model.model[-1], (YOLOESegment)
Expand Down
Loading