diff --git a/ACL_PyTorch/built-in/cv/yolov11/README.md b/ACL_PyTorch/built-in/cv/yolov11/README.md deleted file mode 100644 index 3f46fc797ea9a67ed51d90ab560b42c643bb660d..0000000000000000000000000000000000000000 --- a/ACL_PyTorch/built-in/cv/yolov11/README.md +++ /dev/null @@ -1,118 +0,0 @@ -# YOLOV11(TorchAir)-推理指导 - -- [YOLOV11(TorchAir)-推理指导](#yolov11torchair-推理指导) -- [概述](#概述) -- [推理环境准备](#推理环境准备) -- [快速上手](#快速上手) - - [获取源码](#获取源码) - - [获取数据集](#获取数据集) - - [获取权重](#获取权重) - - [执行推理](#执行推理) - - [性能数据](#性能数据) - -****** - -# 概述 - -- 版本说明: - ``` - url=https://github.com/ultralytics/ultralytics.git - commit_id=e74b035 - model_name=YOLOV11 - ``` - -# 推理环境准备 -- 该模型需要以下插件与驱动 - **表 1** 版本配套表 - - | 配套 | 版本 | 环境准备指导 | - | ------------------------------------------------------------ | ------ | ------------------------------------------------------------ | - | 固件与驱动 | 24.0.RC3 | [Pytorch框架推理环境准备](https://www.hiascend.com/document/detail/zh/ModelZoo/pytorchframework/pies) | - | CANN | 8.1.0 | - | - | Python | 3.8 | - | - | PyTorch | 2.1.0 | - | - | Ascend Extension PyTorch | 2.1.0.post8 | - | - | 说明:Atlas 800I A2/Atlas 300I Pro 推理卡请以CANN版本选择实际固件与驱动版本。 | \ | \ | - - -# 快速上手 - -## 获取源码 - -1. 获取`Pytorch`源码 -``` -git clone https://github.com/ultralytics/ultralytics.git -cd ultralytics -git reset --hard e74b035 -git apply ../diff.patch -cd .. -export PYTHONPATH=./ultralytics:$PYTHONPATH -``` - -2. 安装依赖 -``` -pip3 install -r requirements.txt -``` - - -## 获取数据集 - -1. 新建datasets文件夹,下载COCO-2017数据集,放置datasets目录下 -``` - ultralytics - └── dataset - └── coco-2017 -``` - -3. 利用dataset.py脚本,将数据集转化为YOLO仓支持的格式 -```bash -python3 dataset.py --data_path=./coco/annotations/ -``` -- 参数说明 - - data_path: coco数据集annotations目录 - -执行后生成coco_converted文件夹 - -3. 移动image文件夹到coco_converted内 -``` -mv coco/val2017 coco_converted/image -``` -完成后数据集结构如下 -``` - dataset - └── coco_converted - ├── image - └── val2017 - └── ***.jpg - └── label - └── val2017 - └── ***.txt -``` - -## 获取权重 -下载权重文件[yolo11l.pt](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11l.pt),放到当前目录下 -``` -wget https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11l.pt -``` - -## 执行推理 -运行推理脚本infer.py -``` -python3 infer.py --pth=yolo11l.pt --dataset=coco.yaml --batchsize=16 -``` -- 参数说明 - - pth: 模型权重,以yolo11l.pt为例 - - dataset: 数据集信息 - - batchsize: 数据集推理batchsize - -推理执行完成后,数据集精度和数据集性能会执行打屏 - -## 性能数据 -以bs16在数据集上的推理为例 -|模型|芯片|性能(per image)|精度(mAP)| -|------|------|------|------| -|yolo11l|800I A2|1.7ms|53.3| - -注:该模型支持动态shape数据集推理,输入shape长边会处理为640,短边以原尺寸scale - - diff --git a/ACL_PyTorch/built-in/cv/yolov11/dataset.py b/ACL_PyTorch/built-in/cv/yolov11/dataset.py deleted file mode 100644 index 21e1f8a3d3b05b3ba429e301059e8d0e78891e58..0000000000000000000000000000000000000000 --- a/ACL_PyTorch/built-in/cv/yolov11/dataset.py +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (c) 2025 Huawei Technologies Co., Ltd -# [Software Name] is licensed under Mulan PSL v2. -# You can use this software according to the terms and conditions of the Mulan PSL v2. -# You may obtain a copy of Mulan PSL v2 at: -# http://license.coscl.org.cn/MulanPSL2 -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, -# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, -# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. -# See the Mulan PSL v2 for more details. - -import argparse -from ultralytics.data.converter import convert_coco - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description="yolov11 dataset convert") - parser.add_argument("--data_path", type=str, help="datasetpath") - args = parser.parse_args() - - convert_coco(labels_dir=args.data_path) diff --git a/ACL_PyTorch/built-in/cv/yolov11/diff.patch b/ACL_PyTorch/built-in/cv/yolov11/diff.patch deleted file mode 100644 index 2461135402d8d0329c4d5feedb9a3a82b27084d9..0000000000000000000000000000000000000000 --- a/ACL_PyTorch/built-in/cv/yolov11/diff.patch +++ /dev/null @@ -1,137 +0,0 @@ ---- - ultralytics/engine/validator.py | 7 ++++++- - ultralytics/nn/autobackend.py | 10 ++++++++++ - ultralytics/nn/modules/block.py | 11 +++++++++-- - ultralytics/nn/modules/head.py | 17 ++++++++++------- - ultralytics/utils/tal.py | 3 ++- - 5 files changed, 37 insertions(+), 11 deletions(-) - -diff --git a/ultralytics/engine/validator.py b/ultralytics/engine/validator.py -index 42c0e329..0f46395e 100644 ---- a/ultralytics/engine/validator.py -+++ b/ultralytics/engine/validator.py -@@ -158,7 +158,12 @@ class BaseValidator: - self.dataloader = self.dataloader or self.get_dataloader(self.data.get(self.args.split), self.args.batch) - - model.eval() -- model.warmup(imgsz=(1 if pt else self.args.batch, 3, imgsz, imgsz)) # warmup -+ # model.warmup(imgsz=(1 if pt else self.args.batch, 3, imgsz, imgsz)) # warmup -+ # 新增warmup,保证性能准确 -+ print('start warm up') -+ model.warmup(imgsz=(self.args.batch, 3, imgsz, imgsz)) # warmup -+ model.warmup(imgsz=(self.args.batch, 3, 288, imgsz)) # warmup -+ print('end warm up') - - self.run_callbacks("on_val_start") - dt = ( -diff --git a/ultralytics/nn/autobackend.py b/ultralytics/nn/autobackend.py -index 7629fb7c..36ce75d6 100644 ---- a/ultralytics/nn/autobackend.py -+++ b/ultralytics/nn/autobackend.py -@@ -12,6 +12,10 @@ import numpy as np - import torch - import torch.nn as nn - from PIL import Image -+import torch_npu -+from torch_npu.contrib import transfer_to_npu -+import torchair as tng -+from torchair.configs.compiler_config import CompilerConfig - - from ultralytics.utils import ARM64, IS_JETSON, IS_RASPBERRYPI, LINUX, LOGGER, PYTHON_VERSION, ROOT, yaml_load - from ultralytics.utils.checks import check_requirements, check_suffix, check_version, check_yaml, is_rockchip -@@ -156,6 +160,12 @@ class AutoBackend(nn.Module): - names = model.module.names if hasattr(model, "module") else model.names # get class names - model.half() if fp16 else model.float() - self.model = model # explicitly assign for to(), cpu(), cuda(), half() -+ # 添加torchair适配代码 -+ config = CompilerConfig() -+ config.experimental_config.frozen_parameter = True -+ npu_backbend = tng.get_npu_backend(compiler_config=config) -+ model = torch.compile(model, dynamic=True, fullgraph=True, backend=npu_backbend) -+ tng.use_internal_format_weight(model.model) - pt = True - - # PyTorch -diff --git a/ultralytics/nn/modules/block.py b/ultralytics/nn/modules/block.py -index 567e1aaf..96fe54d0 100644 ---- a/ultralytics/nn/modules/block.py -+++ b/ultralytics/nn/modules/block.py -@@ -185,7 +185,10 @@ class SPPF(nn.Module): - def forward(self, x): - """Forward pass through Ghost Convolution block.""" - y = [self.cv1(x)] -- y.extend(self.m(y[-1]) for _ in range(3)) -+ # y.extend(self.m(y[-1]) for _ in range(3)) -+ for _ in range(3): -+ o1 = self.m(y[-1]) -+ y.extend(o1.unsqueeze(0)) - return self.cv2(torch.cat(y, 1)) - - -@@ -236,7 +239,11 @@ class C2f(nn.Module): - def forward(self, x): - """Forward pass through C2f layer.""" - y = list(self.cv1(x).chunk(2, 1)) -- y.extend(m(y[-1]) for m in self.m) -+ # y.extend(m(y[-1]) for m in self.m) -+ # 该条代码在torch和dynamo中存在逻辑分歧,改为外部循环表示 -+ for m in self.m: -+ o1 = m(y[-1]) -+ y.extend(o1.unsqueeze(0)) - return self.cv2(torch.cat(y, 1)) - - def forward_split(self, x): -diff --git a/ultralytics/nn/modules/head.py b/ultralytics/nn/modules/head.py -index b9d05024..fa4fc606 100644 ---- a/ultralytics/nn/modules/head.py -+++ b/ultralytics/nn/modules/head.py -@@ -102,9 +102,12 @@ class Detect(nn.Module): - # Inference path - shape = x[0].shape # BCHW - x_cat = torch.cat([xi.view(shape[0], self.no, -1) for xi in x], 2) -- if self.format != "imx" and (self.dynamic or self.shape != shape): -- self.anchors, self.strides = (x.transpose(0, 1) for x in make_anchors(x, self.stride, 0.5)) -- self.shape = shape -+ anchors, strides = make_anchors(x, self.stride, 0.5) -+ anchors = anchors.transpose(0, 1) -+ strides = strides.transpose(0, 1) - - if self.export and self.format in {"saved_model", "pb", "tflite", "edgetpu", "tfjs"}: # avoid TF FlexSplitV ops - box = x_cat[:, : self.reg_max * 4] -@@ -118,15 +121,15 @@ class Detect(nn.Module): - grid_h = shape[2] - grid_w = shape[3] - grid_size = torch.tensor([grid_w, grid_h, grid_w, grid_h], device=box.device).reshape(1, 4, 1) -- norm = self.strides / (self.stride[0] * grid_size) -- dbox = self.decode_bboxes(self.dfl(box) * norm, self.anchors.unsqueeze(0) * norm[:, :2]) -+ norm = strides / (stride[0] * grid_size) -+ dbox = self.decode_bboxes(self.dfl(box) * norm, anchors.unsqueeze(0) * norm[:, :2]) - elif self.export and self.format == "imx": - dbox = self.decode_bboxes( -- self.dfl(box) * self.strides, self.anchors.unsqueeze(0) * self.strides, xywh=False -+ self.dfl(box) * strides, anchors.unsqueeze(0) * strides, xywh=False - ) - return dbox.transpose(1, 2), cls.sigmoid().permute(0, 2, 1) - else: -- dbox = self.decode_bboxes(self.dfl(box), self.anchors.unsqueeze(0)) * self.strides -+ dbox = self.decode_bboxes(self.dfl(box), anchors.unsqueeze(0)) * strides - - return torch.cat((dbox, cls.sigmoid()), 1) - -diff --git a/ultralytics/utils/tal.py b/ultralytics/utils/tal.py -index e4a40f5e..2ded54be 100644 ---- a/ultralytics/utils/tal.py -+++ b/ultralytics/utils/tal.py -@@ -341,7 +341,8 @@ def make_anchors(feats, strides, grid_cell_offset=0.5): - sy = torch.arange(end=h, device=device, dtype=dtype) + grid_cell_offset # shift y - sy, sx = torch.meshgrid(sy, sx, indexing="ij") if TORCH_1_10 else torch.meshgrid(sy, sx) - anchor_points.append(torch.stack((sx, sy), -1).view(-1, 2)) -- stride_tensor.append(torch.full((h * w, 1), stride, dtype=dtype, device=device)) -+ # stride_tensor.append(torch.full((h * w, 1), stride, dtype=dtype, device=device)) -+ stride_tensor.append(torch.ones((h * w, 1), dtype=dtype, device=device)*stride) - return torch.cat(anchor_points), torch.cat(stride_tensor) - - --- -2.33.0 - diff --git a/ACL_PyTorch/built-in/cv/yolov11/infer.py b/ACL_PyTorch/built-in/cv/yolov11/infer.py deleted file mode 100644 index 381726e06f4ec3202fc81c09d05992075ff87973..0000000000000000000000000000000000000000 --- a/ACL_PyTorch/built-in/cv/yolov11/infer.py +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright (c) 2025 Huawei Technologies Co., Ltd -# [Software Name] is licensed under Mulan PSL v2. -# You can use this software according to the terms and conditions of the Mulan PSL v2. -# You may obtain a copy of Mulan PSL v2 at: -# http://license.coscl.org.cn/MulanPSL2 -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, -# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, -# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. -# See the Mulan PSL v2 for more details. - - -import argparse -import torch -import torch_npu -from ultralytics import YOLO - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description="yolov11 dataset convert") - parser.add_argument("--pth", type=str, help="weight") - parser.add_argument("--dataset", type=str, help="dataset") - parser.add_argument("--batchsize", type=int, help="batchsize") - args = parser.parse_args() - - torch_npu.npu.set_compile_mode(jit_compile=False) - model = YOLO(args.pth) - with torch.no_grad(): - model.val(data=args.dataset, batch=args.batchsize, half=True, imgsz=640) \ No newline at end of file diff --git a/ACL_PyTorch/built-in/cv/yolov11/requirements.txt b/ACL_PyTorch/built-in/cv/yolov11/requirements.txt deleted file mode 100644 index 7bcb2d91d5636aa8fd9f56c4c6e6c760f9e0c9b0..0000000000000000000000000000000000000000 --- a/ACL_PyTorch/built-in/cv/yolov11/requirements.txt +++ /dev/null @@ -1,10 +0,0 @@ -torch==2.1.0 -torch_npu==2.1.0.post10 -torchvision==0.16.0 -numpy==1.26.0 -pillow -opencv-python -matplotlib -pyyaml -psutil -seaborn \ No newline at end of file