MediaPipeUnityPlugin icon indicating copy to clipboard operation
MediaPipeUnityPlugin copied to clipboard

Add an model source dropdown option for using Application.persistentDataPath

Open Wayne-nulitics opened this issue 1 year ago • 4 comments

Feature Description

Currently the only way to load model files via the ResourceManager is

  • Streaming Assets
  • Asset Bundle
  • Local The latter does not work outside of Editor and I have a requirement to dynamically swap or switch model files at runtime, we place all the model files in the Application.persistentDataPath folder and and would like to load them from there. I can't change StreamingAssets content post build and Asset Bunbles is not an option as these devices don't have public internet access. If you can give me an example of how, similar to Streaming Assets, I can load the files from Application.persistentDataPath as opposed to Application.streamingAssetsPath that would be appriciated.

Current Behaviour/State

I can't get the hand tracking model files to load from Application.streamingAssetsPath in a Android device Even if I can, I need to be able to dynamically update, during runtime, the model files or .byte s files

Additional Context

No response

Wayne-nulitics avatar Dec 21 '23 04:12 Wayne-nulitics

we place all the model files in the Application.persistentDataPath folder

as these devices don't have public internet access.

How do you place them? In other words, how do you get those models and save under Application.persistentDataPath? If the assetPath in the following code is a URL, can this issue be resolved? https://github.com/homuler/MediaPipeUnityPlugin/blob/d495193dd7081142d1a19c9f171b0d0bcccaaa1e/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/ResourceManager/StreamingAssetsResourceManager.cs#L92-L93

homuler avatar Dec 21 '23 15:12 homuler

We currently use OpenCV but I want to move over to MediaPipe, we have self trained / custom models, currently in .onnx format that you can upload to a server, we then use: string filePath = Path.Combine (Application.persistentDataPath, "ML",directory, fileName); if (File.Exists(filePath)) File.Delete(filePath); using (UnityWebRequest www = UnityWebRequest.Get(url)) { if (StaticClass.SelfSignedCertificate) www.certificateHandler = new AcceptAllCertificatesSignedWithASpecificKeyPublicKey(); www.downloadHandler = new DownloadHandlerFile (filePath); UnityWebRequestAsyncOperation request = www.SendWebRequest(); }

So I assume your example will work, I just find it difficult to debug/trace your code with all the overides It would be great if you can give a simple example like the tutorial on how to do a new ResourceManager that points to a Application.persistentDataPath

Wayne-nulitics avatar Dec 21 '23 18:12 Wayne-nulitics

It would be great if you can give a simple example like the tutorial on how to do a new ResourceManager

For now, LocalResourceManager is the simplest example.

That being said, it is not ideal for library users to have to inherit the class and implements abstract methods, so I will make the ResourceManager simpler.

homuler avatar Dec 22 '23 04:12 homuler

LocalResourceManager does not work in Android builds, only in Editor, I tried to re-work it but get errors from the graph as soon as it runs, I'll post those if needed, the .bytes file loads fine, it seems, till the graph needs to read, I just don't understand why it will work in Editor but not runtime.

Can it not just be as simple as doing: var filepath = Path.Combine(Application.persistentDataPath,"folder","filename"); _resourceManager = new LocalsResourceManager(); yield return _resourceManager.PrepareAssetAsync(filepath);

Wayne-nulitics avatar Dec 22 '23 05:12 Wayne-nulitics