Hello,
I am trying to import a sequential model trained from keras, following the example at deeplearning4j-examples/tensorflow-keras-import-examples/src/main/java/org/deeplearning4j/modelimportexamples/keras/quickstart/SimpleSequentialMlpImport.java at 051c59bd06b38ed39ca92f5940a6ca43b0f34c0f · deeplearning4j/deeplearning4j-examples · GitHub
I am always getting errors, because however I am saving my model in keras is not what dl4j is expecting when I load the .h5 file. My current error:
Exception in thread "main" java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to java.util.List
at org.deeplearning4j.nn.modelimport.keras.KerasSequentialModel.(KerasSequentialModel.java:99)
at org.deeplearning4j.nn.modelimport.keras.KerasSequentialModel.(KerasSequentialModel.java:56)
at org.deeplearning4j.nn.modelimport.keras.KerasModel$ModelBuilder.buildSequential(KerasModel.java:646)
at org.deeplearning4j.nn.modelimport.keras.KerasModelImport.importKerasSequentialModelAndWeights(KerasModelImport.java:156)
at SimpleSequentialMlpImport.main(SimpleSequentialMlpImport.java:78)
Can someone provide me with a minimal example in python of saving a sequential model, that I could then try to load in java to troubleshoot my code?
This is the model I am saving
dmodel = tf.keras.Sequential([
Conv2D(128, 1, activation=tf.keras.activations.tanh,
kernel_initializer=tf.random_uniform_initializer),
tf.keras.layers.LayerNormalization(axis=-1),
Conv2D(self.channel_n, 1, activation=tf.keras.activations.sigmoid,
kernel_initializer=tf.random_uniform_initializer),
])
[...]
dmodel.save("model_dl4j.h5", save_format='h5')
And how I am loading
final String SIMPLE_MLP = new File(dataLocalPath,"model_dl4j.h5").getAbsolutePath();
KerasModelImport.importKerasSequentialModelAndWeights(SIMPLE_MLP);