Skip to content

Commit a1af1ff

Browse files
authored
using-executorch-android.md: Use an easier example (#10008)
And it's working without additional requirements!
1 parent 20c7047 commit a1af1ff

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

docs/source/using-executorch-android.md

+13-9
Original file line numberDiff line numberDiff line change
@@ -172,18 +172,22 @@ public class MainActivity extends Activity {
172172
protected void onCreate(Bundle savedInstanceState) {
173173
super.onCreate(savedInstanceState);
174174
// Load the ExecuTorch module
175-
module = Module.load("/path/to/module.pte");
176-
}
177-
public void runInference(View view) {
178-
// Prepare input data
179-
Tensor input = Tensor.fromBlob(getInputData());
180-
// Run inference
181-
Tensor output = module.forward(EValue.from(input))[0].toTensor();
182-
// Process output data
183-
processOutput(output);
175+
Module module = Module.load("/data/local/tmp/add.pte");
176+
Tensor tensor1 = Tensor.fromBlob(new float[] {1.0f}, new long[] {1});
177+
Tensor tensor2 = Tensor.fromBlob(new float[] {20.0f}, new long[] {1});
178+
179+
EValue eValue1 = EValue.from(tensor1);
180+
EValue eValue2 = EValue.from(tensor2);
181+
float result = module.forward(eValue1, eValue2)[0].toTensor().getDataAsFloatArray()[0];
184182
}
185183
}
186184
```
185+
186+
Push the corresponding pte file to the phone:
187+
```sh
188+
adb push extension/module/test/resources/add.pte /data/local/tmp/
189+
```
190+
187191
This example loads an ExecuTorch module, prepares input data, runs inference, and processes the output data.
188192

189193
Please use [DeepLabV3AndroidDemo](https://github.com/pytorch-labs/executorch-examples/tree/main/dl3/android/DeepLabV3Demo)

0 commit comments

Comments
 (0)