From b48c5a81ab63fbeb4851f187230b5b4ff801074b Mon Sep 17 00:00:00 2001 From: Laughing-q <1185102784@qq.com> Date: Wed, 30 Oct 2024 19:18:20 +0800 Subject: [PATCH] update --- .github/workflows/ci.yaml | 1 + tests/test_ncnn.py | 5 ----- tests/test_onnx.py | 6 ++++++ ultralytics/engine/exporter.py | 10 +++++----- 4 files changed, 12 insertions(+), 10 deletions(-) create mode 100644 tests/test_onnx.py diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 33e624492b..03bf06fce3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -195,6 +195,7 @@ jobs: slow="--slow" fi pytest $slow --cov=ultralytics/ --cov-report xml tests/test_ncnn.py + pytest $slow --cov=ultralytics/ --cov-report xml tests/test_onnx.py - name: Upload Coverage Reports to CodeCov if: github.repository == 'ultralytics/ultralytics' # && matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11' uses: codecov/codecov-action@v4 diff --git a/tests/test_ncnn.py b/tests/test_ncnn.py index e387be8732..0d89bc7657 100644 --- a/tests/test_ncnn.py +++ b/tests/test_ncnn.py @@ -17,8 +17,3 @@ def test_ncnn(): # verbose=False, # ) # then export onnx - - -def test_onnx(): - model = YOLO("yolo11n.pt") - model.export(imgsz=160, format="onnx", half=False, int8=False, device="cpu", verbose=False) diff --git a/tests/test_onnx.py b/tests/test_onnx.py new file mode 100644 index 0000000000..22a5c6f8e8 --- /dev/null +++ b/tests/test_onnx.py @@ -0,0 +1,6 @@ +from ultralytics import YOLO + + +def test_onnx(): + model = YOLO("yolo11n.pt") + model.export(imgsz=160, format="onnx", half=False, int8=False, device="cpu", verbose=False) diff --git a/ultralytics/engine/exporter.py b/ultralytics/engine/exporter.py index bdcbb171ca..00a678d12e 100644 --- a/ultralytics/engine/exporter.py +++ b/ultralytics/engine/exporter.py @@ -572,8 +572,8 @@ class Exporter: unzip_dir = safe_download(f"https://github.com/pnnx/pnnx/releases/download/{release}/{asset}", delete=True) if check_is_path_safe(Path.cwd(), unzip_dir): # avoid path traversal security vulnerability shutil.move(src=unzip_dir / name, dst=pnnx) # move binary to ROOT - # pnnx.chmod(0o777) # set read, write, and execute permissions for everyone - # shutil.rmtree(unzip_dir) # delete unzip dir + pnnx.chmod(0o777) # set read, write, and execute permissions for everyone + shutil.rmtree(unzip_dir) # delete unzip dir ncnn_args = [ f'ncnnparam={f / "model.ncnn.param"}', @@ -602,9 +602,9 @@ class Exporter: subprocess.run(cmd, check=True) # Remove debug files - # pnnx_files = [x.split("=")[-1] for x in pnnx_args] - # for f_debug in ("debug.bin", "debug.param", "debug2.bin", "debug2.param", *pnnx_files): - # Path(f_debug).unlink(missing_ok=True) + pnnx_files = [x.split("=")[-1] for x in pnnx_args] + for f_debug in ("debug.bin", "debug.param", "debug2.bin", "debug2.param", *pnnx_files): + Path(f_debug).unlink(missing_ok=True) yaml_save(f / "metadata.yaml", self.metadata) # add metadata.yaml return str(f), None