File size: 1,130 Bytes
74ab0d4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | # Basic Inference
The quickest way to confirm ONNX Runtime is working in your project.
## What it does
Loads a tiny (185-byte) ONNX model that is **embedded directly in the script**
(no `.onnx` file, no download) and runs it. The model computes, element-wise:
```
output = input * 2 + 1
```
With `input = [1, 2, 3]` the expected `output` is `[3, 5, 7]`.
## How to run
1. Import this sample from the Package Manager (**ONNX Runtime → Samples → Basic
Inference → Import**).
2. Create an empty GameObject in a scene and add the **Basic Inference Sample**
component (`BasicInferenceSample`).
3. Enter Play Mode and check the **Console**:
```
[ONNX Runtime] input = [1, 2, 3]
[ONNX Runtime] output = [3, 5, 7] (expected [3, 5, 7])
[ONNX Runtime] Basic inference succeeded ✅
```
## Key API
```csharp
using var session = new InferenceSession(modelBytes);
var inputs = new List<NamedOnnxValue>
{
NamedOnnxValue.CreateFromTensor("input", new DenseTensor<float>(data, new[] { 1, 3 }))
};
using var results = session.Run(inputs);
float[] output = results.First().AsTensor<float>().ToArray();
```
|