# A fatal error has been detected by the Java Runtime Environment

**URL:** <https://community.konduit.ai/t/a-fatal-error-has-been-detected-by-the-java-runtime-environment/3259>\
**Category:** DL4J\
**Created:** [October 21, 2024, 9:47am UTC](https://community.konduit.ai/t/a-fatal-error-has-been-detected-by-the-java-runtime-environment/3259 "2024-10-21T09:47:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![MRV](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@MRV](https://community.konduit.ai/u/MRV)\
**Post date:** [October 21, 2024, 9:47am UTC](https://community.konduit.ai/t/a-fatal-error-has-been-detected-by-the-java-runtime-environment/3259/1 "2024-10-21T09:47:42Z")

</div>

I am trying to load a .h5 model (tf.keras) in scala using deeplearning4j.

I’m using SBT with following dependencies :

```auto
libraryDependencies ++= Seq(
  "org.deeplearning4j" % "deeplearning4j-core" % "1.0.0-M2.1",
  "org.nd4j" % "nd4j-native" % "1.0.0-M2.1",
)

```

When I try to load models containing LSTM or RNN layers, the following error is raised:

```auto
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x000072104b173475, pid=76220, tid=76222
#
# JRE version: OpenJDK Runtime Environment (11.0.24+8) (build 11.0.24+8-post-Ubuntu-1ubuntu322.04)
# Java VM: OpenJDK 64-Bit Server VM (11.0.24+8-post-Ubuntu-1ubuntu322.04, mixed mode, sharing, tiered, compressed oops, g1 gc, linux-amd64)
# Problematic frame:
# C [libnd4jcpu.so+0x1573475] sd::NDArray::getOffset(long long) const+0x25
#
# Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport -p%p -s%s -c%c -d%d -P%P -u%u -g%g -- %E" (or dumping to /home/userr/IdeaProjects/Tor_scala/core.76220)
#
# An error report file with more information is saved as:
# /home/userr/IdeaProjects/Tor_scala/hs_err_pid76220.log

Process finished with exit code 130 (interrupted by signal 2:SIGINT)

```

However, models containing layers other than LSTM/RNN doesnt raise any errors. I tried loading models containing Dense layers and CNN. They worked perfectly. This issue was seen only when I try with LSTM/RNN layers.

I tried with other versions - M2, M1.1 and M1  
The same issue was seen with M2 version too.

But when I used M1.1 and M1, I got the following error for all models regardless of the type of layers used in the model:

```auto
Debug: Deallocating org.bytedeco.hdf5.Group[address=0x71ce3568b530,position=0,limit=1,capacity=1,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x71ce3568b530,deallocatorAddress=0x71ce026a7dc0]]
[error] java.lang.NullPointerException: Cannot invoke "org.deeplearning4j.nn.modelimport.keras.KerasLayer.getNumParams()" because the return value of "java.util.Map.get(Object)" is null
[error] at org.deeplearning4j.nn.modelimport.keras.utils.KerasModelUtils.importWeights(KerasModelUtils.java:235)
[error] at org.deeplearning4j.nn.modelimport.keras.KerasModel.<init>(KerasModel.java:190)
[error] at org.deeplearning4j.nn.modelimport.keras.KerasModel.<init>(KerasModel.java:99)
[error] at org.deeplearning4j.nn.modelimport.keras.utils.KerasModelBuilder.buildModel(KerasModelBuilder.java:311)
[error] at org.deeplearning4j.nn.modelimport.keras.KerasModelImport.importKerasModelAndWeights(KerasModelImport.java:150)
[error] at tesst$.main(tesst.scala:13)
[error] at tesst.main(tesst.scala)
[error] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[error] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[error] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error] at java.base/java.lang.reflect.Method.invoke(Method.java:569)
[error] stack trace is suppressed; run last Compile / run for the full output
[error] (Compile / run) java.lang.NullPointerException: Cannot invoke "org.deeplearning4j.nn.modelimport.keras.KerasLayer.getNumParams()" because the return value of "java.util.Map.get(Object)" is null
[error] Total time: 3 s, completed 21-Oct-2024, 2:26:27 pm

```

My model was compiled and trained in Python and saved as .h5. Following is my scala code for loading the model:

```auto
import org.deeplearning4j.nn.modelimport.keras.KerasModelImport
import org.deeplearning4j.nn.graph.ComputationGraph

object tesst {
  def main(args: Array[String]): Unit = {
    // Path to your .h5 file
    System.setProperty("org.bytedeco.javacpp.logger.debug", "true")
    System.setProperty("org.bytedeco.javacpp.logger", "sl4j")
    val modelPath="/home/userr/Models/lstm_actual.h5"
    val model: ComputationGraph = KerasModelImport.importKerasModelAndWeights(modelPath,false)
    println(model.summary())
  }
}

```

I’m new to DL4J. Can someone guide me and let me know why it happens?

---

<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:** [October 21, 2024, 11:28am UTC](https://community.konduit.ai/t/a-fatal-error-has-been-detected-by-the-java-runtime-environment/3259/2 "2024-10-21T11:28:22Z")

</div>

@MRV could you post the configuration and keras version?

---

<div class="post-metadata">

**Author:** ![MRV](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@MRV](https://community.konduit.ai/u/MRV)\
**Post date:** [October 22, 2024, 5:38am UTC](https://community.konduit.ai/t/a-fatal-error-has-been-detected-by-the-java-runtime-environment/3259/3 "2024-10-22T05:38:40Z")

</div>

@agibsonccc  
Model Type - Functional  
print(model. **class** ) \>\> \<class ‘keras.src.engine.functional.Functional’\>  
TensorFlow version: 2.15.0  
Keras version: 2.15.0  
Keras backend: tensorflow

---

<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:** [October 24, 2024, 3:36am UTC](https://community.konduit.ai/t/a-fatal-error-has-been-detected-by-the-java-runtime-environment/3259/4 "2024-10-24T03:36:26Z")

</div>

@MRV that’s not what I needed. Can you dump the json of the file you’re importing or use model.summary()?

---

<div class="post-metadata">

**Author:** ![MRV](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@MRV](https://community.konduit.ai/u/MRV)\
**Post date:** [October 25, 2024, 4:42am UTC](https://community.konduit.ai/t/a-fatal-error-has-been-detected-by-the-java-runtime-environment/3259/5 "2024-10-25T04:42:52Z")

</div>

@agibsonccc

The details of the model is given below:

Model configuration:  
{‘name’: ‘model\_6’, ‘trainable’: True, ‘layers’: [{‘module’: ‘keras.layers’, ‘class\_name’: ‘InputLayer’, ‘config’: {‘batch\_input\_shape’: (None, 43), ‘dtype’: ‘int32’, ‘sparse’: False, ‘ragged’: False, ‘name’: ‘main\_input1’}, ‘registered\_name’: None, ‘name’: ‘main\_input1’, ‘inbound\_nodes’: }, {‘module’: ‘keras.layers’, ‘class\_name’: ‘Embedding’, ‘config’: {‘name’: ‘embedding\_10’, ‘trainable’: False, ‘dtype’: ‘float32’, ‘batch\_input\_shape’: (None, 43), ‘input\_dim’: 10000, ‘output\_dim’: 50, ‘embeddings\_initializer’: {‘module’: ‘keras.initializers’, ‘class\_name’: ‘RandomUniform’, ‘config’: {‘minval’: -0.05, ‘maxval’: 0.05, ‘seed’: None}, ‘registered\_name’: None}, ‘embeddings\_regularizer’: None, ‘activity\_regularizer’: None, ‘embeddings\_constraint’: None, ‘mask\_zero’: False, ‘input\_length’: 43}, ‘registered\_name’: None, ‘build\_config’: {‘input\_shape’: (None, 43)}, ‘name’: ‘embedding\_10’, ‘inbound\_nodes’: [[[‘main\_input1’, 0, 0, {}]]]}, {‘module’: ‘keras.layers’, ‘class\_name’: ‘InputLayer’, ‘config’: {‘batch\_input\_shape’: (None, 9), ‘dtype’: ‘float32’, ‘sparse’: False, ‘ragged’: False, ‘name’: ‘main\_input2’}, ‘registered\_name’: None, ‘name’: ‘main\_input2’, ‘inbound\_nodes’: }, {‘module’: ‘keras.layers’, ‘class\_name’: ‘LSTM’, ‘config’: {‘name’: ‘lstm\_2’, ‘trainable’: True, ‘dtype’: ‘float32’, ‘return\_sequences’: False, ‘return\_state’: False, ‘go\_backwards’: False, ‘stateful’: False, ‘unroll’: False, ‘time\_major’: False, ‘units’: 64, ‘activation’: ‘tanh’, ‘recurrent\_activation’: ‘sigmoid’, ‘use\_bias’: True, ‘kernel\_initializer’: {‘module’: ‘keras.initializers’, ‘class\_name’: ‘GlorotUniform’, ‘config’: {‘seed’: None}, ‘registered\_name’: None}, ‘recurrent\_initializer’: {‘module’: ‘keras.initializers’, ‘class\_name’: ‘Orthogonal’, ‘config’: {‘gain’: 1.0, ‘seed’: None}, ‘registered\_name’: None}, ‘bias\_initializer’: {‘module’: ‘keras.initializers’, ‘class\_name’: ‘Zeros’, ‘config’: {}, ‘registered\_name’: None}, ‘unit\_forget\_bias’: True, ‘kernel\_regularizer’: None, ‘recurrent\_regularizer’: None, ‘bias\_regularizer’: None, ‘activity\_regularizer’: None, ‘kernel\_constraint’: None, ‘recurrent\_constraint’: None, ‘bias\_constraint’: None, ‘dropout’: 0.0, ‘recurrent\_dropout’: 0.0, ‘implementation’: 2}, ‘registered\_name’: None, ‘build\_config’: {‘input\_shape’: (None, 43, 50)}, ‘name’: ‘lstm\_2’, ‘inbound\_nodes’: [[[‘embedding\_10’, 0, 0, {}]]]}, {‘module’: ‘keras.layers’, ‘class\_name’: ‘Dense’, ‘config’: {‘name’: ‘dense\_14’, ‘trainable’: True, ‘dtype’: ‘float32’, ‘units’: 64, ‘activation’: ‘relu’, ‘use\_bias’: True, ‘kernel\_initializer’: {‘module’: ‘keras.initializers’, ‘class\_name’: ‘GlorotUniform’, ‘config’: {‘seed’: None}, ‘registered\_name’: None}, ‘bias\_initializer’: {‘module’: ‘keras.initializers’, ‘class\_name’: ‘Zeros’, ‘config’: {}, ‘registered\_name’: None}, ‘kernel\_regularizer’: None, ‘bias\_regularizer’: None, ‘activity\_regularizer’: None, ‘kernel\_constraint’: None, ‘bias\_constraint’: None}, ‘registered\_name’: None, ‘build\_config’: {‘input\_shape’: (None, 9)}, ‘name’: ‘dense\_14’, ‘inbound\_nodes’: [[[‘main\_input2’, 0, 0, {}]]]}, {‘module’: ‘keras.layers’, ‘class\_name’: ‘Dropout’, ‘config’: {‘name’: ‘dropout\_16’, ‘trainable’: True, ‘dtype’: ‘float32’, ‘rate’: 0.5, ‘noise\_shape’: None, ‘seed’: None}, ‘registered\_name’: None, ‘build\_config’: {‘input\_shape’: (None, 64)}, ‘name’: ‘dropout\_16’, ‘inbound\_nodes’: [[[‘lstm\_2’, 0, 0, {}]]]}, {‘module’: ‘keras.layers’, ‘class\_name’: ‘Dropout’, ‘config’: {‘name’: ‘dropout\_17’, ‘trainable’: True, ‘dtype’: ‘float32’, ‘rate’: 0.1, ‘noise\_shape’: None, ‘seed’: None}, ‘registered\_name’: None, ‘build\_config’: {‘input\_shape’: (None, 64)}, ‘name’: ‘dropout\_17’, ‘inbound\_nodes’: [[[‘dense\_14’, 0, 0, {}]]]}, {‘module’: ‘keras.layers’, ‘class\_name’: ‘Concatenate’, ‘config’: {‘name’: ‘concatenate\_8’, ‘trainable’: True, ‘dtype’: ‘float32’, ‘axis’: -1}, ‘registered\_name’: None, ‘build\_config’: {‘input\_shape’: [(None, 64), (None, 64)]}, ‘name’: ‘concatenate\_8’, ‘inbound\_nodes’: [[[‘dropout\_16’, 0, 0, {}], [‘dropout\_17’, 0, 0, {}]]]}, {‘module’: ‘keras.layers’, ‘class\_name’: ‘Dense’, ‘config’: {‘name’: ‘dense\_15’, ‘trainable’: True, ‘dtype’: ‘float32’, ‘units’: 1, ‘activation’: ‘sigmoid’, ‘use\_bias’: True, ‘kernel\_initializer’: {‘module’: ‘keras.initializers’, ‘class\_name’: ‘GlorotUniform’, ‘config’: {‘seed’: None}, ‘registered\_name’: None}, ‘bias\_initializer’: {‘module’: ‘keras.initializers’, ‘class\_name’: ‘Zeros’, ‘config’: {}, ‘registered\_name’: None}, ‘kernel\_regularizer’: None, ‘bias\_regularizer’: None, ‘activity\_regularizer’: None, ‘kernel\_constraint’: None, ‘bias\_constraint’: None}, ‘registered\_name’: None, ‘build\_config’: {‘input\_shape’: (None, 128)}, ‘name’: ‘dense\_15’, ‘inbound\_nodes’: [[[‘concatenate\_8’, 0, 0, {}]]]}], ‘input\_layers’: [[‘main\_input1’, 0, 0], [‘main\_input2’, 0, 0]], ‘output\_layers’: [[‘dense\_15’, 0, 0]]}

```auto
Model architecture:
Model: "model_6"
__________________________________________________________________________________________________
 Layer (type) Output Shape Param # Connected to                  
==================================================================================================
 main_input1 (InputLayer) [(None, 43)] 0 []                            
                                                                                                  
 embedding_10 (Embedding) (None, 43, 50) 500000 ['main_input1[0][0]']         
                                                                                                  
 main_input2 (InputLayer) [(None, 9)] 0 []                            
                                                                                                  
 lstm_2 (LSTM) (None, 64) 29440 ['embedding_10[0][0]']        
                                                                                                  
 dense_14 (Dense) (None, 64) 640 ['main_input2[0][0]']         
                                                                                                  
 dropout_16 (Dropout) (None, 64) 0 ['lstm_2[0][0]']              
                                                                                                  
 dropout_17 (Dropout) (None, 64) 0 ['dense_14[0][0]']            
                                                                                                  
 concatenate_8 (Concatenate (None, 128) 0 ['dropout_16[0][0]',          
 ) 'dropout_17[0][0]']          
                                                                                                  
 dense_15 (Dense) (None, 1) 129 ['concatenate_8[0][0]']       
                                                                                                  
==================================================================================================
Total params: 530209 (2.02 MB)
Trainable params: 30209 (118.00 KB)
Non-trainable params: 500000 (1.91 MB)
__________________________________________________________________________________________________

```

Model type: Functional

---

<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:** [October 29, 2024, 12:40pm UTC](https://community.konduit.ai/t/a-fatal-error-has-been-detected-by-the-java-runtime-environment/3259/6 "2024-10-29T12:40:45Z")

</div>

@MRV apologies please ping me if I don’t get back to you. looking at the model again it might be an issue with functional models specifically. Could you try converting this to a sequential and see if you still have that issue?  
It’s still hard to tell why a nullpointer is being thrown there. It looks like a native crash but could also be a java one. There’s a mixed cause there…
