# Keras functional model with custom layer import error

**URL:** <https://community.konduit.ai/t/keras-functional-model-with-custom-layer-import-error/2126>\
**Category:** DL4J\
**Created:** [December 15, 2022, 2:47pm UTC](https://community.konduit.ai/t/keras-functional-model-with-custom-layer-import-error/2126 "2022-12-15T14:47:53Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vamshi](https://avatars.discourse-cdn.com/v4/letter/v/ecccb3/32.png) [@Vamshi](https://community.konduit.ai/u/Vamshi)\
**Post date:** [December 15, 2022, 2:47pm UTC](https://community.konduit.ai/t/keras-functional-model-with-custom-layer-import-error/2126/1 "2022-12-15T14:47:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![treo](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/treo/32/47_2.png) [@treo](https://community.konduit.ai/u/treo)\
**Post date:** [December 15, 2022, 2:56pm UTC](https://community.konduit.ai/t/keras-functional-model-with-custom-layer-import-error/2126/2 "2022-12-15T14:56:13Z")

</div>

That looks like a stacktrace out of a JVM crash file. Put that file on [gist.github.com](http://gist.github.com) and link that gist here.

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

---

<div class="post-metadata">

**Author:** ![Vamshi](https://avatars.discourse-cdn.com/v4/letter/v/ecccb3/32.png) [@Vamshi](https://community.konduit.ai/u/Vamshi)\
**Post date:** [December 15, 2022, 3:18pm UTC](https://community.konduit.ai/t/keras-functional-model-with-custom-layer-import-error/2126/3 "2022-12-15T15:18:49Z")

</div>

> [@treo](#):
>
> VM crash while reading your HDF5 file.

Hi @treo  
Please find the attached link

> <https://gist.github.com/VamshiG/ab3904536af2712569d398559a2d84a0>

---

<div class="post-metadata">

**Author:** ![treo](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/treo/32/47_2.png) [@treo](https://community.konduit.ai/u/treo)\
**Post date:** [December 15, 2022, 3:36pm UTC](https://community.konduit.ai/t/keras-functional-model-with-custom-layer-import-error/2126/4 "2022-12-15T15:36:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Vamshi](https://avatars.discourse-cdn.com/v4/letter/v/ecccb3/32.png) [@Vamshi](https://community.konduit.ai/u/Vamshi)\
**Post date:** [December 15, 2022, 4:07pm UTC](https://community.konduit.ai/t/keras-functional-model-with-custom-layer-import-error/2126/5 "2022-12-15T16:07:09Z")

</div>

My bad. sorry

> <https://gist.github.com/VamshiG/bbf3dd06a712a0924a87f080e919caf1>

---

<div class="post-metadata">

**Author:** ![treo](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/treo/32/47_2.png) [@treo](https://community.konduit.ai/u/treo)\
**Post date:** [December 15, 2022, 4:11pm UTC](https://community.konduit.ai/t/keras-functional-model-with-custom-layer-import-error/2126/6 "2022-12-15T16:11:55Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [December 15, 2022, 10:02pm UTC](https://community.konduit.ai/t/keras-functional-model-with-custom-layer-import-error/2126/7 "2022-12-15T22:02:14Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![bjohnson](https://avatars.discourse-cdn.com/v4/letter/b/e9a140/32.png) [@bjohnson](https://community.konduit.ai/u/bjohnson)\
**Post date:** [December 16, 2022, 4:00pm UTC](https://community.konduit.ai/t/keras-functional-model-with-custom-layer-import-error/2126/8 "2022-12-16T16:00:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [December 18, 2022, 12:03am UTC](https://community.konduit.ai/t/keras-functional-model-with-custom-layer-import-error/2126/9 "2022-12-18T00:03:13Z")

</div>

@bjohnson yes that would be amazing thank you!

---

<div class="post-metadata">

**Author:** ![nas-sh](https://avatars.discourse-cdn.com/v4/letter/n/a3d4f5/32.png) [@nas-sh](https://community.konduit.ai/u/nas-sh)\
**Post date:** [June 8, 2023, 3:49pm UTC](https://community.konduit.ai/t/keras-functional-model-with-custom-layer-import-error/2126/10 "2023-06-08T15:49:48Z")

</div>

@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?

---

<div class="post-metadata">

**Author:** ![nas-sh](https://avatars.discourse-cdn.com/v4/letter/n/a3d4f5/32.png) [@nas-sh](https://community.konduit.ai/u/nas-sh)\
**Post date:** [June 8, 2023, 5:25pm UTC](https://community.konduit.ai/t/keras-functional-model-with-custom-layer-import-error/2126/11 "2023-06-08T17:25:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [June 8, 2023, 10:37pm UTC](https://community.konduit.ai/t/keras-functional-model-with-custom-layer-import-error/2126/12 "2023-06-08T22:37:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nas-sh](https://avatars.discourse-cdn.com/v4/letter/n/a3d4f5/32.png) [@nas-sh](https://community.konduit.ai/u/nas-sh)\
**Post date:** [June 9, 2023, 10:57pm UTC](https://community.konduit.ai/t/keras-functional-model-with-custom-layer-import-error/2126/13 "2023-06-09T22:57:26Z")

</div>

@agibsonccc you should be able to reproduce the error by importing our h5 file [here](https://github.com/sequoiarose/race/blob/smoke/race-earth/src/main/python/smoke-segmentation/smoke_segmentation_512.h5). 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);
