Passer1072 / RookieAI_yolov8

基于yolov8实现的AI自瞄项目 AI self-aiming project based on yolov8
MIT License
280 stars 68 forks source link

加载ONNX模型失败,PT正常 #60

Open Cyber-2000 opened 2 months ago

Cyber-2000 commented 2 months ago

Describe the bug

A clear and concise description of what the bug is.

描述问题的清晰而简明的说明

加载ONNX模型失败,PT正常

To Reproduce

Steps to reproduce the behavior.

重现行为的步骤

加载一个 ONNX 模型,报错。

Expected behavior

A clear and concise description of what you expected to happen.

期望发生的行为的清晰而简明的描述

正常使用

Screenshots

If applicable, add screenshots to help explain your problem.

如果适用,请添加截图以帮助解释您的问题

(base) C:\Users\1\Desktop\R>python main.py
开始加载飞易来盒子文件...
启动飞易来盒子...
open handle = 18446744073709551615
鼠标移动:False
启动盒子失败
Loading prefix variables...
前置变量加载成功!
开始获取公告......
获取成功
开始获取版本号......
获取成功
加载模型文件: C:/Users/1/Desktop/sjz/sjz1.onnx
半精度推理 设置为: False
WARNING ⚠️ Unable to automatically guess model task, assuming 'task=detect'. Explicitly define task for your model, i.e. 'task=detect', 'segment', 'classify','pose' or 'obb'.
开始获取版本号......
获取成功
Loading settings...
设置加载成功!
update_values function was called(配置已更新)
正在等待加载完成
[INFO]已禁用DXcam
Loading C:\Users\1\Desktop\sjz\sjz1.onnx for ONNX Runtime inference...
Exception in thread Thread-2 (main_program_loop):
Traceback (most recent call last):
  File "C:\ProgramData\anaconda3\Lib\threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "C:\ProgramData\anaconda3\Lib\threading.py", line 1010, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\1\Desktop\R\main.py", line 2645, in main_program_loop
    results = model.predict(frame, save=False, conf=confidence, half=half_precision_model, agnostic_nms=True, iou=0.7, classes=[
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\1\AppData\Roaming\Python\Python312\site-packages\ultralytics\engine\model.py", line 547, in predict
    self.predictor.setup_model(model=self.model, verbose=is_cli)
  File "C:\Users\1\AppData\Roaming\Python\Python312\site-packages\ultralytics\engine\predictor.py", line 303, in setup_model
    self.model = AutoBackend(
                 ^^^^^^^^^^^^
  File "C:\ProgramData\anaconda3\Lib\site-packages\torch\utils\_contextlib.py", line 116, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\1\AppData\Roaming\Python\Python312\site-packages\ultralytics\nn\autobackend.py", line 415, in __init__
    task = metadata["task"]
           ~~~~~~~~^^^^^^^^
KeyError: 'task'

Equipment information:

win11 RookieAI最新版
(base) C:\Users\1\Desktop\R>pip show torch
Name: torch
Version: 2.4.1+cu121
Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration
Home-page: https://pytorch.org/
Author: PyTorch Team
Author-email: packages@pytorch.org
License: BSD-3
Location: C:\ProgramData\anaconda3\Lib\site-packages
Requires: filelock, fsspec, jinja2, networkx, setuptools, sympy, typing-extensions
Required-by: accelerate, onnx2pytorch, optimum, thop, torchaudio, torchvision, ultralytics, ultralytics-thop
(base) C:\Users\1\Desktop\R>pip show onnxruntime
WARNING: Package(s) not found: onnxruntime

(base) C:\Users\1\Desktop\R>pip show onnxruntime-gpu
Name: onnxruntime-gpu
Version: 1.19.2
Summary: ONNX Runtime is a runtime accelerator for Machine Learning models
Home-page: https://onnxruntime.ai
Author: Microsoft Corporation
Author-email: onnxruntime@microsoft.com
License: MIT License
Location: C:\ProgramData\anaconda3\Lib\site-packages
Requires: coloredlogs, flatbuffers, numpy, packaging, protobuf, sympy
Required-by:
(base) C:\Windows\System32>nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Tue_Feb_27_16:28:36_Pacific_Standard_Time_2024
Cuda compilation tools, release 12.4, V12.4.99
Build cuda_12.4.r12.4/compiler.33961263_0
(base) C:\Windows\System32>python --version
Python 3.12.4

image

image

Additional context

Add any other context about the problem here.

在这里添加关于问题的其他相关信息

molanp commented 2 months ago

看日志模型中似乎没定义task

尝试使用仓库中的转换工具处理模型

Cyber-2000 commented 1 month ago

好吧,我试试