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

Extracting local model ZIP multiple times #3025

Closed
StefanOltmann opened this issue Mar 11, 2024 · 3 comments · Fixed by #3026
Closed

Extracting local model ZIP multiple times #3025

StefanOltmann opened this issue Mar 11, 2024 · 3 comments · Fixed by #3026
Labels
bug Something isn't working

Comments

@StefanOltmann
Copy link
Contributor

I specified the model to be loaded from a ZIP:

    val criteria =
        Criteria.builder()
            .setTypes(Image::class.java, DetectedObjects::class.java)
            .optModelUrls("jar:/META-INF/models/retinaface.zip")
            .optModelName("retinaface")
            .optTranslator(translator)
            .optProgress(ProgressBar())
            .optEngine("PyTorch")
            .build()

What really happens is that it gets extracted to users home into .djl.ai/cache/repo/model/undefined/ai/djl/localmodelzoo.

The problem is that I noticed that after some updates of my app I got multiple subfolders with random names that all contain the same retinaface.zip:

.djl.ai/cache/repo/model/undefined/ai/djl/localmodelzoo/eb340bf40259987587ddb6d57cef4d11080c1554
.djl.ai/cache/repo/model/undefined/ai/djl/localmodelzoo/eb340bf40259987587ddb6d57cef4d11080c1554/retinaface.pt
.djl.ai/cache/repo/model/undefined/ai/djl/localmodelzoo/6a64f34b02433288b2fd5691998e4d849ef955f1
.djl.ai/cache/repo/model/undefined/ai/djl/localmodelzoo/6a64f34b02433288b2fd5691998e4d849ef955f1/retinaface.pt
.djl.ai/cache/repo/model/undefined/ai/djl/localmodelzoo/82d7a6a140da73236f584914be3a6c50d27a1dd7
.djl.ai/cache/repo/model/undefined/ai/djl/localmodelzoo/82d7a6a140da73236f584914be3a6c50d27a1dd7/retinaface.pt

How can I stop this behavior?

@StefanOltmann StefanOltmann added the bug Something isn't working label Mar 11, 2024
@frankfliu
Copy link
Contributor

frankfliu commented Mar 11, 2024

The model's cache folder is a hash of real jar URL. For example, if your program generate the jar file in the following path: /source/my_app/build/libs/my_app-0.27.0-SNAPSHOT.jar, the URL will be: jar:file:/source/my_app/build/libs/my_app-0.27.0-SNAPSHOT.jar!/META-INF/models/retinaface.zip. You got different hash is because, the jar file name (or location) changed 3 times during your development. Did you bump up application version?

@StefanOltmann
Copy link
Contributor Author

Yes, with each release I bump up the version.

Can I control where it will be extracted?

This hash will result in additional 100 MB retinaface.pt with every update of my app. That’s not good.

@frankfliu
Copy link
Contributor

@StefanOltmann
I created a PR to use relative jar uri to generate hash. You can use the following model url to avoid multiple cache folder:

.optModelUrls("jar:/META-INF/models/retinaface.zip?ignore_real_uri=true")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants