我正在尝试从deeplearning4j示例运行CnnSentenceClassification
。我将此文件移至Gradle项目。当我从日食中运行该类时,它工作正常。但是,当我从./gradlew run
运行它时出现以下错误:
Exception in thread "main" java.lang.ExceptionInInitializerError
at
main.CnnSentenceClassification.main(CnnSentenceClassification.java:75)
Caused by: java.lang.RuntimeException:
org.nd4j.linalg.factory.Nd4jBackend$NoAvailableBackendException:
Please ensure that you have an nd4j backend on your classpath. Please
see: http://nd4j.org/getstarted.html
at org.nd4j.linalg.factory.Nd4j.initContext(Nd4j.java:6089)
at org.nd4j.linalg.factory.Nd4j.<clinit>(Nd4j.java:201)
... 1 more
Caused by:
org.nd4j.linalg.factory.Nd4jBackend$NoAvailableBackendException:
Please ensure that you have an nd4j backend on your classpath. Please
see: http://nd4j.org/getstarted.html
at org.nd4j.linalg.factory.Nd4jBackend.load(Nd4jBackend.java:258)
at org.nd4j.linalg.factory.Nd4j.initContext(Nd4j.java:6086)
... 2 more
我检查了nd4j-api-0.9.1.jar
在我的类路径中。这是我的build.gradle
:
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'
repositories {
jcenter()
}
mainClassName="main.CnnSentenceClassification"
dependencies {
compile group: 'org.deeplearning4j', name: 'deeplearning4j-core', version: '0.9.1'
compile group: 'org.deeplearning4j', name: 'deeplearning4j-nlp', version: '0.9.1'
testCompile group: 'org.nd4j', name: 'nd4j-native-platform', version: '0.9.1'
compile group: 'org.nd4j', name: 'nd4j-api', version: '0.9.1'
compile "org.slf4j:slf4j-simple:1.7.25"
compile "org.slf4j:slf4j-api:1.7.25"
}
答案 0 :(得分:2)
你在nd4j后端有测试范围。 nd4j后端永远不是可选的。 https://nd4j.org/backend.html
错误在消息中是正确的。我们甚至会在堆栈跟踪中为您提供一个解释链接。
答案 1 :(得分:0)
我遇到了同样的问题。希望它可以为其他人节省时间
您需要一个ND4J后端,这意味着仅在项目的pom中包括以下依赖项:
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-native</artifactId>
<version>0.9.1</version>
</dependency>
此本地后端使用CPU进行计算。 启用CUDA的图形卡还有另一个依赖性。
我发现此链接有用: DL4J Performance Debugging