How to import model from a sub-folder of Assets

Hi there,
Thank you for this great project!
I want to import a model file (onnx) from a sub-folder of Assets, more specifically Assets/StreamingAssets.
How can I do that?
Thank you!

I think the following works:

  • copy the onnx model inside the Assets folder
  • serialise it to the StreamingAssets folder so that it becomes a .sentis model
  • delete the onnx model in the Assets folder
1 Like
var model = Resources.Load<ModelAsset>(assetName);

Thank you for the reply!
It doesn’t seem to work with version 1.2.0-exp.2.
I have tried the following variants but they are all null:

var modelAsset = Resources.Load<ModelAsset>("Assets/StreamingAssets/model.onnx");
var modelAsset = Resources.Load<ModelAsset>("StreamingAssets/model.onnx");
var modelAsset = Resources.Load<ModelAsset>("model.onnx");
var modelAsset = Resources.Load<ModelAsset>("model");
var modelAsset = Resources.Load<ModelAsset>("Assets/StreamingAssets/model.sentis");
var modelAsset = Resources.Load<ModelAsset>("StreamingAssets/model.sentis");
var modelAsset = Resources.Load<ModelAsset>("model.sentis");

Resources.Load only works for the Resources folder

For StreamingAssets you can use something like this

string path = Path.Combine(Application.streamingAssetsPath, "your_model.sentis");
Model m = ModelLoader.Load(path);

But I’m not sure this will work on Android/WebGL as you’ll have to use WebRequests to access StreamingAssets: Unity - Manual: Streaming Assets

Thank you for the answers!
Yes ModelLoader.Load works, but if I copy a file to the StreamingAssets folder it isn’t being converted to sentis format.
This is probably because StreamingAssets bypass Unity’s import pipeline.

Correct that’s why we recommend to put large (per-imported) models there.
Make sure to serialize your model first and then put the serialized .sentis file there to be able to load it

1 Like