运行Deeplearning4J分类时DataVec矩阵中的零列

时间:2017-11-20 12:14:52

标签: java maven intellij-idea deeplearning4j nd4j

我试图运行deeplearning4j quickstart分类问题。

我使用的是Windows 8 64位,Oracle JDK 8,IntelliJ 2017.2.5和Maven 3.3.9。

我已经超越了早先困扰我的Canova问题。现在我在运行时遇到了一个新问题。

这是我为自己构建的pom.xml。我没有使用@newOne建议来使用示例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>deeplearning4j.example</groupId>
    <artifactId>deeplearning4j</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.test.skip>false</maven.test.skip>
        <timestamp>${maven.build.timestamp}</timestamp>
        <maven.build.timestamp.format>MM-dd-yyyy HH:mm</maven.build.timestamp.format>
        <timestamp>${maven.build.timestamp}</timestamp>
        <maven.build.timestamp.format>MM-dd-yyyy HH:mm</maven.build.timestamp.format>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <deeplearning4j.version>0.9.1</deeplearning4j.version>
        <nd4j.version>0.9.1</nd4j.version>
    </properties>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.deeplearning4j/deeplearning4j-core -->
        <dependency>
            <groupId>org.deeplearning4j</groupId>
            <artifactId>deeplearning4j-core</artifactId>
            <version>${deeplearning4j.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.deeplearning4j/deeplearning4j-nlp -->
        <dependency>
            <groupId>org.deeplearning4j</groupId>
            <artifactId>deeplearning4j-nlp</artifactId>
            <version>${deeplearning4j.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.deeplearning4j/deeplearning4j-ui-components -->
        <dependency>
            <groupId>org.deeplearning4j</groupId>
            <artifactId>deeplearning4j-ui-components</artifactId>
            <version>${deeplearning4j.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.deeplearning4j/deeplearning4j-ui-model -->
        <dependency>
            <groupId>org.deeplearning4j</groupId>
            <artifactId>deeplearning4j-ui-model</artifactId>
            <version>${deeplearning4j.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.deeplearning4j/deeplearning4j-nearestneighbors-model -->
        <dependency>
            <groupId>org.deeplearning4j</groupId>
            <artifactId>deeplearning4j-nearestneighbors-model</artifactId>
            <version>${deeplearning4j.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.nd4j/nd4j-api -->
        <dependency>
            <groupId>org.nd4j</groupId>
            <artifactId>nd4j-native-platform</artifactId>
            <version>${nd4j.version}</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.deeplearning4j/deeplearning4j-nn -->
        <dependency>
            <groupId>org.deeplearning4j</groupId>
            <artifactId>deeplearning4j-nn</artifactId>
            <version>${deeplearning4j.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/jfree/jfreechart -->
        <dependency>
            <groupId>jfree</groupId>
            <artifactId>jfreechart</artifactId>
            <version>1.0.13</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>
        <!-- https://mvnrepository.com/artifact/org.deeplearning4j/dl4j-test-resources -->
        <dependency>
            <groupId>org.deeplearning4j</groupId>
            <artifactId>dl4j-test-resources</artifactId>
            <version>0.4.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.10.19</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.0.1</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.4</version>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.maven.wagon</groupId>
                        <artifactId>wagon-http-lightweight</artifactId>
                        <version>1.0</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>buildnumber-maven-plugin</artifactId>
                <version>1.4</version>
                <executions>
                    <execution>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>create-metadata</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <attach>true</attach>
                    <!--make it available for jar/war classpath resource -->
                    <addOutputDirectoryToResources>true</addOutputDirectoryToResources>
                    <revisionOnScmFailure>na</revisionOnScmFailure>
                    <doCheck>false</doCheck>
                    <doUpdate>false</doUpdate>
                    <revisionOnScmFailure>true</revisionOnScmFailure>
                    <format>{0,date,yyyy-MM-dd_HH-mm}_{1}</format>
                    <items>
                        <item>timestamp</item>
                        <item>${user.name}</item>
                    </items>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

IntelliJ在我的Maven窗口中没有红色。我可以成功构建和打包代码而不会出现错误消息。

当我运行分类问题时,我在运行时收到此消息:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "ADSI prefetch thread" java.lang.RuntimeException: org.nd4j.linalg.exception.ND4JIllegalStateException: Invalid shape: Requested INDArray shape [50, 0] contains dimension size values < 1 (all dimensions must be 1 or more)
    at org.deeplearning4j.datasets.iterator.AsyncDataSetIterator$AsyncPrefetchThread.run(AsyncDataSetIterator.java:442)
Caused by: org.nd4j.linalg.exception.ND4JIllegalStateException: Invalid shape: Requested INDArray shape [50, 0] contains dimension size values < 1 (all dimensions must be 1 or more)
    at org.nd4j.linalg.factory.Nd4j.checkShapeValues(Nd4j.java:5022)
    at org.nd4j.linalg.factory.Nd4j.create(Nd4j.java:5012)
    at org.nd4j.linalg.factory.Nd4j.create(Nd4j.java:4965)
    at org.nd4j.linalg.factory.Nd4j.create(Nd4j.java:4093)
    at org.deeplearning4j.datasets.datavec.RecordReaderMultiDataSetIterator.convertWritables(RecordReaderMultiDataSetIterator.java:377)
    at org.deeplearning4j.datasets.datavec.RecordReaderMultiDataSetIterator.convertFeaturesOrLabels(RecordReaderMultiDataSetIterator.java:271)
    at org.deeplearning4j.datasets.datavec.RecordReaderMultiDataSetIterator.nextMultiDataSet(RecordReaderMultiDataSetIterator.java:234)
    at org.deeplearning4j.datasets.datavec.RecordReaderMultiDataSetIterator.next(RecordReaderMultiDataSetIterator.java:177)
    at org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator.next(RecordReaderDataSetIterator.java:306)
    at org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator.next(RecordReaderDataSetIterator.java:393)
    at org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator.next(RecordReaderDataSetIterator.java:51)
    at org.deeplearning4j.datasets.iterator.AsyncDataSetIterator$AsyncPrefetchThread.run(AsyncDataSetIterator.java:423)

我应该在输入中调整什么来通过零列的矩阵?

1 个答案:

答案 0 :(得分:0)

我上面发布的pom完成了这项工作。

原来我的下一个问题是数据。我的训练和评估文件不正确。

一旦我有了正确的文件,我就在控制台窗口中得到了这个结果:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Evaluate model....

Examples labeled as 0 classified by model as 0: 100 times
Examples labeled as 1 classified by model as 1: 100 times


==========================Scores========================================
 # of classes:    2
 Accuracy:        1.0000
 Precision:       1.0000
 Recall:          1.0000
 F1 Score:        1.0000
========================================================================
****************Example finished********************

作为一个额外的奖励,我有两个可爱的弹出窗口:

培训数据

enter image description here

评估数据

enter image description here

我很高兴能够通过deeplearning4j获得一分钱。我希望我的简化pom.xml可以帮助其他人。

干得好,deeplearning4j团队!我期待着更深入的潜水。