Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an model source dropdown option for using Application.persistentDataPath #1077

Closed
Wayne-nulitics opened this issue Dec 21, 2023 · 4 comments · Fixed by #1210
Closed

Add an model source dropdown option for using Application.persistentDataPath #1077

Wayne-nulitics opened this issue Dec 21, 2023 · 4 comments · Fixed by #1210
Assignees
Labels
type:feature New feature or request

Comments

@Wayne-nulitics
Copy link

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 Wayne-nulitics added the type:feature New feature or request label Dec 21, 2023
@homuler
Copy link
Owner

homuler commented Dec 21, 2023

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?

var assetPath = GetAssetPathFor(assetName);
using (var webRequest = UnityWebRequest.Get(assetPath))

@Wayne-nulitics
Copy link
Author

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

@homuler
Copy link
Owner

homuler commented Dec 22, 2023

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 homuler self-assigned this Dec 22, 2023
@Wayne-nulitics
Copy link
Author

Wayne-nulitics commented Dec 22, 2023

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants