Sky-Kim's picture
Update ONNX Runtime to 1.27.0 / GenAI to 0.14.0 and add samples
74ab0d4
|
Raw
History Blame Contribute Delete
1.13 kB

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

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();