2

我正在尝试CnnSentenceClassification从 deeplearning4j 示例运行。我将此文件移动到我的 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"
}
4

2 回答 2

1

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

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

于 2017-10-26T13:45:11.243 回答
0

我遇到了同样的问题。希望它可以为其他人节省时间

您需要一个 ND4J 后端,这意味着只需在项目的 pom 中包含以下依赖项:

<dependency>
    <groupId>org.nd4j</groupId>
    <artifactId>nd4j-native</artifactId>
    <version>0.9.1</version>
</dependency>

对于 Gradle,只需在依赖项中添加以下行:

compile "org.nd4j:nd4j-native:0.9.1"

这个原生后端使用 CPU 进行计算。启用 CUDA 的显卡还有另一个依赖项。

我发现这个链接很有帮助: DL4J Performance Debugging

于 2019-09-29T13:48:04.730 回答