Question by
MarcDed · Jan 24, 2021 at 01:23 PM ·
unityeditorvisual studio
How to correctly create an onnx model in unity project and deploy it to hololens?
I have an unity project that makes use of an onnx file to recognize objects. The problem is that the model is not created, and I always end up in the catch of ONNXModelHelper.cs
script where it tells me: Model not created. Here are the pieces of code:
ONNXModel:
public sealed class ONNXModel
{
private LearningModel _learningModel = null;
private LearningModelSession _session;
public static async Task<ONNXModel> CreateOnnxModel(StorageFile file)
{
LearningModel learningModel = null;
try
{
learningModel = await LearningModel.LoadFromStorageFileAsync(file);
}
catch (Exception e)
{
var exceptionStr = e.ToString();
Debug.WriteLine(exceptionStr);
throw e;
}
return new ONNXModel()
{
_learningModel = learningModel,
_session = new LearningModelSession(learningModel)
};
}
ONNXModelHelper:
public async Task LoadModelAsync()
{
ModifyText($"Loading {ModelFilename}... Patience");
try
{
TimeRecorder = Stopwatch.StartNew();
var modelFile = await StorageFile.GetFileFromApplicationUriAsync(
new Uri($"ms-appx:///Data/StreamingAssets/{ModelFilename}"));
Model = await ONNXModel.CreateOnnxModel(modelFile);
TimeRecorder.Stop();
ModifyText($"Loaded {ModelFilename}: Elapsed time: {TimeRecorder.ElapsedMilliseconds} ms");
}
catch (Exception ex)
{
ModifyText($"Model not created");
Model = null;
}
}
Does anyone know how I can solve the problem ?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613023910im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to solve PrecompiledAssemblyException? 0 Answers
After Git pull I get these error messages 2 Answers
Steps for/How to setup a base for "Game from ground-up without using Editor"? 0 Answers
Unity App on HoloLens2 does not work with new os-version 21H1 0 Answers
Why is my DialogueBoxObject not recognizing its dialogue? 0 Answers