deepjavalibrary / djl

An Engine-Agnostic Deep Learning Framework in Java
https://djl.ai
Apache License 2.0
4.13k stars 656 forks source link

no onnxruntime in java.library.path #2099

Closed iszhangsc closed 2 years ago

iszhangsc commented 2 years ago

Description

Caused by: java.lang.UnsatisfiedLinkError: no onnxruntime in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867) ~[na:1.8.0_181] at java.lang.Runtime.loadLibrary0(Runtime.java:870) ~[na:1.8.0_181] at java.lang.System.loadLibrary(System.java:1122) ~[na:1.8.0_181] at ai.onnxruntime.OnnxRuntime.load(OnnxRuntime.java:338) ~[onnxruntime_gpu-1.12.1.jar:1.12.1] at ai.onnxruntime.OnnxRuntime.init(OnnxRuntime.java:139) ~[onnxruntime_gpu-1.12.1.jar:1.12.1] at ai.onnxruntime.OrtEnvironment.(OrtEnvironment.java:29) ~[onnxruntime_gpu-1.12.1.jar:1.12.1] at ai.djl.onnxruntime.engine.OrtEngine.(OrtEngine.java:45) ~[onnxruntime-engine-0.15.0.jar:na] at ai.djl.onnxruntime.engine.OrtEngine.newInstance(OrtEngine.java:49) ~[onnxruntime-engine-0.15.0.jar:na] at ai.djl.onnxruntime.engine.OrtEngineProvider.getEngine(OrtEngineProvider.java:40) ~[onnxruntime-engine-0.15.0.jar:na] at ai.djl.engine.Engine.getEngine(Engine.java:177) ~[api-0.15.0.jar:na] at ai.djl.Model.newInstance(Model.java:98) ~[api-0.15.0.jar:na] at ai.djl.repository.zoo.BaseModelLoader.createModel(BaseModelLoader.java:187) ~[api-0.15.0.jar:na] at ai.djl.repository.zoo.BaseModelLoader.loadModel(BaseModelLoader.java:149) ~[api-0.15.0.jar:na] at ai.djl.repository.zoo.Criteria.loadModel(Criteria.java:166) ~[api-0.15.0.jar:na] at ai.djl.repository.zoo.ModelZoo.loadModel(ModelZoo.java:132) ~[api-0.15.0.jar:na] at com.deep.ai.yolo.YoloService.init(YoloService.java:71) ~[classes/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]

frankfliu commented 2 years ago

OnnxRuntime will try to extract shared library into temp directory at runtime. Looks like it failed, can you check the following:

  1. Check System.getProperty("java.io.tmpdir"), and see if it point to a valid path
  2. check the temp path is writable

You can also try to redirect the cache directory by setting system property to your own cache folder which is writable: `System.setProperty("onnxruntime.native.path", "/my_cache");

iszhangsc commented 2 years ago

OnnxRuntime will try to extract shared library into temp directory at runtime. Looks like it failed, can you check the following:

  1. Check System.getProperty("java.io.tmpdir"), and see if it point to a valid path
  2. check the temp path is writable

You can also try to redirect the cache directory by setting system property to your own cache folder which is writable: `System.setProperty("onnxruntime.native.path", "/my_cache");

I tried using System.setProperty("onnxruntime.native.path", "/Users/zhangshichang/.djl.ai/my_cache")。 However : Caused by: java.lang.RuntimeException: Failed to load onnx-runtime library at ai.onnxruntime.OrtEnvironment.(OrtEnvironment.java:27) ~[onnxruntime-1.10.0.jar:1.10.0] ... 49 common frames omitted Caused by: java.io.IOException: Native library 'onnxruntime' not found at /Users/zhangshichang/.djl.ai/my_cache/libonnxruntime.dylib at ai.onnxruntime.OnnxRuntime.load(OnnxRuntime.java:300) ~[onnxruntime-1.10.0.jar:1.10.0] at ai.onnxruntime.OnnxRuntime.init(OnnxRuntime.java:137) ~[onnxruntime-1.10.0.jar:1.10.0] at ai.onnxruntime.OrtEnvironment.(OrtEnvironment.java:25) ~[onnxruntime-1.10.0.jar:1.10.0] ... 49 common frames omitted

georgewei commented 2 years ago

Try add these dependencies in your pom.xml:

        <dependency>
            <groupId>ai.djl.onnxruntime</groupId>
            <artifactId>onnxruntime-engine</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>com.microsoft.onnxruntime</groupId>
                    <artifactId>onnxruntime</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.microsoft.onnxruntime</groupId>
            <artifactId>onnxruntime</artifactId>
            <version>1.12.1</version>
            <scope>runtime</scope>
        </dependency>
frankfliu commented 2 years ago
  1. Do you have any security manager or classloader configured for your JVM?
  2. Are you able to reproduce the issue on other machine?
  3. Can you debug your code and step into ai.onnxruntime.OnnxRuntime class
  4. Your log doesn't seem match your pom.xml file, your pom.xml is using CPU (I guess you try to use gpu), but the log showing you are using GPU jar file.
iszhangsc commented 2 years ago

thank! The onnxruntime of the gpu version I used earlier