Skip to content
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

Add ncnn deployment examples #145

Merged
merged 14 commits into from
Jul 30, 2021
Merged

Add ncnn deployment examples #145

merged 14 commits into from
Jul 30, 2021

Conversation

zhiqwang
Copy link
Owner

@zhiqwang zhiqwang commented Jul 22, 2021

  • Add ONNX export tools
  • Add ncnn C++ inference examples
  • Add ncnn Python inference examples

@codecov
Copy link

codecov bot commented Jul 22, 2021

Codecov Report

Merging #145 (d941d94) into master (947956f) will increase coverage by 0.15%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #145      +/-   ##
==========================================
+ Coverage   84.34%   84.49%   +0.15%     
==========================================
  Files          11       12       +1     
  Lines         811      819       +8     
==========================================
+ Hits          684      692       +8     
  Misses        127      127              
Flag Coverage Δ
unittests 84.49% <100.00%> (+0.15%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
test/test_models_common.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 947956f...d941d94. Read the comment docs.

@zhiqwang zhiqwang added the deployment Inference acceleration for production label Jul 23, 2021
@zhiqwang zhiqwang added the enhancement New feature or request label Jul 26, 2021
Comment on lines +171 to +178
Reshape Reshape_259 1 1 671 689 0=-1 1=85 2=3
Permute Transpose_260 1 1 689 h1 0=1
Convolution Conv_261 1 1 644_splitncnn_0 691 0=255 1=1 5=1 6=65280
Reshape Reshape_275 1 1 691 709 0=-1 1=85 2=3
Permute Transpose_276 1 1 709 h2 0=1
Convolution Conv_277 1 1 670 711 0=255 1=1 5=1 6=130560
Reshape Reshape_291 1 1 711 729 0=-1 1=85 2=3
Permute Transpose_292 1 1 729 h3 0=1
Copy link
Owner Author

@zhiqwang zhiqwang Jul 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exported natively by ncnnoptimize is

Reshape                  Reshape_259              1 1 671 689 0=6400 1=-1 2=3
Permute                  Transpose_260            1 1 689 h1 0=1
Convolution              Conv_261                 1 1 644_splitncnn_0 691 0=255 1=1 5=1 6=65280
Reshape                  Reshape_275              1 1 691 709 0=1600 1=-1 2=3
Permute                  Transpose_276            1 1 709 h2 0=1
Convolution              Conv_277                 1 1 670 711 0=255 1=1 5=1 6=130560
Reshape                  Reshape_291              1 1 711 729 0=400 1=-1 2=3
Permute                  Transpose_292            1 1 729 h3 0=1

7767517
176 200
Input images 0 1 images
YOLOv5Focus focus 1 1 images 401
Copy link
Owner Author

@zhiqwang zhiqwang Jul 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exported natively by onnx2ncnn is

185 212
Input            images                   0 1 images
Split            splitncnn_input0         1 4 images images_splitncnn_0 images_splitncnn_1 images_splitncnn_2 images_splitncnn_3
Crop             Slice_4                  1 1 images_splitncnn_3 365 -23309=1,0 -23310=1,2147483647 -23311=1,1
Crop             Slice_9                  1 1 365 370 -23309=1,0 -23310=1,2147483647 -23311=1,2
Crop             Slice_14                 1 1 images_splitncnn_2 375 -23309=1,1 -23310=1,2147483647 -23311=1,1
Crop             Slice_19                 1 1 375 380 -23309=1,0 -23310=1,2147483647 -23311=1,2
Crop             Slice_24                 1 1 images_splitncnn_1 385 -23309=1,0 -23310=1,2147483647 -23311=1,1
Crop             Slice_29                 1 1 385 390 -23309=1,1 -23310=1,2147483647 -23311=1,2
Crop             Slice_34                 1 1 images_splitncnn_0 395 -23309=1,1 -23310=1,2147483647 -23311=1,1
Crop             Slice_39                 1 1 395 400 -23309=1,1 -23310=1,2147483647 -23311=1,2
Concat           Concat_40                4 1 370 380 390 400 401 0=0

@@ -170,6 +170,15 @@ def focus_transform(x: Tensor) -> Tensor:
return y


def space_to_depth(x: Tensor) -> Tensor:
Copy link
Owner Author

@zhiqwang zhiqwang Jul 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use this function yet, but we'll put it here for now and see how to call this part later, or do some experiments with it.

cc @xiguadong

@zhiqwang
Copy link
Owner Author

The whole process of exporting PyTorch to ONNX and then to ncnn is currently a bit cumbersome. We have verified the feasibility of the whole process in this PR, and we will continue to explore whether we can simplify the process next. For now, I'm merging this branch to facilitate the subsequent work.

@zhiqwang
Copy link
Owner Author

zhiqwang commented Jul 30, 2021

The whole work is just in the beginning of deploying yolort with ncnn. If you have some new ideas, you can add them to this thread as well.

cc @xiguadong .

@zhiqwang zhiqwang merged commit f34194c into master Jul 30, 2021
@zhiqwang zhiqwang deleted the ncnn-deployment branch July 30, 2021 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployment Inference acceleration for production enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants