From 06f76dd1568b463e6fd7ebfa9a991b39e178d973 Mon Sep 17 00:00:00 2001 From: Frank Liu Date: Mon, 5 Jul 2021 18:33:00 -0700 Subject: [PATCH] Fix NPE bug in block.toString() function (#1076) Change-Id: I2aa8bc6c8d36d01cc00c02778907b040d782330c --- api/src/main/java/ai/djl/nn/AbstractBlock.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/ai/djl/nn/AbstractBlock.java b/api/src/main/java/ai/djl/nn/AbstractBlock.java index 2613976f679..c6820539eb8 100644 --- a/api/src/main/java/ai/djl/nn/AbstractBlock.java +++ b/api/src/main/java/ai/djl/nn/AbstractBlock.java @@ -115,7 +115,7 @@ public final NDList forward( boolean training, PairList params) { NDManager paramsManager = parameterStore.getManager(); - if (!isInitialized()) { + if (training && !isInitialized()) { initialize(paramsManager, DataType.FLOAT32, inputs.getShapes()); } return forwardInternal(parameterStore, inputs, training, params); @@ -330,6 +330,9 @@ protected void prepare(Shape[] inputShapes) {} /** {@inheritDoc} */ @Override public boolean isInitialized() { + if (inputShapes == null) { + return false; + } for (Parameter param : getParameters().values()) { if (!param.isInitialized()) { return false;