You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The outputs can then be analyzed by inspecting the values inside the `output` list of numpy arrays.
297
296
298
-
The full code is available [here](mnist.py). It finds that `0` is the most likely digit for the given input. The command is:
297
+
The full code is available [here](mnist-runPyRuntime.py). It finds that `0` is the most likely digit for the given input. The command is:
299
298
300
299
```shell
301
-
./mnist.py
300
+
./mnist-runPyRuntime.py
302
301
```
303
302
304
303
and produces an output similar to the following (you may see slightly different prediction numbers if you train the model yourself):
@@ -321,6 +320,22 @@ prediction 9 = 8.650948e-15
321
320
The digit is 0
322
321
```
323
322
323
+
We provide two additional Python interfaces.
324
+
The second interface extends the above execution session by simply compiling a model before loading it for execution (see [here](mnist-runPyCompileAndRuntime.py)).
325
+
The user simply passes the `.onnx` model and the flags needed to compile the model.
326
+
Unless explicitly disabled by the `reuse_compiled_model=0`, the execution session will reuse a previously compiled model whose name matches the name the output file generated by the compiler.
327
+
Note that the execution session does not check if the cached version was compiled using identical compiler flags; it is the responsibility of the user to then clear the cached version, or disable the reuse using the provided optional flag.
328
+
329
+
For example, the code below will compile and load the `mnist.onnx` model, compiling only when the `mnist2.so` binary file cannot be located. Model inference can then proceed using the `session.run(...)` command.
330
+
331
+
```Python
332
+
# Load onnx model and create CompileExecutionSession object,
333
+
# by first compiling the mnist.onnx model with the "-O3" options.
The third interface provides a simple interface to explicitly compile an onnx model (see [here](mnist-compile.py)).
338
+
324
339
## Write a Java Driver Code
325
340
326
341
Inference APIs and data structures for Java closely mirror those for C/C++. Documentation of the APIs are found [here](https://onnx.ai/onnx-mlir/doxygen_html/OMModel_java/classcom_1_1ibm_1_1onnxmlir_1_1_o_m_model.html), with the Java interface for Tensor [here](https://onnx.ai/onnx-mlir/doxygen_html/OMTensor_java/classcom_1_1ibm_1_1onnxmlir_1_1_o_m_tensor.html) and TensorList [here](https://onnx.ai/onnx-mlir/doxygen_html/OMTensorList_java/classcom_1_1ibm_1_1onnxmlir_1_1_o_m_tensor_list.html).
0 commit comments