0

I'm trying to import a Keras model trained in Python with DL4J and I'm getting the following error:

11:39:22.588 [main] Exception in thread "main" java.lang.IllegalStateException: Invalid input type: Batch norm layer expected input of type CNN, CNN Flat or FF, got InputTypeRecurrent(10,timeSeriesLength=24,format=NWC) for layer index -1, layer name = batch_normalization_1
    at org.deeplearning4j.nn.conf.layers.BatchNormalization.getOutputType(BatchNormalization.java:130)
    at org.deeplearning4j.nn.modelimport.keras.layers.normalization.KerasBatchNormalization.getOutputType(KerasBatchNormalization.java:165)
    at org.deeplearning4j.nn.modelimport.keras.KerasModel.inferOutputTypes(KerasModel.java:473)
    at org.deeplearning4j.nn.modelimport.keras.KerasModel.<init>(KerasModel.java:186)
    at org.deeplearning4j.nn.modelimport.keras.KerasModel.<init>(KerasModel.java:99)
    at org.deeplearning4j.nn.modelimport.keras.utils.KerasModelBuilder.buildModel(KerasModelBuilder.java:311)
    at org.deeplearning4j.nn.modelimport.keras.KerasModelImport.importKerasModelAndWeights(KerasModelImport.java:167)
    at edu.mit.ll.seamnet.SpeechEnhancement.runBatchNormErrModel(SpeechEnhancement.java:161)
    at edu.mit.ll.seamnet.SpeechEnhancement.main(SpeechEnhancement.java:172)

This error seems to be documented and, according to the issue report, a fix was implemented in later versions of DL4J. That said, I'm still seeing this error. I'm I missing something?

I'm using DL4J version 1.0.0-M1

Python code to save a simple model that generates this error:

in_layer = Input((25, 25,))
x = Conv1D(filters=10, kernel_size=2)(in_layer)
out_layer = BatchNormalization()(x)
model = Model(in_layer, out_layer)
model.save("batchNormError.h5")

Here's the DL4J code I'm using to import the model:

String modelPath ="batchNormError.h5";
ComputationGraph model = KerasModelImport.importKerasModelAndWeights(modelPath);

Any help will be greatly appreciated.

  • Hi, this was indeed an issue and a PR has been created: https://github.com/eclipse/deeplearning4j/pull/9338 - after that you can pull from snapshots for the fix. – Adam Gibson Jun 03 '21 at 02:19
  • @AdamGibson Do I have to build from source or can I update the Maven artifact version? If building, can you point me to instructions? If Maven, what would the proper version tag be? Thank you! – Joel Acevedo Jun 03 '21 at 12:52
  • Hi, till this pull request is merged, you'll have to pull this branch and build from source: https://github.com/eclipse/deeplearning4j/pull/9338 again though just run mvn clean install on the relevant modules, not the whole thing. Otherwise you have to compile c++ and a bunch of unrelated things. For your use case just deeplearning4j-nn is all you need. Please keep an eye on this pull request and when it is merged, we will run snapshot builds. – Adam Gibson Jun 03 '21 at 23:24
  • @AdamGibson Thank you! I see that the PR has been merged but I don't see a new Maven snapshot. How much time does it usually take from merge to build? I'm working on a tight schedule and was wondering if I would see the fix soon or if I should switch to a different technology to meet my deadline. Thanks again. – Joel Acevedo Jun 08 '21 at 12:45
  • Hi Joel: I've published new snapshots, but just of note here for that 1 module you can also just clone the master branch and run mvn clean install -DskipTests on just the associated deeplearning4j-nn and deeplearning4j-modelimport - there's no reason not to at least try it with what you have. We'll also be publishing a follow up release within a few weeks. However, If you need an SLA that meets your specific needs please feel free to contact me on the community forums. From next week we'll have nightlies published which should help. – Adam Gibson Jun 08 '21 at 21:40

0 Answers0