Keras functional model with custom layer import error

I am geting below java runtime error while loading a keras model

  V  [libjvm.dylib+0x584935]  jni_SetLongField+0xc5
  C  [libjnihdf5.dylib+0x8196]  Java_org_bytedeco_hdf5_Attribute_read__Lorg_bytedeco_hdf5_DataType_2Lorg_bytedeco_javacpp_BytePointer_2+0x2a6
  j  org.bytedeco.hdf5.Attribute.read(Lorg/bytedeco/hdf5/DataType;Lorg/bytedeco/javacpp/BytePointer;)V+0
  j  org.deeplearning4j.nn.modelimport.keras.Hdf5Archive.readAttributeAsString(Lorg/bytedeco/hdf5/Attribute;)Ljava/lang/String;+42
  j  org.deeplearning4j.nn.modelimport.keras.Hdf5Archive.readAttributeAsString(Ljava/lang/String;[Ljava/lang/String;)Ljava/lang/String;+62
  j  org.deeplearning4j.nn.modelimport.keras.utils.KerasModelUtils.importWeights(Lorg/deeplearning4j/nn/modelimport/keras/Hdf5Archive;Ljava/lang/String;Ljava/util/Map;ILjava/lang/String;)V+270
  j  org.deeplearning4j.nn.modelimport.keras.KerasModel.<init>(Ljava/lang/String;Ljava/lang/String;Lorg/deeplearning4j/nn/modelimport/keras/Hdf5Archive;Ljava/lang/String;Ljava/lang/String;Lorg/deeplearning4j/nn/modelimport/keras/Hdf5Archive;Z[ILorg/deeplearning4j/nn/modelimport/keras/KerasLayer$DimOrder;)V+638
  j  org.deeplearning4j.nn.modelimport.keras.KerasModel.<init>(Lorg/deeplearning4j/nn/modelimport/keras/utils/KerasModelBuilder;)V+37
  j  org.deeplearning4j.nn.modelimport.keras.utils.KerasModelBuilder.buildModel()Lorg/deeplearning4j/nn/modelimport/keras/KerasModel;+5
  j  org.deeplearning4j.nn.modelimport.keras.KerasModelImport.importKerasModelAndWeights(Ljava/lang/String;Z)Lorg/deeplearning4j/nn/graph/ComputationGraph;+18
  j  wdnn_maven.wdnn_test.keras_test.main([Ljava/lang/String;)V+25

I am using deeplearning4j 1.0.0-M2.1 on mac m1

Can anyone help me understand whats the issue here

That looks like a stacktrace out of a JVM crash file. Put that file on gist.github.com and link that gist here.

Whatever you are doing seems to result in a JVM crash while reading your HDF5 file.

Hi @treo
Please find the attached link

Well, I’m not a compiler, so I’m not going to read all that code.

I asked for the jvm crash file, it should be called something like hs_err_pid<pid>.log where <pid> is some number.

My bad. sorry

So you are using it in emulated x64 mode. I wonder if something about that may be the issue, as it is very unusual to see a segmentation fault at that particular place.

@agibsonccc what do you think?

@treo I think this might be a data type overflow when hdf5 is reading the file. @Vamshi could you please DM me your model? I’d like to look at this. There’s only so much I can do but I can at least inspect what’s going on with the model file.

I recently saw a similar error importing a model on my Mac (failed on both an Intel and Silicon one) with error at:

V [libjvm.dylib+0x584935] jni_SetLongField+0xc5

The error went away when I removed BatchNormalization from the first layer of model.
I can try to regenerate and upload model if that would be helpful

@bjohnson yes that would be amazing thank you!

@treo @agibsonccc I am getting the same java runtime error as the one posted here by Vamshi. Were you able to find out what the problem is and how to resolve it?

@Vamshi could you find out what the problem was? I am experiencing a similar issue.

@nas-sh same question: do you have something I can see to reproduce this?

@agibsonccc you should be able to reproduce the error by importing our h5 file here. Would you like to see the model in python also?

On Java side, I use the following to import the h5 model which leads to the error in the native code:
KerasModelImport.importKerasModelAndWeights(h5ModelPath, false);