# Trying to load a simple sequential tf.keras model saved as .h5 file

**URL:** <https://community.konduit.ai/t/trying-to-load-a-simple-sequential-tf-keras-model-saved-as-h5-file/2451>\
**Category:** DL4J\
**Created:** [April 7, 2023, 10:26am UTC](https://community.konduit.ai/t/trying-to-load-a-simple-sequential-tf-keras-model-saved-as-h5-file/2451 "2023-04-07T10:26:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hodophile](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/hodophile/32/1071_2.png) [@hodophile](https://community.konduit.ai/u/hodophile)\
**Post date:** [April 7, 2023, 10:26am UTC](https://community.konduit.ai/t/trying-to-load-a-simple-sequential-tf-keras-model-saved-as-h5-file/2451/1 "2023-04-07T10:26:52Z")

</div>

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);
	
    }

```

}
