Skip to content

using-executorch-android.md: Use an easier example #10029

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

Merged
merged 1 commit into from
Apr 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions docs/source/using-executorch-android.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 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)
Expand Down
Loading