Hi everyone,
I would like to use an onnx file external to the build so I can update it remotely without republishing the app (iOS and Android). ONNX works perfectly if I import it into Unity with drag and drop. So I’m 100% sure the problem is not the file. What I do? I download the file via a UnityWebRequest like this:
using (UnityWebRequest request = UnityWebRequest.Get(URL_Model))
{
yield return request.SendWebRequest();
if (request.result != UnityWebRequest.Result.Success)
{
Debug.LogError("Failed to download file: " + request.error);
}
else
{
string filePath = Application.persistentDataPath + "/model.onnx";
File.WriteAllBytes(filePath, request.downloadHandler.data);
}
}
And then, on the model I downloaded locally I do this to convert it in runtime:
ModelAsset asset = new ModelAsset
{
name = "opere_converted_pretrained",
modelAssetData = new ModelAssetData(),
};
var ONNXPath = Application.persistentDataPath + "/model.onnx";
Unity.Sentis.ONNX.ONNXModelConverter onnx = new ONNXModelConverter(true, ONNXPath);
Model model = onnx.Convert();
using (var memoryStream = new MemoryStream())
using (var writer = new BinaryWriter(memoryStream))
{
ModelWriter.Save(writer.BaseStream, model);
byte[] bbb = memoryStream.ToArray();
asset.modelAssetData.value = bbb;
kerasModel = asset;
}
In the inspector it’s 100% identical to the dragged onnx into Unity.
But if I try to console log some value modelWeightsChunks and modelAssetData :
modelWeightsChunks0: 5926022
modelAssetData(Unity): 26307
modelWeightsChunks(Converted ONNX from Online): null
modelAssetData(Converted ONNX from Online): 59286535
Any one have a solution?
