Intellij Maven深度学习4J

Intellij Maven深度学习4J,maven,intellij-idea,deeplearning4j,nd4j,Maven,Intellij Idea,Deeplearning4j,Nd4j,我正在尝试在IntelliJ中建立一个maven项目,我需要关于如何为deeplearning4j进行设置的最新完整说明,因为我经常遇到以下错误: java.lang.NoClassDefFoundError:无法初始化类 org.nd4j.linalg.factory.nd4j和java.lang.exceptionininitializerror (这些是我使用Kotlin REPL时使用的)。当我离开时,我也会收到这些警告 正常运行程序:log4j:WARN找不到附加程序 记录器(org.

我正在尝试在IntelliJ中建立一个maven项目,我需要关于如何为deeplearning4j进行设置的最新完整说明,因为我经常遇到以下错误:

java.lang.NoClassDefFoundError:无法初始化类 org.nd4j.linalg.factory.nd4j和java.lang.exceptionininitializerror (这些是我使用Kotlin REPL时使用的)。当我离开时,我也会收到这些警告 正常运行程序:log4j:WARN找不到附加程序 记录器(org.nd4j.linalg.factory.Nd4jBackend)

这是我的pom.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>Test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>org.example Test</name>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <kotlin.version>1.3.61</kotlin.version>
    <kotlin.code.style>official</kotlin.code.style>
    <junit.version>4.12</junit.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-stdlib</artifactId>
        <version>${kotlin.version}</version>
    </dependency>
    <dependency>
        <groupId>org.nd4j</groupId>
        <artifactId>nd4j-common</artifactId>
        <version>1.0.0-beta6</version>
    </dependency>
        <dependency>
            <groupId>org.deeplearning4j</groupId>
            <artifactId>deeplearning4j-core</artifactId>
            <version>1.0.0-beta4</version>
        </dependency>
        <dependency>
            <groupId>org.nd4j</groupId>
            <artifactId>nd4j-native-platform</artifactId>
            <version>1.0.0-beta4</version>
        </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.5</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.5</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.5</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.5</version>
    </dependency>
    <dependency>
        <groupId>org.nd4j</groupId>
        <artifactId>nd4j-jblas</artifactId>
        <version>0.0.3.5.5.4-SNAPSHOT</version>
    </dependency>
</dependencies>

<build>
    <sourceDirectory>src/main/kotlin</sourceDirectory>
    <testSourceDirectory>src/test/kotlin</testSourceDirectory>

    <plugins>
        <plugin>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-maven-plugin</artifactId>
            <version>${kotlin.version}</version>
            <executions>
                <execution>
                    <id>compile</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
                <execution>
                    <id>test-compile</id>
                    <phase>test-compile</phase>
                    <goals>
                        <goal>addSources</goal>
                        <goal>test-compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

哇,这个pom.xml看起来很糟糕。你从哪里弄来的

通常,您希望所有DL4J和ND4J依赖项都具有相同的版本,但您在这里混用了。然后,您已经多次获得了slf4j api依赖项和jblas的一个古老版本(一个多年不需要的依赖项)

看看


此示例pom.xml通常是最新的,是一个很好的起点。

此处提供了完整的安装指南:

注意:仅支持64位jdk,不支持jdk 13,jdk 7对我来说工作正常,请在intellij中启用自动导入模块

import org.nd4j.linalg.api.ndarray.INDArray
import org.nd4j.linalg.factory.Nd4j
import java.util.*

class Test3
{

}

fun main() { /*
        Before we begin, let's review what an INDArray is:
        A INDArray is a multi-dimensional array of numbers: a vector, matrix, or tensor for example.
        Internally, it may store single precision or double precision floating point values for each entry.
        Here, we'll see how you can get some basic information about INDArrays. In later examples, we'll see
        the different ways to create INDArrays, and more operations we can do on them.
         */
//Let's start by creating a basic 2d array: a matrix with 3 rows and 5 columns. All elements are 0.0
    val nRows = 3
    val nColumns = 5
    val myArray: INDArray = Nd4j.zeros(nRows, nColumns)
    //Next, print some basic information about the array:
    System.out.println("Basic INDArray information:")
    System.out.println("Num. Rows:          " + myArray.rows())
    System.out.println("Num. Columns:       " + myArray.columns())
    System.out.println("Num. Dimensions:    " + myArray.rank()) //2 dimensions -> rank 2
    System.out.println("Shape:              " + Arrays.toString(myArray.shape())) //[3,5] -> 3 rows, 5 columns
    System.out.println("Length:             " + myArray.length()) // 3 rows * 5 columns = 15 total elements
    //We can print the array itself using toString method:
    System.out.println("\nArray Contents:\n$myArray")
    //There are some other ways we can get the same or similar info
    System.out.println()
    System.out.println("size(0) == nRows:   " + myArray.size(0)) //Also equivalent to: .shape()[0]
    System.out.println("size(1) == nCols:   " + myArray.size(1)) //Also equivalent to: .shape()[1]
    System.out.println("Is a vector:        " + myArray.isVector())
    System.out.println("Is a scalar:        " + myArray.isScalar())
    System.out.println("Is a matrix:        " + myArray.isMatrix())
    System.out.println("Is a square matrix: " + myArray.isSquare())
    //Let's make some modifications to our array...
// Note that indexing starts at 0. Thus 0..2 are valid indices for rows, and 0..4 are valid indices for columns here
    myArray.putScalar(0, 1, 2.0) //Set value at row 0, column 1 to value 2.0
    myArray.putScalar(2, 3, 5.0) //Set value at row 2, column 3 to value 5.0
    System.out.println("\nArray after putScalar operations:")
    System.out.println(myArray)
    //We can also get individual values:
    val val0: Double = myArray.getDouble(0, 1) //Get the value at row 0, column 1 - expect value 2.0 as we set this earlier
    System.out.println("\nValue at (0,1):     $val0")
    //Finally, there are many things we can do to the array... for example adding scalars:
    val myArray2: INDArray = myArray.add(1.0) //Add 1.0 to each entry
    System.out.println("\nNew INDArray, after adding 1.0 to each entry:")
    System.out.println(myArray2)
    val myArray3: INDArray = myArray2.mul(2.0) //Multiply each entry by 2.0
    System.out.println("\nNew INDArray, after multiplying each entry by 2.0:")
    System.out.println(myArray3)
}