yolov5-seg-ncnn icon indicating copy to clipboard operation
yolov5-seg-ncnn copied to clipboard

How to convert yolov5s-seg.pt to ncnn?

Open Digital2Slave opened this issue 2 years ago • 2 comments

  1. environment
Ubuntu 18.04.6 LTS
torch                     1.8.0+cpu
torchaudio                0.8.0
torchvision               0.9.0+cpu
cmake                     3.25.0
ninja                     1.11.1
gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0

Build pnnx refer https://zhuanlan.zhihu.com/p/444022507.

  1. yolov5s-seg.pt

https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5s-seg.pt

  1. export.py

https://github.com/ultralytics/yolov5/blob/v7.0/export.py

  1. convert pt to torchscript
$ python export.py --weights /home/tianzx/AI/pre_weights/yolov5-7.0/test/yolov5s-seg.pt --include torchscript

export: data=data/coco128.yaml, weights=['/home/tianzx/AI/pre_weights/yolov5-7.0/test/yolov5s-seg.pt'], imgsz=[640, 640], batch_size=1, device=cpu, half=False, inplace=False, keras=False, optimize=False, int8=False, dynamic=False, simplify=False, opset=12, verbose=False, workspace=4, nms=False, agnostic_nms=False, topk_per_class=100, topk_all=100, iou_thres=0.45, conf_thres=0.25, include=['torchscript']
YOLOv5 🚀 2022-11-22 Python-3.7.16 torch-1.8.0+cpu CPU

Fusing layers... 
YOLOv5s-seg summary: 224 layers, 7611485 parameters, 0 gradients, 26.4 GFLOPs

PyTorch: starting from /home/tianzx/AI/pre_weights/yolov5-7.0/test/yolov5s-seg.pt with output shape (1, 25200, 117) (14.9 MB)

TorchScript: starting export with torch 1.8.0+cpu...
TorchScript: export success ✅ 1.8s, saved as /home/tianzx/AI/pre_weights/yolov5-7.0/test/yolov5s-seg.torchscript (29.5 MB)

Export complete (4.0s)
Results saved to /home/tianzx/AI/pre_weights/yolov5-7.0/test
Detect:          python segment/detect.py --weights /home/tianzx/AI/pre_weights/yolov5-7.0/test/yolov5s-seg.torchscript 
Validate:        python segment/val.py --weights /home/tianzx/AI/pre_weights/yolov5-7.0/test/yolov5s-seg.torchscript 
PyTorch Hub:     model = torch.hub.load('ultralytics/yolov5', 'custom', '/home/tianzx/AI/pre_weights/yolov5-7.0/test/yolov5s-seg.torchscript')  # WARNING ⚠️ SegmentationModel not yet supported for PyTorch Hub AutoShape inference
Visualize:       https://netron.app
  1. convert torchscript to ncnn
$ ./pnnx /home/tianzx/AI/pre_weights/yolov5-7.0/test/yolov5s-seg.torchscript inputshape=[1,3,640,640]
pnnxparam = /home/tianzx/AI/pre_weights/yolov5-7.0/test/yolov5s-seg.pnnx.param
pnnxbin = /home/tianzx/AI/pre_weights/yolov5-7.0/test/yolov5s-seg.pnnx.bin
pnnxpy = /home/tianzx/AI/pre_weights/yolov5-7.0/test/yolov5s-seg_pnnx.py
pnnxonnx = /home/tianzx/AI/pre_weights/yolov5-7.0/test/yolov5s-seg.pnnx.onnx
ncnnparam = /home/tianzx/AI/pre_weights/yolov5-7.0/test/yolov5s-seg.ncnn.param
ncnnbin = /home/tianzx/AI/pre_weights/yolov5-7.0/test/yolov5s-seg.ncnn.bin
ncnnpy = /home/tianzx/AI/pre_weights/yolov5-7.0/test/yolov5s-seg_ncnn.py
fp16 = 1
optlevel = 2
device = cpu
inputshape = [1,3,640,640]f32
inputshape2 = 
customop = 
moduleop = 
############# pass_level0
inline module = models.common.Bottleneck
inline module = models.common.C3
inline module = models.common.Concat
inline module = models.common.Conv
inline module = models.common.Proto
inline module = models.common.SPPF
inline module = models.yolo.Segment
inline module = models.common.Bottleneck
inline module = models.common.C3
inline module = models.common.Concat
inline module = models.common.Conv
inline module = models.common.Proto
inline module = models.common.SPPF
inline module = models.yolo.Segment

----------------

############# pass_level1
no attribute value
no attribute value
unknown Parameter value kind prim::Constant of TensorType, t.dim = 5
unknown Parameter value kind prim::Constant of TensorType, t.dim = 5
unknown Parameter value kind prim::Constant of TensorType, t.dim = 5
unknown Parameter value kind prim::Constant of TensorType, t.dim = 5
unknown Parameter value kind prim::Constant of TensorType, t.dim = 5
unknown Parameter value kind prim::Constant of TensorType, t.dim = 1
unknown Parameter value kind prim::Constant of TensorType, t.dim = 5
no attribute value
unknown Parameter value kind prim::Constant of TensorType, t.dim = 1
unknown Parameter value kind prim::Constant of TensorType, t.dim = 1
############# pass_level2
############# pass_level3
assign unique operator name pnnx_unique_0 to model.9.m
assign unique operator name pnnx_unique_1 to model.9.m
############# pass_level4
############# pass_level5
############# pass_ncnn
select along batch axis 0 is not supported
select along batch axis 0 is not supported
select along batch axis 0 is not supported
ignore Crop select_0 param dim=0
ignore Crop select_0 param index=0
ignore Crop select_1 param dim=0
ignore Crop select_1 param index=1
ignore Crop select_2 param dim=0
ignore Crop select_2 param index=2

The content of yolov5s-seg.ncnn.param file is not same content of your param file provided yolov5s-seg.param.

yolov5s-seg.ncnn.param

Could you help me out or figure out where is the problem ?

@FeiGeChuanShu

Thanks a lot in advance any way!

Digital2Slave avatar Jan 28 '23 04:01 Digital2Slave

@Digital2Slave Did you solve it? I'm also facing this issue

MjiS avatar Feb 09 '23 10:02 MjiS

@Digital2Slave Did you solve it? I'm also facing this issue

Not yet!

Digital2Slave avatar Feb 10 '23 02:02 Digital2Slave