UnboundLocalError

Hello @afa1414 ,

Sorry to reply late.

Suggest you use the latest KSNN. We no longer maintain old versions.

Your pose code has not mistakes. I run your code directly and get below result.

Have you infer your original model (.pt) that can get right result?

I attempted to convert the model using ultralytics 8.0.86, torch 1.8.0, and onnx 1.8.0, and when I tried to convert the .pt file to onnx, I encountered the following error:

(yolov8_env) ss@ss-System-Product-Name:~/yolov8_env$ python3 export1.py
WARNING ⚠️ yolov8n-pose.pt appears to require 'ultralytics.nn.modules.conv', which is not in ultralytics requirements.
AutoInstall will run now for 'ultralytics.nn.modules.conv' but this feature will be removed in the future.
Recommend fixes are to train a new model using the latest 'ultralytics' package or to run a command with an official YOLOv8 model, i.e. 'yolo predict model=yolov8n.pt'
requirements: YOLOv8 requirement "ultralytics.nn.modules.conv" not found, attempting AutoUpdate...
ERROR: Could not find a version that satisfies the requirement ultralytics.nn.modules.conv (from versions: none)
ERROR: No matching distribution found for ultralytics.nn.modules.conv
requirements: ❌ Command 'pip install --no-cache "ultralytics.nn.modules.conv"  ' returned non-zero exit status 1.
Traceback (most recent call last):
  File "export1.py", line 2, in <module>
    model = YOLO("yolov8n-pose.pt")
  File "/home/ss/yolov8_env/lib/python3.8/site-packages/ultralytics/yolo/engine/model.py", line 107, in __init__
    self._load(model, task)
  File "/home/ss/yolov8_env/lib/python3.8/site-packages/ultralytics/yolo/engine/model.py", line 156, in _load
    self.model, self.ckpt = attempt_load_one_weight(weights)
  File "/home/ss/yolov8_env/lib/python3.8/site-packages/ultralytics/nn/tasks.py", line 419, in attempt_load_one_weight
    ckpt, weight = torch_safe_load(weight)  # load ckpt
  File "/home/ss/yolov8_env/lib/python3.8/site-packages/ultralytics/nn/tasks.py", line 374, in torch_safe_load
    return torch.load(file, map_location='cpu'), file  # load
  File "/home/ss/yolov8_env/lib/python3.8/site-packages/torch/serialization.py", line 592, in load
    return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
  File "/home/ss/yolov8_env/lib/python3.8/site-packages/torch/serialization.py", line 851, in _load
    result = unpickler.load()
ModuleNotFoundError: No module named 'ultralytics.nn.modules.conv'; 'ultralytics.nn.modules' is not a package

Due to this error, I modified the yaml file. Could this process cause any issues?

Hello @afa1414 ,

I do not know what you modify in yaml, so i cannot judge.

The model you convert is trained by ultralytics 8.0.86? Higher version model may change the name of modules.

I went through this code to convert it to ONNX.

from ultralytics import YOLO
model = YOLO("yolov8n-pose.yaml")
results = model.export(format="onnx")

I also modified the modules and tasks files.

Hello @afa1414 ,

If you only modify the name of modules and tasks, i think it causes nothing.

If somthing wrong, you also can try to retrain model in ultralytics 8.0.86.

Thank you for your response. I will give it a try.

I’m trying it, but it’s not going well. Could you provide the YOLOv8n pose model you used for the conversion?
I’m curious about the versions. I would like to know the versions of ultralytics, YOLOv8n pose model, and ONNX that were used for the conversion.
First, when I converted to onnx in version 8.0.86, I got that error by using the model that was automatically downloaded with the code above, so I converted the yaml file.
@Louis-Cheng-Liu

Hello @afa1414 ,

All models are in it.
https://dl.khadas.com/.test/yolov8n_pose.zip

Thank you for your kind response. The pose estimation model is now running without any issues.