deepjavalibrary / djl

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

ModelZoo doesn't support specified engine: TensorFlow #2267

Closed chupee120 closed 1 year ago

chupee120 commented 1 year ago

Description

I run java class ai.djl.examples.inference.ObjectDetectionWithTensorflowSavedModel but I have an error:

ModelZoo doesn't support specified engine: TensorFlow

Expected Behavior

Program run successfully

Error Message

/Users/King/Library/Java/JavaVirtualMachines/openjdk-19.0.1/Contents/Home/bin/java -javaagent:/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar=50101:/Applications/IntelliJ IDEA CE.app/Contents/bin -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath /Users/King/github/tonyKing/ia/djl/djl/examples/target/classes:/Users/King/.m2/repository/ai/djl/pytorch/pytorch-engine/0.19.0/pytorch-engine-0.19.0.jar:/Users/King/.m2/repository/commons-cli/commons-cli/1.5.0/commons-cli-1.5.0.jar:/Users/King/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.18.0/log4j-slf4j-impl-2.18.0.jar:/Users/King/.m2/repository/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar:/Users/King/.m2/repository/org/apache/logging/log4j/log4j-api/2.18.0/log4j-api-2.18.0.jar:/Users/King/.m2/repository/org/apache/logging/log4j/log4j-core/2.18.0/log4j-core-2.18.0.jar:/Users/King/.m2/repository/ai/djl/api/0.21.0-SNAPSHOT/api-0.21.0-20221226.104327-24.jar:/Users/King/.m2/repository/com/google/code/gson/gson/2.10/gson-2.10.jar:/Users/King/.m2/repository/net/java/dev/jna/jna/5.12.1/jna-5.12.1.jar:/Users/King/.m2/repository/org/apache/commons/commons-compress/1.22/commons-compress-1.22.jar:/Users/King/.m2/repository/ai/djl/basicdataset/0.21.0-SNAPSHOT/basicdataset-0.21.0-20221226.104327-24.jar:/Users/King/.m2/repository/org/apache/commons/commons-csv/1.9.0/commons-csv-1.9.0.jar:/Users/King/.m2/repository/ai/djl/model-zoo/0.21.0-SNAPSHOT/model-zoo-0.21.0-20221226.104327-24.jar:/Users/King/.m2/repository/ai/djl/timeseries/timeseries/0.21.0-SNAPSHOT/timeseries-0.21.0-20221226.104327-24.jar:/Users/King/.m2/repository/tech/tablesaw/tablesaw-core/0.43.1/tablesaw-core-0.43.1.jar:/Users/King/.m2/repository/com/google/guava/guava/30.0-jre/guava-30.0-jre.jar:/Users/King/.m2/repository/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar:/Users/King/.m2/repository/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar:/Users/King/.m2/repository/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar:/Users/King/.m2/repository/org/checkerframework/checker-qual/3.5.0/checker-qual-3.5.0.jar:/Users/King/.m2/repository/com/google/errorprone/error_prone_annotations/2.3.4/error_prone_annotations-2.3.4.jar:/Users/King/.m2/repository/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar:/Users/King/.m2/repository/org/apache/commons/commons-math3/3.6.1/commons-math3-3.6.1.jar:/Users/King/.m2/repository/it/unimi/dsi/fastutil/8.3.0/fastutil-8.3.0.jar:/Users/King/.m2/repository/org/roaringbitmap/RoaringBitmap/0.9.25/RoaringBitmap-0.9.25.jar:/Users/King/.m2/repository/org/roaringbitmap/shims/0.9.25/shims-0.9.25.jar:/Users/King/.m2/repository/com/univocity/univocity-parsers/2.8.4/univocity-parsers-2.8.4.jar:/Users/King/.m2/repository/com/ibm/icu/icu4j/65.1/icu4j-65.1.jar:/Users/King/.m2/repository/io/github/classgraph/classgraph/4.8.60/classgraph-4.8.60.jar:/Users/King/.m2/repository/tech/tablesaw/tablesaw-jsplot/0.43.1/tablesaw-jsplot-0.43.1.jar:/Users/King/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.13.2.1/jackson-databind-2.13.2.1.jar:/Users/King/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.13.2/jackson-annotations-2.13.2.jar:/Users/King/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.13.2/jackson-core-2.13.2.jar:/Users/King/.m2/repository/io/pebbletemplates/pebble/3.1.2/pebble-3.1.2.jar:/Users/King/.m2/repository/org/unbescape/unbescape/1.1.6.RELEASE/unbescape-1.1.6.RELEASE.jar:/Users/King/.m2/repository/ai/djl/huggingface/tokenizers/0.21.0-SNAPSHOT/tokenizers-0.21.0-20221226.104327-24.jar:/Users/King/.m2/repository/ai/djl/mxnet/mxnet-model-zoo/0.21.0-SNAPSHOT/mxnet-model-zoo-0.21.0-20221226.104327-24.jar:/Users/King/.m2/repository/ai/djl/mxnet/mxnet-engine/0.21.0-SNAPSHOT/mxnet-engine-0.21.0-20221226.104327-24.jar:/Users/King/.m2/repository/ai/djl/pytorch/pytorch-model-zoo/0.21.0-SNAPSHOT/pytorch-model-zoo-0.21.0-20221226.104327-24.jar ai.djl.examples.inference.ObjectDetectionWithTensorflowSavedModel Exception in thread "main" ai.djl.repository.zoo.ModelNotFoundException: ModelZoo doesn't support specified engine: TensorFlow at ai.djl.repository.zoo.Criteria.loadModel(Criteria.java:121) at ai.djl.examples.inference.ObjectDetectionWithTensorflowSavedModel.predict(ObjectDetectionWithTensorflowSavedModel.java:97) at ai.djl.examples.inference.ObjectDetectionWithTensorflowSavedModel.main(ObjectDetectionWithTensorflowSavedModel.java:74)

