deepjavalibrary / djl

An Engine-Agnostic Deep Learning Framework in Java
https://djl.ai
Apache License 2.0
4.07k stars 648 forks source link

java.lang.NullPointerException #1074

Closed kameronren closed 3 years ago

kameronren commented 3 years ago

Description

djl version: 0.11.0

I implements a ssd. when execute net.saveParameters(os); there will be a exception: java.lang.NullPointerException means net is null.

Expected Behavior

save net's parameters into a file.param.

Error Message

java.lang.NullPointerException

How to Reproduce?

run follow code can reproduce: File mlpParamFile = new File("mlp.param"); DataOutputStream os = new DataOutputStream(Files.newOutputStream(mlpParamFile.toPath())); net.saveParameters(os);

Exception in thread "main" java.lang.NullPointerException
    at ai.djl.nn.AbstractBlock.appendShape(AbstractBlock.java:465)
    at ai.djl.nn.AbstractBlock.toString(AbstractBlock.java:455)
    at java.base/java.lang.String.valueOf(String.java:2951)
    at java.base/java.io.PrintStream.println(PrintStream.java:897)
    at cn.hn.xt.rk.ssd.SSD.trainingSSD(SSD.java:371)
    at cn.hn.xt.rk.ssd.SSD.main(SSD.java:407)
frankfliu commented 3 years ago

@kameronren It looks like your model is not initialized. You won't be able to save the model before the model get trained.

But we should not throw NPE in this case.

kameronren commented 3 years ago

@frankfliu my model is initialized and get trained. the ‘net’ in my code is null, so run it will throw NPE.

frankfliu commented 3 years ago

@kameronren Please try latest snapshot build, the NPE bug should have been fixed with PR: https://github.com/deepjavalibrary/djl/pull/1076

frankfliu commented 3 years ago

Please feel free to reopen this issue if you still have questions.

kameronren commented 3 years ago

@frankfliu in my project, the djl version have already been 0.11.0 (the latest version ).

frankfliu commented 3 years ago

@kameronren the fix will be included in 0.12.0 release, you can try 0.12.0-SNAPSHOT version. We publish nightly build to maven snapshot repository

    <repositories>
        <repository>
            <id>djl.ai</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
        </repository>
    </repositories>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>ai.djl</groupId>
                <artifactId>bom</artifactId>
                <version>0.12.0-SNAPSHOT</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>ai.djl</groupId>
            <artifactId>api</artifactId>
        </dependency>
    </dependencies>
kameronren commented 3 years ago

@frankfliu thanks