From e99b778cc4f4e429103c36ab00bf7d5288225377 Mon Sep 17 00:00:00 2001 From: Mohammed Yasin <32206511+Y-T-G@users.noreply.github.com> Date: Sun, 26 Jan 2025 21:18:51 +0800 Subject: [PATCH] Fix TFLite error and OpenVINO int8 error at imgsz=32 (#18898) Signed-off-by: Glenn Jocher Co-authored-by: Glenn Jocher Co-authored-by: UltralyticsAssistant --- docs/en/guides/azureml-quickstart.md | 4 ++-- docs/mkdocs_github_authors.yaml | 3 +++ tests/test_exports.py | 2 +- ultralytics/engine/exporter.py | 16 ++++++++++++++-- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/docs/en/guides/azureml-quickstart.md b/docs/en/guides/azureml-quickstart.md index b472e5fb..d13f9812 100644 --- a/docs/en/guides/azureml-quickstart.md +++ b/docs/en/guides/azureml-quickstart.md @@ -47,7 +47,7 @@ Start your compute and open a Terminal: ### Create virtualenv Create your conda virtualenv with your favorite python version and install pip in it: -Python 3.13.1 is having some issues with some dependecies in AzureML. +Python 3.13.1 is having some issues with some dependencies in AzureML. ```bash conda create --name yolo11env -y python=3.12 @@ -90,7 +90,7 @@ Open the compute Terminal. Open Terminal

-From your compute terminal, you need to create a new ipykernel (with a specific python version - because Python 3.13.1 is having some issues with some dependecies in AzureML) that will be used by your notebook to manage your dependencies: +From your compute terminal, you need to create a new ipykernel (with a specific python version - because Python 3.13.1 is having some issues with some dependencies in AzureML) that will be used by your notebook to manage your dependencies: ```bash conda create --name yolo11env -y python=3.12 diff --git a/docs/mkdocs_github_authors.yaml b/docs/mkdocs_github_authors.yaml index 8f6b9bf4..4d854b1d 100644 --- a/docs/mkdocs_github_authors.yaml +++ b/docs/mkdocs_github_authors.yaml @@ -61,6 +61,9 @@ 48149018+zhixuwei@users.noreply.github.com: avatar: https://avatars.githubusercontent.com/u/48149018?v=4 username: zhixuwei +49172033+Lucashygi@users.noreply.github.com: + avatar: https://avatars.githubusercontent.com/u/49172033?v=4 + username: Lucashygi 49699333+dependabot[bot]@users.noreply.github.com: avatar: https://avatars.githubusercontent.com/u/27347476?v=4 username: dependabot diff --git a/tests/test_exports.py b/tests/test_exports.py index 3c96f7fe..0faba6d4 100644 --- a/tests/test_exports.py +++ b/tests/test_exports.py @@ -81,7 +81,7 @@ def test_export_openvino_matrix(task, dynamic, int8, half, batch, nms): for task, dynamic, int8, half, batch, simplify, nms in product( TASKS, [True, False], [False], [False], [1, 2], [True, False], [True, False] ) - if not ((int8 and half) or (task == "classify" and nms)) + if not ((int8 and half) or (task == "classify" and nms) or (task == "obb" and nms and not TORCH_1_13)) ], ) def test_export_onnx_matrix(task, dynamic, int8, half, batch, simplify, nms): diff --git a/ultralytics/engine/exporter.py b/ultralytics/engine/exporter.py index 90807106..94cb5af0 100644 --- a/ultralytics/engine/exporter.py +++ b/ultralytics/engine/exporter.py @@ -1559,6 +1559,7 @@ class NMSModel(torch.nn.Module): extra_shape = pred.shape[-1] - (4 + self.model.nc) # extras from Segment, OBB, Pose boxes, scores, extras = pred.split([4, self.model.nc, extra_shape], dim=2) scores, classes = scores.max(dim=-1) + self.args.max_det = min(pred.shape[1], self.args.max_det) # in case num_anchors < max_det # (N, max_det, 4 coords + 1 class score + 1 class label + extra_shape). out = torch.zeros( boxes.shape[0], @@ -1596,14 +1597,25 @@ class NMSModel(torch.nn.Module): offbox = nmsbox[:, :end] + cls_offset * multiplier nmsbox = torch.cat((offbox, nmsbox[:, end:]), dim=-1) nms_fn = ( - partial(nms_rotated, use_triu=not (self.is_tf or (self.args.opset or 14) < 14)) if self.obb else nms + partial( + nms_rotated, + use_triu=not ( + self.is_tf + or (self.args.opset or 14) < 14 + or (self.args.format == "openvino" and self.args.int8) # OpenVINO int8 error with triu + ), + ) + if self.obb + else nms ) keep = nms_fn( torch.cat([nmsbox, extra], dim=-1) if self.obb else nmsbox, score, self.args.iou, )[: self.args.max_det] - dets = torch.cat([box[keep], score[keep].view(-1, 1), cls[keep].view(-1, 1), extra[keep]], dim=-1) + dets = torch.cat( + [box[keep], score[keep].view(-1, 1), cls[keep].view(-1, 1).to(out.dtype), extra[keep]], dim=-1 + ) # Zero-pad to max_det size to avoid reshape error pad = (0, 0, 0, self.args.max_det - dets.shape[0]) out[i] = torch.nn.functional.pad(dets, pad)