From 313821f99cd683f5e555db4e33c40b86e0b06e43 Mon Sep 17 00:00:00 2001 From: Hansong <107070759+kirklandsign@users.noreply.github.com> Date: Wed, 9 Apr 2025 13:43:40 -0700 Subject: [PATCH 1/2] using-executorch-android.md: Use an easier example And it's working without additional requirements! --- docs/source/using-executorch-android.md | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/docs/source/using-executorch-android.md b/docs/source/using-executorch-android.md index f1a18ba4ae4..8d9e14e6e8f 100644 --- a/docs/source/using-executorch-android.md +++ b/docs/source/using-executorch-android.md @@ -172,18 +172,22 @@ public class MainActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Load the ExecuTorch module - module = Module.load("/path/to/module.pte"); - } - public void runInference(View view) { - // Prepare input data - Tensor input = Tensor.fromBlob(getInputData()); - // Run inference - Tensor output = module.forward(EValue.from(input))[0].toTensor(); - // Process output data - processOutput(output); + module = Module.load("/data/local/tmp/add.pte"); + Tensor tensor1 = Tensor.fromBlob(new float[] {1.0f}, new long[] {1}); + Tensor tensor2 = Tensor.fromBlob(new float[] {20.0f}, new long[] {1}); + + EValue eValue1 = EValue.from(tensor1); + EValue eValue2 = EValue.from(tensor2); + float result = module.forward(eValue1, eValue2)[0].toTensor().getDataAsFloatArray()[0]; } } ``` + +Push the corresponding pte file to the phone: +```sh +adb push extension/module/test/resources/add.pte /data/local/tmp/ +``` + This example loads an ExecuTorch module, prepares input data, runs inference, and processes the output data. Please use [DeepLabV3AndroidDemo](https://github.com/pytorch-labs/executorch-examples/tree/main/dl3/android/DeepLabV3Demo) From 1f5a326e13e6f93ffdb57585c3408023d501adf4 Mon Sep 17 00:00:00 2001 From: Hansong <107070759+kirklandsign@users.noreply.github.com> Date: Wed, 9 Apr 2025 13:45:37 -0700 Subject: [PATCH 2/2] Update using-executorch-android.md --- docs/source/using-executorch-android.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/using-executorch-android.md b/docs/source/using-executorch-android.md index 8d9e14e6e8f..4528de55219 100644 --- a/docs/source/using-executorch-android.md +++ b/docs/source/using-executorch-android.md @@ -172,7 +172,7 @@ public class MainActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Load the ExecuTorch module - module = Module.load("/data/local/tmp/add.pte"); + Module module = Module.load("/data/local/tmp/add.pte"); Tensor tensor1 = Tensor.fromBlob(new float[] {1.0f}, new long[] {1}); Tensor tensor2 = Tensor.fromBlob(new float[] {20.0f}, new long[] {1});