当前位置: 首页 > 知识库问答 >
问题:

deeplearning4j和Maven的错误

邓嘉致
2023-03-14

这是我下面的教程。

pom。xml文件是dl4j examples文件夹附带的默认文件,因此不应该存在问题,但仍然存在错误。

代码如下:

package org.deeplearning4j.self;
import org.deeplearning4j.datasets.iterator.impl.EmnistDataSetIterator;
import org.deeplearning4j.nn.conf.MultiLayerConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.layers.DenseLayer;
import org.deeplearning4j.nn.conf.layers.OutputLayer;
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
import org.deeplearning4j.nn.weights.WeightInit;
import org.nd4j.linalg.activations.Activation;
import org.nd4j.linalg.learning.config.Adam;
import org.nd4j.linalg.lossfunctions.LossFunctions;

import java.io.IOException;

public class first {
    int batchSize = 128; // how many examples to simultaneously train in the network
    EmnistDataSetIterator.Set emnistSet = EmnistDataSetIterator.Set.BALANCED;
    EmnistDataSetIterator emnistTrain;
    { try { emnistTrain = new EmnistDataSetIterator(emnistSet, batchSize, true); } catch (IOException e) { e.printStackTrace(); } }
    EmnistDataSetIterator emnistTest;
    { try { emnistTest = new EmnistDataSetIterator(emnistSet, batchSize, false); } catch (IOException e) { e.printStackTrace(); } }

    int outputNum = EmnistDataSetIterator.numLabels(emnistSet);// total output classes
    int rngSeed = 123; // integer for reproducability of a random number generator
    int numRows = 28; // number of "pixel rows" in an mnist digit
    int numColumns = 28;

    MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
        .seed(rngSeed)
        .updater(new Adam())
        .l2(1e-4)
        .list()
        .layer(new DenseLayer.Builder()
            .nIn(numRows * numColumns) // Number of input datapoints.
            .nOut(1000) // Number of output datapoints.
            .activation(Activation.RELU) // Activation function.
            .weightInit(WeightInit.XAVIER) // Weight initialization.
            .build())
        .layer(new OutputLayer.Builder(LossFunctions.LossFunction.NEGATIVELOGLIKELIHOOD)
            .nIn(1000)
            .nOut(outputNum)
            .activation(Activation.SOFTMAX)
            .weightInit(WeightInit.XAVIER)
            .build())
        .build();

    MultiLayerNetwork network = new MultiLayerNetwork(conf);
    network.init();

    // pass a training listener that reports score every 10 iterations
    int eachIterations = 10;
    network.addListeners(new ScoreIterationListener(eachIterations));
}

我正在使用IntelliJ。

我在课堂上遇到的错误是:

无法识别在“网络”上调用的两个方法,“init()”和“addListeners()”都有“无法解析符号”。它还在“网络”上说“从不使用字段网络”。

此外,int“eachIterations”在addListeners()方法内有一个“未知类”错误。

这是pom.xml文件:

<?xml version="1.0" encoding="UTF-8"?> <!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~ Copyright (c) 2020 Konduit K.K.   ~ Copyright (c) 2015-2019 Skymind, Inc.   ~   ~ This program and the accompanying materials are made available under the   ~ terms of the Apache License, Version 2.0 which is available at   ~ https://www.apache.org/licenses/LICENSE-2.0.   ~   ~ Unless required by applicable law or agreed to in writing, software  ~ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT   ~ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the   ~ License for the specific language governing permissions and limitations   ~ under the License.   ~   ~ SPDX-License-Identifier: Apache-2.0   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->

