Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

org.nd4j.linalg.factory.Nd4jBackend$NoAvailableBackendException

I don't know what it wants from me. I am using

    <dependency>
        <groupId>org.deeplearning4j</groupId>
        <artifactId>deeplearning4j-core</artifactId>
        <version>${deeplearning4j.version}</version>
    </dependency>

    <dependency>
        <groupId>org.deeplearning4j</groupId>
        <artifactId>deeplearning4j-nlp</artifactId>
        <version>${deeplearning4j.version}</version>
    </dependency>

where

<deeplearning4j.version>0.4-rc3.8</deeplearning4j.version>

but I am getting

Caused by: org.nd4j.linalg.factory.Nd4jBackend$NoAvailableBackendException: null
    at org.nd4j.linalg.factory.Nd4jBackend.load(Nd4jBackend.java:148) ~[nd4j-api-0.4-rc3.7.jar:na]
    at org.nd4j.linalg.factory.Nd4j.initContext(Nd4j.java:4498) ~[nd4j-api-0.4-rc3.7.jar:na]
    ... 53 common frames omitted

if I try to load the Google word vector model:

@RequestMapping("/loadModel")
public Boolean loadModel(@RequestParam(value="model") String model) {

    Resource resource = appContext.getResource("WEB-INF/word-vector-models/" + model);

    try {
        File modelFile = resource.getFile();

        System.err.println(modelFile.getAbsolutePath());
        WordVectors googleModel = WordVectorSerializer.loadGoogleModel(modelFile, true);
        this.wordVectorsMap.put(model, googleModel);
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }

    return true;
}
like image 306
Stefan Falk Avatar asked Feb 12 '16 15:02

Stefan Falk


1 Answers

It looks like you don't have an nd4j backend specified in your pom file. You have to have one, and you should use only one (don't have multiple backends in your pom at once unless you use profiles). Currently, for version 0.4-rc3.8, I've had luck with nd4j-x86 on non-GPU enabled Mac, Windows and linux boxes. If you have access to GPUs, you could use one of the nd4j-jcublas-7.x jars, but be aware that there is a major Cuda rewrite going on according to their Gitter.

For now,

  • Read the "Dependencies and Backends" section of http://deeplearning4j.org/quickstart.html,
  • Determine which backend is right for you at http://nd4j.org/dependencies.html (Note that Jblas is only available if you downgrade to version 0.4-rc3.6)
  • Keep an eye on the dl4j Gitter
  • If you're trying to use GPUs like I am, keep an eye on Github issue #555

Here's how I set up my pom.xml dependencies. By default ((i.e. mvn clean install), it runs with nd4j-x86, but when I pull my code onto the GPU box, I just append the profile name (so mvn clean install -P cuda) and switch backends easily:

<!-- Platform-dependent backend selection (netlib is default) -->
<profiles>
    <profile>
        <id>cuda</id>
        <dependencies>
            <dependency>
                <groupId>org.nd4j</groupId>
                <artifactId>nd4j-jcublas-${cuda.version}</artifactId>
                <version>${nd4j.version}</version>
            </dependency>
        </dependencies>
    </profile>
    <profile>
        <id>netlib</id>
        <dependencies>
            <dependency>
                <groupId>org.nd4j</groupId>
                <artifactId>nd4j-x86</artifactId>
                <version>${nd4j.version}</version>
            </dependency>
        </dependencies>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>
</profiles>
<!-- end platform-dependent backend selection -->


<dependencies>
<!-- dl4j dependencies -->
    <dependency>
        <groupId>org.deeplearning4j</groupId>
        <artifactId>deeplearning4j-core</artifactId>
        <version>${dl4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.deeplearning4j</groupId>
        <artifactId>deeplearning4j-ui</artifactId>
        <version>${dl4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.deeplearning4j</groupId>
        <artifactId>deeplearning4j-scaleout-api</artifactId>
        <version>${dl4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.deeplearning4j</groupId>
        <artifactId>deeplearning4j-scaleout-akka</artifactId>
        <version>${dl4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.deeplearning4j</groupId>
        <artifactId>deeplearning4j-scaleout-zookeeper</artifactId>
        <version>${dl4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.deeplearning4j</groupId>
        <artifactId>deeplearning4j-nlp</artifactId>
        <version>${dl4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.deeplearning4j</groupId>
        <artifactId>deeplearning4j-aws</artifactId>
        <version>${dl4j.version}</version>
    </dependency>
    <!-- end dl4j dependencies -->

    <!-- nd4j dependencies -->
    <dependency>
        <groupId>org.nd4j</groupId>
        <artifactId>canova-nd4j-image</artifactId>
        <version>${canova.version}</version>
    </dependency>
    <dependency>
        <groupId>org.nd4j</groupId>
        <artifactId>canova-nd4j-codec</artifactId>
        <version>${canova.version}</version>
    </dependency>
    <!-- end nd4j dependencies -->

    <dependency>
        <groupId>com.fasterxml.jackson.dataformat</groupId>
        <artifactId>jackson-dataformat-yaml</artifactId>
        <version>${jackson.version}</version>
    </dependency>

    <dependency>
        <groupId>net.java.openjfx.backport</groupId>
        <artifactId>openjfx-78-backport</artifactId>
        <version>1.8.0-ea-b96.1</version>
    </dependency>


    <!-- logging -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.13</version>
    </dependency>
    <!-- end logging -->


    <dependency>
        <groupId>org.apache.maven.reporting</groupId>
        <artifactId>maven-reporting-api</artifactId>
        <version>2.2.1</version>
    </dependency>
</dependencies>
like image 55
Catsbergers Avatar answered Nov 09 '22 07:11

Catsbergers