public static String dataLocalPath;
public static void main(String[] args) throws Exception {
String SIMPLE_MLP = new ClassPathResource("simple_mlp.h5").getFile().getPath();
System.out.println(SIMPLE_MLP);
MultiLayerNetwork model = KerasModelImport.importKerasSequentialModelAndWeights(SIMPLE_MLP, false);
INDArray input = Nd4j.create(DataType.FLOAT, 256, 100);
INDArray output = model.output(input);
model.fit(input, output);
}
}
Trying to load a tf.keras sequential model using dl4j throws the error below.?!
Exception in thread “main” org.deeplearning4j.exception.DL4JException: Cannot calculate gradient and score with respect to labels: final layer is not an IOutputLayer. Final layer class: class org.deeplearning4j.nn.layers.feedforward.dense.DenseLayer. To calculate gradients and fit a network using backpropagation, the final layer must be an output layer
@hodophile you seem to have an invalid keras model. Could you post your keras code? I almost guarantee you forgot to specify a loss function or something.
Remove the extra output layer and you should be good to go. 99% of the time model import is used for inference then you add your updaters and other training information on top of that.