在首次运行DJL库时出现报错
Simulation progress : [ 0 SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
ai.djl.engine.EngineException: No deep learning engine found.
Please refer to https://github.com/deepjavalibrary/djl/blob/master/docs/development/troubleshooting.md for more details.
at ai.djl.engine.Engine.getInstance(Engine.java:140)
at ai.djl.Model.newInstance(Model.java:72)
at ai.djl.Model.newInstance(Model.java:61)
进程已结束,退出代码0
跳转到GitHub文档的问题解释:
链接地址 https://github.com/deepjavalibrary/djl/blob/master/docs/development/troubleshooting.md
github里提出的两种解决方案:
- 打成胖包导致的问题
- IntelliJ 和 Gradle 之间不匹配导致的
结果发现并不能解决我的问题
需要选择不同的本地库构建,如 Apache MXNet、PyTorch、TensorFlow 和 ONNX Runtime,
发现需要引用相关的引擎(ps:还是太天真了)
跳转链接
MXNet Engine
PyTorch Engine
TensorFlow Engine
ONNX Engine
里面介绍需要在Maven中添加依赖
<dependency>
<groupId>ai.djl.tensorflow</groupId>
<artifactId>tensorflow-engine</artifactId>
<version>0.25.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>ai.djl.tensorflow</groupId>
<artifactId>tensorflow-native-auto</artifactId>
<version>2.2.0</version>
</dependency>
添加之后又有新的错误问题
Simulation progress : [ 0 Exception in thread "main" java.lang.ExceptionInInitializerError
at ai.djl.tensorflow.engine.TfEngineProvider.getEngine(TfEngineProvider.java:36)
at ai.djl.engine.Engine.initEngine(Engine.java:59)
at ai.djl.engine.Engine.<clinit>(Engine.java:49)
at ai.djl.Model.newInstance(Model.java:71)
at ai.djl.Model.newInstance(Model.java:60)
at examples.MyClass.DQNLearning.<init>(DQNLearning.java:93)
...
Caused by: ai.djl.engine.EngineException: Failed to load TensorFlow native library
at ai.djl.tensorflow.engine.TfEngine.newInstance(TfEngine.java:75)
at ai.djl.tensorflow.engine.TfEngineProvider$InstanceHolder.<clinit>(TfEngineProvider.java:40)
... 20 more
Caused by: java.lang.NoSuchMethodError: 'java.lang.String ai.djl.util.Utils.getEnvOrSystemProperty(java.lang.String)'
at ai.djl.tensorflow.engine.javacpp.LibUtils.findOverrideLibrary(LibUtils.java:72)
at ai.djl.tensorflow.engine.javacpp.LibUtils.getLibName(LibUtils.java:64)
at ai.djl.tensorflow.engine.javacpp.LibUtils.loadLibrary(LibUtils.java:48)
at ai.djl.tensorflow.engine.TfEngine.newInstance(TfEngine.java:53)
我认为是是模型库没有这个方法的实现
我又将Maven换为
<dependency>
<groupId>ai.djl.mxnet</groupId>
<artifactId>mxnet-native-auto</artifactId>
<version>1.7.0-backport</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>ai.djl</groupId>
<artifactId>basicdataset</artifactId>
<version>0.8.0</version>
</dependency>
<dependency>
<groupId>ai.djl</groupId>
<artifactId>model-zoo</artifactId>
<version>0.8.0</version>
</dependency>
之后报错就变为了(PS难受啊)
Exception in thread "main" java.lang.NoSuchMethodError: 'ai.djl.Device ai.djl.Device.defaultIfNull(ai.djl.Device)'
at ai.djl.mxnet.engine.MxModel.<init>(MxModel.java:64)
at ai.djl.mxnet.engine.MxEngine.newModel(MxEngine.java:88)
at ai.djl.Model.newInstance(Model.java:71)
at ai.djl.Model.newInstance(Model.java:60)
at com.mechalikh.pureedgesim.simulationmanager.DefaultSimulationManager.processEvent(DefaultSimulationManager.java:178)
at com.mechalikh.pureedgesim.simulationengine.PureEdgeSim.processEvent(PureEdgeSim.java:178)
at com.mechalikh.pureedgesim.simulationengine.PureEdgeSim.processFutureEventsHappeningAtSameTimeOfTheFirstOne(PureEdgeSim.java:158)
at com.mechalikh.pureedgesim.simulationengine.PureEdgeSim.runClockTickAndProcessFutureEvents(PureEdgeSim.java:133)
at com.mechalikh.pureedgesim.simulationengine.PureEdgeSim.start(PureEdgeSim.java:106)
at com.mechalikh.pureedgesim.simulationmanager.DefaultSimulationManager.startSimulation(DefaultSimulationManager.java:106)
at com.mechalikh.pureedgesim.simulationmanager.SimulationThread.startSimulation(SimulationThread.java:137)
at com.mechalikh.pureedgesim.simulationmanager.Simulation.launchSimulation(Simulation.java:158)
at examples.Example8.main(Example8.java:69)
经过不断奋斗
将maven文件换成如下就可以正确运行–问题解决
<dependency>
<groupId>ai.djl</groupId>
<artifactId>api</artifactId>
<version>0.8.0</version>
</dependency>
<dependency>
<groupId>ai.djl.mxnet</groupId>
<artifactId>mxnet-engine</artifactId>
<version>0.8.0</version>
</dependency>
<dependency>
<groupId>ai.djl.mxnet</groupId>
<artifactId>mxnet-native-auto</artifactId>
<version>1.7.0-backport</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.26</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.26</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>5.3.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ai.djl</groupId>
<artifactId>basicdataset</artifactId>
<version>0.8.0</version>
</dependency>
<dependency>
<groupId>ai.djl</groupId>
<artifactId>model-zoo</artifactId>
<version>0.8.0</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.4</version>
</dependency>