-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
模型转换问题 #1
Comments
Same question, I already try onn2ncnn and pnnx but none works 😭 |
my model converted from onnx. you should change the split to slice in c2f block |
How to change the split to slice in c2f block? @FeiGeChuanShu |
https://github.com/triple-Mu/YOLOv8-TensorRT/blob/main/models/common.py#L87-L91 |
Got it! Thanks a lot. |
Hello @FeiGeChuanShu @Qengineering and others, 7767517 |
Can you help me what changes need to be made before converting .pt to onnx and then .param and .bin? Thank you in advance. |
@apanand14 Not focus on yolov8 yet. |
Any other modifications than this? and this modification should be done before exporting it to ONNX right? |
@apanand14 But here is an issue There maybe two ways to handle this issue.
Note that
|
Thank you for your valuable inputs! @Digital2Slave Yes. I have converted from onnx to ncnn with export_seg.py and generated axis=-1keepdims=1Cast not supported yet! to=1**Sorry but I didn't get the modifications you talked about. I tried to make ArgMax layer ON in and then tried but results are same. I understood that some modifications needs to be done to run properly but if you help me out there then it would be grateful of you. Thank in advance for your time. |
i have update the readme show how to change v8 code |
Refer the codes convert to onnx for ncnn in README. I modified
However, I have an issue when convert yolov8s-seg.pt to yolov8s-seg.onnx by the
$ python export.py
Ultralytics YOLOv8.0.29 🚀 Python-3.7.16 torch-1.8.0+cpu CPU
YOLOv8s-seg summary (fused): 195 layers, 11810560 parameters, 0 gradients
Traceback (most recent call last):
File "export.py", line 7, in <module>
success = model.export(format="onnx", opset=12, simplify=True)
File "/home/tianzx/.virtualenvs/d2l/lib/python3.7/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "/home/tianzx/Github/ultralytics/ultralytics/yolo/engine/model.py", line 188, in export
exporter(model=self.model)
File "/home/tianzx/.virtualenvs/d2l/lib/python3.7/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "/home/tianzx/Github/ultralytics/ultralytics/yolo/engine/exporter.py", line 184, in __call__
y = model(im) # dry runs
File "/home/tianzx/.virtualenvs/d2l/lib/python3.7/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/tianzx/Github/ultralytics/ultralytics/nn/tasks.py", line 198, in forward
return self._forward_once(x, profile, visualize) # single-scale inference, train
File "/home/tianzx/Github/ultralytics/ultralytics/nn/tasks.py", line 57, in _forward_once
x = m(x) # run
File "/home/tianzx/.virtualenvs/d2l/lib/python3.7/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/tianzx/Github/ultralytics/ultralytics/nn/modules.py", line 451, in forward
return (torch.cat([x, mc], 1), p) if self.export else (torch.cat([x[0], mc], 1), (x[1], mc, p))
RuntimeError: Sizes of tensors must match except in dimension 1. Got 144 and 8400 in dimension 2 (The offending index is 1) The Same issue for the following export script.
Environment:
|
@Digital2Slave i have fixed the readme for seg model. you can try it. |
Thank you so much but not able to see the change after self.export in return of forward method for seg in your .jpg. It would be helpful if you share it again. Thank you in advance |
it's same as the original code after self.export.you should only change the code before self.export. |
Okay!! Thank you so much for your input. Just one more thing. Should train again with these changes or I can export my trained model with these changes and convert to ncnn? |
Yes. maybe you should change the num_class here if your class number isn't 80. https://github.com/FeiGeChuanShu/ncnn-android-yolov8/blob/main/ncnn-yolov8s-seg/yolov8-seg.cpp#L261 |
@FeiGeChuanShu Thanks a lot! Great job! As for yolov8 segment model. I need modify three
Run
|
Great! Thank you! I attac
Thank you. I just converted my ONNX to NCNN. my param looks quite similar like yours but I have only one crop where you have two. I attach my best.param file in .txt format here if you would just have a glance then it would be great. |
my model is old.The new one crop model is more efficient than my old model |
Great! Then I asssume that I'm good to go for inference with NCNN |
Btw, I have trained yolov8n-seg for my custom dataset. Your .cpp will work with this model as well right? |
Of course |
Thank you again!! |
Thank you so much @FeiGeChuanShu and @Digital2Slave for all your help!! everything works well and able to test successfully my custom model. One more thing, do you have an app for seg model like detection model then I would like try with an app as well. |
|
1. Prepare yolov8 segment ncnn modelsI use yolov8n-seg.pt and yolov8s-seg.pt to convert ncnn model files.
Put the ncnn models to 2. Modify
|
Thank you so much @Digital2Slave for your support to run ncnn anroid app for yolov8. It runs fine. And thank you @FeiGeChuanShu for proving an inference script for yolov8-seg and yolov5-seg ncnn anroid app. Great work guys! |
飞哥 @FeiGeChuanShu 我这边还是有闪退问题。 |
@FeiGeChuanShu @Digital2Slave Thank you for everyone's contributions to the paradigm shift
My conversion command is as follows
Error
I really look forward to everyone's help with this problem, I think there are many people having the same problem as me. Thanks in advance |
Permute Transpose_526 1 1 custom_output_8 output 0=1 |
|
飞哥,yoloV8的pt模型如何转换为ONNX,再转换为NCNN模型的?
The text was updated successfully, but these errors were encountered: