YOLOV5_NCNN_Android icon indicating copy to clipboard operation
YOLOV5_NCNN_Android copied to clipboard

how to removed the Slice operation and replaced the input with a downscaled image and stacked it to match the channel number?

Open huolianchu opened this issue 4 years ago • 6 comments

Hi,

Thanks for you work

i using my own trained model file will report error Slice operation in .pt or in .onnx?

huolianchu avatar Jun 24 '20 07:06 huolianchu

more details needed as you

miziha-zp avatar Jun 27 '20 03:06 miziha-zp

ONNX converts the operation of line 87 in common.py

return self.conv(torch.cat([x[..., ::2, ::2], x[..., 1::2, ::2], x[..., ::2, 1::2], x[..., 1::2, 1::2]], 1))

into a slice operation with steps.

The easiest way to eliminate the slice operation is to change this line into:

return self.conv(torch.cat([x,x,x,x], 1))

It is also possible to change this operation into a convolution operation.

sunnyden avatar Jun 28 '20 08:06 sunnyden

ONNX converts the operation of line 87 in common.py

return self.conv(torch.cat([x[..., ::2, ::2], x[..., 1::2, ::2], x[..., ::2, 1::2], x[..., 1::2, 1::2]], 1))

into a slice operation with steps.

The easiest way to eliminate the slice operation is to change this line into:

return self.conv(torch.cat([x,x,x,x], 1))

It is also possible to change this operation into a convolution operation.

Thanks a lot

huolianchu avatar Jun 28 '20 08:06 huolianchu

Hi, Can I remove slice operation for trained model? I have trained my custom dataset, and converted it to pytorchscript. But the result is afwul (all boxes are wrong). Can I use models/onnx_export.py from ultralytics for my model and remove slice operation without retraining? Thank you so much

tadejj avatar Jul 09 '20 08:07 tadejj

Of course, you can remove the slice operation without retraining.

On Thu, Jul 9, 2020, 16:17 tadejj [email protected] wrote:

Hi, Can I remove slice operation for trained model? I have trained my custom dataset, and converted it to pytorchscript. But the result is afwul (all boxes are wrong). Can I use models/onnx_export.py from ultralytics for my model and remove slice operation without retraining? Thank you so much

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/sunnyden/YOLOV5_NCNN_Android/issues/2#issuecomment-655981291, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABA7OF5ZBMCCCBZNXUXWFPTR2V4JDANCNFSM4OGM3S4A .

sunnyden avatar Jul 10 '20 01:07 sunnyden

Of course, you can remove the slice operation without retraining. On Thu, Jul 9, 2020, 16:17 tadejj @.***> wrote: Hi, Can I remove slice operation for trained model? I have trained my custom dataset, and converted it to pytorchscript. But the result is afwul (all boxes are wrong). Can I use models/onnx_export.py from ultralytics for my model and remove slice operation without retraining? Thank you so much — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#2 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABA7OF5ZBMCCCBZNXUXWFPTR2V4JDANCNFSM4OGM3S4A .

Thanks a lot!

tadejj avatar Jul 13 '20 06:07 tadejj