【问题标题】:How to install the library Deeplearning4j with IntelliJ and Maven?如何使用 IntelliJ 和 Maven 安装库 Deeplearning4j?
【发布时间】:2017-09-24 10:30:40
【问题描述】:

我正在尝试安装 Deeplearning4j 库 (https://deeplearning4j.org/index.html),但我不明白如何使用 IntelliJ 和 Maven 正确安装库,以便我可以从中构建一个 .jar 文件。

只要我从 IntelliJ 运行程序,一切似乎都可以正常工作。

这是我的 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>DeepLearning</groupId>
<artifactId>deeplearning</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>


    <!-- https://mvnrepository.com/artifact/org.deeplearning4j/deeplearning4j-core -->
    <dependency>
        <groupId>org.deeplearning4j</groupId>
        <artifactId>deeplearning4j-core</artifactId>
        <version>0.9.1</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.nd4j/nd4j-native -->
    <dependency>
        <groupId>org.nd4j</groupId>
        <artifactId>nd4j-native</artifactId>
        <version>0.9.1</version>
    </dependency>


    <!-- https://mvnrepository.com/artifact/org.nd4j/nd4j-api -->
    <dependency>
        <groupId>org.nd4j</groupId>
        <artifactId>nd4j-api</artifactId>
        <version>0.9.1</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.nd4j/nd4j-native-platform -->
    <dependency>
        <groupId>org.nd4j</groupId>
        <artifactId>nd4j-native-platform</artifactId>
        <version>0.9.1</version>
    </dependency>


    <!-- https://mvnrepository.com/artifact/org.datavec/datavec-api -->
    <dependency>
        <groupId>org.datavec</groupId>
        <artifactId>datavec-api</artifactId>
        <version>0.9.1</version>
    </dependency>


</dependencies>


<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>

            <configuration>
                <archive>
                    <manifest>
                        <mainClass>MLPClassifierLinear</mainClass>
                    </manifest>
                </archive>
            </configuration>

        </plugin>
    </plugins>
</build>

我不确定一切是否设置正确,因为这是我第一次使用 maven。

当我运行 maven install 命令并启动 .jar 文件时,我收到一条错误消息,指出发生了 JNI 错误和 NoClassDefFoundError。

这是确切的错误消息:

错误:发生 JNI 错误,请检查您的安装并 再试一次 线程“主”java.lang.NoClassDefFoundError 中的异常: org/deeplearning4j/nn/conf/layers/Layer at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) 在 java.lang.Class.privateGetMethodRecursive(Class.java:3048) 在 java.lang.Class.getMethod0(Class.java:3018) 在 java.lang.Class.getMethod(Class.java:1784) 在 sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544) 在 sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526) 引起:java.lang.ClassNotFoundException: org.deeplearning4j.nn.conf.layers.Layer at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) 在 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 7 更多

谁能解释我如何正确使用 maven,以便我可以构建 .jar 文件而不会出错?

谢谢你:)

【问题讨论】:

  • 您的 jar 文件不包含任何依赖项。如果你想获得一个可执行的 jar,你需要使用 maven-assembly-plugin 或 maven-shade-plugin...

标签: java maven java-native-interface deeplearning4j dl4j


【解决方案1】:

完成大多数事情的简单方法:

deeplearning4j-core、nd4j-native-platform、maven shade 插件

deeplearning4j-core 为您提供人们在简单桌面上使用的大多数依赖项。

nd4j-native-platform 捆绑了所有操作系统原生依赖项,因此您不必担心多操作系统部署/二进制文件。这也使得 sbt 和 gradle 实际上......可用,因为它们无法处理分类器。

maven shade 插件可以正确地构建 jar。 https://github.com/deeplearning4j/dl4j-examples/blob/94568e78e86c56807c03fe17d6a2f89f0b0df377/dl4j-spark-examples/dl4j-spark/pom.xml#L98

另外,请不要使用“安装”一词。你没有安装任何东西。您正在使用依赖管理器设置一组库。它不像 ruby​​ 和 python 那样在操作系统的意义上安装。

除此之外:对您的 pom.xml 的具体批评。 nd4j-native 这里是多余的。你不需要那个。如果您使用快照或从源代码构建,则仅使用 nd4j-native。

不需要 Datavec-api,因为 deeplearning4j-core 已经引入了它。请阅读 maven 传递依赖项以了解其工作原理。

如果您不确定如何解决这些问题,请查看使用

mvn 依赖:树

【讨论】:

    猜你喜欢
    • 2015-11-27
    • 2019-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-03
    • 2011-11-23
    • 2021-09-15
    • 1970-01-01
    相关资源
    最近更新 更多