javaeclipsegradledeeplearning4jnd4j

Deeplearning4j example does not work with gradle


I am trying to run CnnSentenceClassification from deeplearning4j example. I moved this file to my Gradle project. When I run the class from the eclipse it works fine. However when I run it from ./gradlew run I get following error:

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

I checked and nd4j-api-0.9.1.jar is in my classpath. This is my 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"
}

Solution

  • Edit: new link is here. https://deeplearning4j.konduit.ai/config/backends

    Old content below: You have test scope on the nd4j backend. An nd4j backend is NEVER optional. https://nd4j.org/backend.html

    The error is right in the message. We even give you a link with an explanation right in the stack trace.