A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
Hello @mc ,
The error occurred due to the following line of code in your MainActivity.cs file:
private readonly InferenceSession _session = new InferenceSession("");
because InferenceSession() requires a valid model path, and "" is not a valid path.
Suggested fix:
var modelPath = Path.Combine(CacheDir.AbsolutePath, "all-MiniLM-L6-v2.onnx"); // replace with your model file name
using (var modelStream = Assets.Open("models/all-MiniLM-L6-v2.onnx")) // replace with the actual asset path
using (var modelFile = File.Create(modelPath))
{
modelStream.CopyTo(modelFile);
}
_session = new InferenceSession(modelPath);
Note 1: While this is not directly related to the reported error, the path used for the vocabulary file also appears to be incorrect. Since the file is located under the Models folder, you should update the reference from vocab.txt to Models/vocab.txt.
Note 2: ONNX Runtime can only load ONNX models (.onnx). If your project contains an Apple Core ML model (.mlmodel), it cannot be loaded through InferenceSession. In that case, you would need to use an ONNX version of the model instead.
If you found my response helpful or informative, I would greatly appreciate it if you could follow this guide for your confirmation. Thank you.