-
Notifications
You must be signed in to change notification settings - Fork 4.2k
[android][recipe] Making android native app using torchscript model with custom op #1041
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
[android][recipe] Making android native app using torchscript model with custom op #1041
Conversation
Fix allreduce implmentation in tutorial
Signed-off-by: Edward Z. Yang <ezyang@fb.com>
- Don't clean before running html-noplot (if you want to do a clean build, just run make clean yourself!) - Replace filename_pattern with ignore_pattern (with a negative lookahead assertion). This means that specifying a GALLERY_PATTERN will also skip parsing all Python files that you don't care about. This saves several seconds from the no-op doc build. - Use distutils to only copy rst files if the mtime is newer than the destination; this (probably) helps Sphinx avoid recompiling these files when it's useless. There are some semantic changes in this diff which is why I'm putting it up for review. Signed-off-by: Edward Z. Yang <ezyang@fb.com>
Reduce amount of unnecessary recompilation done by sphinx
|
||
- OpenCV SDK for Android | ||
|
||
Our custom operator will be implemented using the OpenCV library. To use it for android, we need to download OpenCV SDK for Android with prebuilt libraries. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Capitalize "android"
Making Android Application | ||
========================== | ||
|
||
After we succeeded in having ``compute.pt``, we want to use this TorchScript model within android application. Using general TorchScript models (without custom operators) on Android, using java API, you can find `here <https://pytorch.org/mobile/android/>`_. We can not use this approach for our case, as our model uses a custom operator(``my_ops.warp_perspective``), default TorchScript execution will fail to find it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Capitalize "java"
|
||
After we succeeded in having ``compute.pt``, we want to use this TorchScript model within android application. Using general TorchScript models (without custom operators) on Android, using java API, you can find `here <https://pytorch.org/mobile/android/>`_. We can not use this approach for our case, as our model uses a custom operator(``my_ops.warp_perspective``), default TorchScript execution will fail to find it. | ||
|
||
Registration of ops is not exposed to PyTorch java API, thus we need to build Android Application with native part (C++) and using LibTorch C++ API to implement and register the same custom operator for Android. As our operator uses the OpenCV library - we will use prebuilt OpenCV Android libraries and use the same functions from OpenCV. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Capitalize "java"
Android Application Manifest | ||
============================ | ||
|
||
Every android application has a manifest. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Capitalize "android"
} | ||
} | ||
|
||
``NativePeer#loadAndForwardModel`` is declared as ``native``, it does not have definition in java. Call to this method will beredispatched through jni to C++ method in our ``libpytorch_nativeapp.so``, in ``NativeApp/app/src/main/cpp/pytorch_nativeapp.cpp``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add space: "beredispatched" -> "be re-dispatched"
Capitalize "jni" -> "JNI"
|
||
|
||
|
||
The full setup of this app you can find in `PyTorch Android Demo Application Repository <https://github.com/pytorch/android-demo-app/tree/master/NativeApp>`_. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommend to also add this line at the beginning of the recipe for users to download and follow along from the start.
- How to use within this application TorchScript models with custom operators. | ||
|
||
Setup | ||
===== |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Recommend not to use the same header level === for sub-headers as is currently used for the title.
33e2a77
to
fc41a1d
Compare
fc41a1d
to
8e4e379
Compare
Deploy preview for pytorch-tutorials-preview ready! Built with commit a79c227 https://deploy-preview-1041--pytorch-tutorials-preview.netlify.app |
More condensed setup information and result application setup is here:
pytorch/android-demo-app#73