Process finished with exit code 1

How to Reproduce?

(If you developed your own code, please provide a short script that reproduces the error. For existing examples, please provide link.)

Steps to reproduce

(Paste the commands you ran that produced the error.)

  1. Run ai.djl.examples.inference.ObjectDetectionWithTensorflowSavedModel

What have you tried to solve it?

1. 2.

Environment Info

MacOs 11.7.2

frankfliu commented 1 year ago

I'm not able to reproduce your issue. I didn't see tensorflow-engine-0.21.0.jar in your classpath. How you import the gradle project in your IntelliJ? I also noticed you are using 0.19.0 version of PyTorch engine. There must be something wrong with your project. Can you re-import the gradle project or refresh it?

You can also try to run the project in command line:

cd examples
./gradlew run -Dmain=ai.djl.examples.inference.ObjectDetectionWithTensorflowSavedModel

See document: https://github.com/deepjavalibrary/djl/blob/master/examples/docs/object_detection_with_tensorflow_saved_model.md

chupee120 commented 1 year ago

Thanks for your help.

I use maven to build project.

I've added tensorflow-engine dependency in pom.xml and now it works.

<dependency>
            <groupId>ai.djl.tensorflow</groupId>
            <artifactId>tensorflow-engine</artifactId>
            <version>0.20.0</version>
            <scope>runtime</scope>
 </dependency>

If I don't override version of pytorch engine to 0.19 in pom.xml I have an error trying to run SemanticSegmentation.

Maybe the issue is my old mac os version 11.7.2 but i can't update it as my mac is not compatible with mac os 12.

Loading: 100% |████████████████████████████████████████| [INFO ] - Downloading https://publish.djl.ai/pytorch/1.13.1/cpu/osx-x86_64/native/lib/libtorch_cpu.dylib.gz ... [INFO ] - Downloading https://publish.djl.ai/pytorch/1.13.1/cpu/osx-x86_64/native/lib/libiomp5.dylib.gz ... [INFO ] - Downloading https://publish.djl.ai/pytorch/1.13.1/cpu/osx-x86_64/native/lib/libtorch.dylib.gz ... [INFO ] - Downloading https://publish.djl.ai/pytorch/1.13.1/cpu/osx-x86_64/native/lib/libc10.dylib.gz ... [INFO ] - Downloading jni https://publish.djl.ai/pytorch/1.13.1/jnilib/0.21.0/osx-x86_64/cpu/libdjl_torch.dylib to cache ... Exception in thread "main" ai.djl.engine.EngineException: Failed to load PyTorch native library at ai.djl.pytorch.engine.PtEngine.newInstance(PtEngine.java:85) at ai.djl.pytorch.engine.PtEngineProvider.getEngine(PtEngineProvider.java:40) at ai.djl.engine.Engine.getEngine(Engine.java:186) at ai.djl.Model.newInstance(Model.java:99) at ai.djl.repository.zoo.BaseModelLoader.createModel(BaseModelLoader.java:191) at ai.djl.repository.zoo.BaseModelLoader.loadModel(BaseModelLoader.java:154) at ai.djl.repository.zoo.Criteria.loadModel(Criteria.java:168) at ai.djl.examples.inference.SemanticSegmentation.predict(SemanticSegmentation.java:69) at ai.djl.examples.inference.SemanticSegmentation.main(SemanticSegmentation.java:49) Caused by: java.lang.UnsatisfiedLinkError: Can't load library: /Users/King/.djl.ai/pytorch/1.13.1-cpu-osx-x86_64/0.21.0-libdjl_torch.dylib at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2633) at java.base/java.lang.Runtime.load0(Runtime.java:768) at java.base/java.lang.System.load(System.java:1837) at ai.djl.pytorch.jni.LibUtils.loadNativeLibrary(LibUtils.java:360) at ai.djl.pytorch.jni.LibUtils.loadLibrary(LibUtils.java:81) at ai.djl.pytorch.engine.PtEngine.newInstance(PtEngine.java:54) ... 8 more

Is there any tips I can load this library with my mac os version ?

frankfliu commented 1 year ago

@chupee120 You should be able to use PyTorch 1.12.1 with DJL 0.21.0-SNAPSHOT by setting environment variable or system property

export PYTORCH_VERSION=1.12.1
or
java -DPYTORCH_VERSION=1.12.1