<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>org.deeplearning4j</groupId>
    <artifactId>dl4j-examples</artifactId>
    <version>1.0.0-beta7</version>
    <name>Introduction to DL4J</name>
    <description>A set of examples introducing the DL4J framework</description>

    <properties>
        <dl4j-master.version>1.0.0-beta7</dl4j-master.version>
        <!-- Change the nd4j.backend property to nd4j-cuda-X-platform to use CUDA GPUs -->
        <!-- <nd4j.backend>nd4j-cuda-10.2-platform</nd4j.backend> -->
        <nd4j.backend>nd4j-native</nd4j.backend>
        <java.version>1.8</java.version>
        <maven-compiler-plugin.version>3.6.1</maven-compiler-plugin.version>
        <maven.minimum.version>3.3.1</maven.minimum.version>
        <exec-maven-plugin.version>1.4.0</exec-maven-plugin.version>
        <maven-shade-plugin.version>2.4.3</maven-shade-plugin.version>
        <jcommon.version>1.0.23</jcommon.version>
        <jfreechart.version>1.0.13</jfreechart.version>
        <logback.version>1.1.7</logback.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.freemarker</groupId>
                <artifactId>freemarker</artifactId>
                <version>2.3.29</version>
            </dependency>
            <dependency>
                <groupId>io.netty</groupId>
                <artifactId>netty-common</artifactId>
                <version>4.1.48.Final</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.nd4j</groupId>
            <artifactId>${nd4j.backend}</artifactId>
            <version>${dl4j-master.version}</version>
        </dependency>
        <dependency>
            <groupId>org.datavec</groupId>
            <artifactId>datavec-api</artifactId>
            <version>${dl4j-master.version}</version>
        </dependency>
        <dependency>
            <groupId>org.datavec</groupId>
            <artifactId>datavec-data-image</artifactId>
            <version>${dl4j-master.version}</version>
        </dependency>
        <dependency>
            <groupId>org.datavec</groupId>
            <artifactId>datavec-local</artifactId>
            <version>${dl4j-master.version}</version>
        </dependency>
        <dependency>
            <groupId>org.deeplearning4j</groupId>
            <artifactId>deeplearning4j-datasets</artifactId>
            <version>${dl4j-master.version}</version>
        </dependency>
        <dependency>
            <groupId>org.deeplearning4j</groupId>
            <artifactId>deeplearning4j-core</artifactId>
            <version>${dl4j-master.version}</version>
        </dependency>
        <dependency>
            <groupId>org.deeplearning4j</groupId>
            <artifactId>deeplearning4j-ui</artifactId>
            <version>${dl4j-master.version}</version>
        </dependency>
        <dependency>
            <groupId>org.deeplearning4j</groupId>
            <artifactId>deeplearning4j-zoo</artifactId>
            <version>${dl4j-master.version}</version>
        </dependency>
        <!-- ParallelWrapper & ParallelInference live here -->
        <dependency>
            <groupId>org.deeplearning4j</groupId>
            <artifactId>deeplearning4j-parallel-wrapper</artifactId>
            <version>${dl4j-master.version}</version>
        </dependency>
        <!-- Used in the feedforward/classification/MLP* and feedforward/regression/RegressionMathFunctions example -->
        <dependency>
            <groupId>jfree</groupId>
            <artifactId>jfreechart</artifactId>
            <version>${jfreechart.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jfree</groupId>
            <artifactId>jcommon</artifactId>
            <version>${jcommon.version}</version>
        </dependency>
        <!-- Used for downloading data in some of the examples -->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.3.5</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>${logback.version}</version>
        </dependency>
        <dependency>
            <groupId>org.datavec</groupId>
            <artifactId>datavec-data-codec</artifactId>
            <version>${dl4j-master.version}</version>
        </dependency>
        <dependency>
            <groupId>org.bytedeco</groupId>
            <artifactId>javacv-platform</artifactId>
            <version>1.5.2</version>
        </dependency>
    </dependencies>
    <!-- Maven Enforcer: Ensures user has an up to date version of Maven before building -->
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>1.0.1</version>
                <executions>
                    <execution>
                        <id>enforce-default</id>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <requireMavenVersion>
                                    <version>[${maven.minimum.version},)</version>
                                    <message>********** Minimum Maven Version is ${maven.minimum.version}. Please upgrade Maven before continuing (run "mvn --version" to check). **********</message>
                                </requireMavenVersion>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-plugin.version}</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.lewisd</groupId>
                <artifactId>lint-maven-plugin</artifactId>
                <version>0.0.11</version>
                <configuration>
                    <failOnViolation>true</failOnViolation>
                    <onlyRunRules>
                        <rule>DuplicateDep</rule>
                        <rule>RedundantPluginVersion</rule>
                        <!-- Rules incompatible with Java 9
                        <rule>VersionProp</rule>
                        <rule>DotVersionProperty</rule> -->
                    </onlyRunRules>
                </configuration>
                <executions>
                    <execution>
                        <id>pom-lint</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>${exec-maven-plugin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <executable>java</executable>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>${maven-shade-plugin.version}</version>
                <configuration>
                    <shadedArtifactAttached>true</shadedArtifactAttached>
                    <shadedClassifierName>${shadedClassifier}</shadedClassifierName>
                    <createDependencyReducedPom>true</createDependencyReducedPom>
                    <filters>
                        <filter>
                            <artifact>*:*</artifact>
                            <excludes>
                                <exclude>org/datanucleus/**</exclude>
                                <exclude>META-INF/*.SF</exclude>
                                <exclude>META-INF/*.DSA</exclude>
                                <exclude>META-INF/*.RSA</exclude>
                            </excludes>
                        </filter>
                    </filters>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>reference.conf</resource>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
        </plugins>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>com.lewisd</groupId>
                                        <artifactId>lint-maven-plugin</artifactId>
                                        <versionRange>[0.0.11,)</versionRange>
                                        <goals>
                                            <goals><goal>check</goal></goals>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore/>
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build> </project>

此处的错误为“${shadedClassifier}”shadedClassifier为红色,错误为:“无法解析符号‘shadedClassifier’”

所以我用“mvn干净安装”重新安装了maven,但它仍然不起作用。

Maven已经正确安装了clean install,但我仍然有这些错误。

请任何帮助都将被感谢。我已经坚持了一个星期,我真的很想学习机器学习。

共有1个答案

韩鸿
2023-03-14

我猜maven设置不正确。我会确保IDE是最新的。右键单击intellij中的项目并点击reload是我会考虑做的事情。与此处相同的答案:强制Intellij IDEA重读所有maven依赖项

 类似资料:
  • 我试图安装Deeplearning4j库(https://Deeplearning4j.org/index.html),但我不明白如何将install the lib正确地与IntelliJ和Maven一起使用,以便从中构建一个.jar文件。 我不确定是否一切都设置正确,因为这是我第一次使用Maven。 当我运行maven install命令并启动。jar文件时,我会得到一个错误,该错误表示发生了

  • Deeplearning4j(简称DL4J)是为Java和Scala编写的首个商业级开源分布式深度学习库。DL4J与Hadoop和Spark集成,为商业环境(而非研究工具目的)所设计。Skymind是DL4J的商业支持机构。 Deeplearning4j技术先进,以即插即用为目标,通过更多预设的使用,避免太多配置,让非研究人员也能够进行快速的原型制作。DL4J同时可以规模化定制。DL4J遵循Apa

  • Eclipse Deeplearning4J 有助于构建涵盖从数据预处理到部署的深入学习产品的整个生命周期的深度学习应用程序。 Eclipse Deeplearning4j 的目标是为构建应用程序提供一组核心组件,涵盖构建智能AI产品的整个生命周期。 企业内部的智能AI产品通常具有比机器学习部分更广泛的范围。 提供分发的总体目标是提供一种建立深入学习应用的方式,涵盖构建AI产品的整个生命周期。

  • 我正试图在我的Clojure/Leiningen学习过程中迈出下一步。 我想在我的clojure项目中导入deeplearning4j。做一些研究,似乎可以通过Maven与leiningen一起做。根据教程,maven库来自这里。 我希望工作的过程是查找库(在本例中为deeplearning4j),并将其添加到: 但我发现了错误: 我尝试添加键,但也没有成功: 我得到了一个错误: 谁能帮我明白我错

  • 问题内容: 我在(版本3.1)中使用。当我尝试编译下一行代码 使用maven-compiler-plugin(版本3.3),我收到编译失败消息: 我使用Java 1.7.0_55进行编译。 我该如何解决? 问题答案: 发生问题是因为方法的签名具有可变参数。调用方法时,将分三个阶段搜索所有适用的方法。在阶段3中搜索具有可变参数的方法,在该阶段中,可以进行装箱和拆箱。 因此和都适用于此处,因为考虑了装

  • 首先感谢你花时间来帮助我。我的名字是Matt,我一直在努力学习java,并创建mc插件。我一直在尝试为MC制作一个具有深入学习的插口插件。我正在尝试使用deeplearning4j。我知道我可以把这个问题放到spigotmc的网站上,但我不认为他们会很有帮助,因为从以前在spigotmc上的帖子来看,他们中的很多人似乎对dl4j不太了解。因此,到目前为止,我所做的是使用dl4j网站上的快速入门指南