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.
import org.deeplearning4j.nn.modelimport.keras.KerasModelImport;
import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;
import org.nd4j.common.io.ClassPathResource;
import org.nd4j.linalg.api.buffer.DataType;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.factory.Nd4j;
public class SimpleSequentialMlpImport {
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);
}
}