1

I am relatively new to Java and am currently working on a neural network in deeplearning4j. I've got a sequential Keras model (.h5) and try to import it into my project using the following lines:

String path = "C:\\Users\\username\\Documents\\AIProject\\AiProjectDl4j\\data\\InceptionResNetV2CatAndDog.h5";
MultiLayerNetwork model = KerasModelImport.importKerasSequentialModelAndWeights(path);

However, when I run the code I get the following error that I cannot find any solution to online:

Exception in thread "main" java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to java.util.List
at org.deeplearning4j.nn.modelimport.keras.KerasSequentialModel.<init>(KerasSequentialModel.java:102)
at org.deeplearning4j.nn.modelimport.keras.KerasSequentialModel.<init>(KerasSequentialModel.java:61)
at org.deeplearning4j.nn.modelimport.keras.utils.KerasModelBuilder.buildSequential(KerasModelBuilder.java:320)
at org.deeplearning4j.nn.modelimport.keras.KerasModelImport.importKerasSequentialModelAndWeights(KerasModelImport.java:195)
at catsdogs.Model.main(Model.java:80)

Line 80 is the line with the Keras import. I would be very thankful for any kind of help since I don't even get why it says anything about Hashmap being cast to List since I don't have either anywhere near my code and the MultiLayerNetwork isn't of either type. If there is any other way to import your own .h5 model, I'd try that as well.

art-m
  • 9
  • 5
  • Are you using the most recent version of dl4j (1.0.0-beta7)? And are you sure you have a Sequential Model and not a functional model? – Paul Dubs May 26 '20 at 15:24
  • I've been using beta2 but changing it to version 7 did not help. As far as I know my model is sequential but to check I've tried to import it as a functional model which gave me an error (Expected model class name Model (found Sequential)) that, i guess, confirmes it. Unfortunately I cannot find a way to inspect my .h5 file to look if there's any misconfiguration or anything that could prevent it from being imported – art-m May 27 '20 at 16:40
  • if the model is based on tf.keras (in contrast to normal keras), then you *need* beta7. – Paul Dubs May 27 '20 at 20:37

0 Answers0