我正在尝试从deeplearning4j示例运行CnnSentenceClassification。我将此文件移到我的Gradle项目中。当我从 eclipse 运行类时,它可以正常工作。但是,当我从./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"
}

最佳答案

您在nd4j后端上具有测试范围。 nd4j后端永远不是可选的。
https://nd4j.org/backend.html

错误在消息中。我们甚至在堆栈跟踪中为您提供了一个带说明的链接。

09-25 22:17