Fail to load sentis model

I got this error when I try to load sentis model, which is downloaded from hugging face, the musicGen example( unity/sentis-MusicGen · Hugging Face:
my sentis version is 2.0.0

Invalid model: , msg: System.ArgumentException: Path is empty
  at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x00027] in <17d9ce77f27a4bd2afb5ba32c9bea976>:0 
  at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) [0x00000] in <17d9ce77f27a4bd2afb5ba32c9bea976>:0 
  at (wrapper remoting-invoke-with-check) System.IO.FileStream..ctor(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
  at System.IO.File.Open (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) [0x00000] in <17d9ce77f27a4bd2afb5ba32c9bea976>:0 
  at System.IO.File.Open (System.String path, System.IO.FileMode mode) [0x00000] in <17d9ce77f27a4bd2afb5ba32c9bea976>:0 
  at Unity.Sentis.ModelLoader.Load (System.String path) [0x00001] in .\Library\PackageCache\com.unity.sentis@2.0.0\Runtime\Core\Serialization\ModelLoader.cs:44 
  at MuseSentisNodeView.<Enable>b__3_0 (UnityEngine.UIElements.ChangeEvent`1[T] v) [0x0001f] in .\Packages\UnitySDGraph\Editor\Views\MuseViews\MuseSentisNodeView.cs:48 
UnityEngine.Debug:LogError (object)
MuseSentisNodeView:<Enable>b__3_0 (UnityEngine.UIElements.ChangeEvent`1<UnityEngine.Object>) (at ./Packages/UnitySDGraph/Editor/Views/MuseViews/MuseSentisNodeView.cs:55)
UnityEditor.EditorApplication:Internal_CallDelayFunctions ()


Failed to load serialized Sentis model, ensure model was exported with Sentis 1.4 or newer. (Specified argument was out of the range of valid values.)
UnityEngine.Debug:LogError (object)
Unity.Sentis.D:LogError (object) (at ./Library/PackageCache/com.unity.sentis@2.0.0/Runtime/Core/Internals/Debug.cs:131)
Unity.Sentis.ModelLoader:Load (System.IO.Stream) (at ./Library/PackageCache/com.unity.sentis@2.0.0/Runtime/Core/Serialization/ModelLoader.cs:82)
Unity.Sentis.ModelLoader:Load (string) (at ./Library/PackageCache/com.unity.sentis@2.0.0/Runtime/Core/Serialization/ModelLoader.cs:45)
MuseSentisNodeView:<Enable>b__3_0 (UnityEngine.UIElements.ChangeEvent`1<UnityEngine.Object>) (at ./Packages/UnitySDGraph/Editor/Views/MuseViews/MuseSentisNodeView.cs:48)
UnityEditor.EditorApplication:Internal_CallDelayFunctions ()

Unfortunately that sample is only compatible with Sentis 1.3, from Sentis 1.4 we introduced a new serialization scheme. We will try and get round to updating the demo when we have time.

1 Like

Hello, will Unity Sentis continue to develop the model serialization feature? I’m currently using Sentis version 2.1.3, but I still get the error ‘Failed to load serialized Sentis model, ensure model was exported with Sentis 1.4 or newer’ when loading serialized models.

What is the source of your model you are loading?

My model name is tflite_f16_quantized. I’m trying to load this file on an Android device through StreamingAssets. Since Android devices cannot directly access the StreamingAssets directory, I’m using UnityWebRequest to get the content and store it in a MemoryStream, then using ModelLoader.Load with the stream loading method. However, I’m getting a Sentis version error.

Loading the ModelAsset directly works fine.

So you quantized the model yourself from the same version of Sentis as you are loading from? And the same .sentis file works if you load from the editor, it only fails if you load through a memory stream?

I can directly load the ONNX model as a ModelAsset and it works. However, when I load the serialized Sentis model of this ONNX model, I get an error about the Sentis version. I used the same version of Sentis for both serialization and usage. I’ve only tested it on Android devices. I’ll test other platforms tomorrow to see if there’s the same problem.

On the PC side, I can directly use ModelLoader.Load with the StreamingAssets path to read and use the serialized model normally. However, on the Android side, since Android cannot directly access files in StreamingAssets, I use UnityWebRequest’s downloadHandler.text to fetch the model, convert it into a byte[] array, and store it in a MemoryStream. Finally, when using ModelLoader.Load to read this memory stream, it produces the error I mentioned earlier. Could you provide a correct example of the loading method for the Android platform?*

You need to download the raw data rather than text. Can you use downlodHandler.data and deserialize that instead?

Thanks. I’ll go and give it a try.