Hi, i’m trying to run a trained tensorflow 2 model using dl4j.
I followed Frozen-Graph-TensorFlow/TensorFlow_v2 at master · leimao/Frozen-Graph-TensorFlow · GitHub example1.py code to save the pb model. (this link was from https://github.com/eclipse/deeplearning4j-examples/blob/master/tensorflow-keras-import-examples/README.md ).
Then in java, using version 1.0.0-M1.1 of nd4j/dl4j i imported the graph using:
byte[] content = IOUtils.toByteArray(new FileInputStream(file));
List<String> inputs= Arrays.asList(INPUTS);
try(GraphRunner graphRunner = GraphRunner.builder().graphBytes(content).inputNames(inputs).build()) {
...
this loads with no errors.
However when i try to run it using:
Map<String,INDArray>output=graphRunner.run(testInput);
where testInput is the map of ind arrays for a sample input i get:
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x000000014c451cc4, pid=54941, tid=10499
#
# JRE version: OpenJDK Runtime Environment Corretto-11.0.11.9.1 (11.0.11+9) (build 11.0.11+9-LTS)
# Java VM: OpenJDK 64-Bit Server VM Corretto-11.0.11.9.1 (11.0.11+9-LTS, mixed mode, tiered, compressed oops, g1 gc, bsd-amd64)
# Problematic frame:
# C [libtensorflow_cc.so.1+0x4b4ecc4] _ZNK10tensorflow4Node4nameEv+0x4
#
# No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /Users/fabrizio/tactile/ai-models/hs_err_pid54941.log
#
# If you would like to submit a bug report, please visit:
# https://github.com/corretto/corretto-11/issues/
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
I also tried to import the same pb file using:
TFGraphMapper.importGraph(file);
as indicated in other examples but in that case i get this error:
Exception in thread "main" java.lang.IllegalStateException: Could not find class for TF Ops: TensorListFromTensor
at org.nd4j.common.base.Preconditions.throwStateEx(Preconditions.java:638)
at org.nd4j.common.base.Preconditions.checkState(Preconditions.java:301)
at org.nd4j.imports.graphmapper.tf.TFGraphMapper.importGraph(TFGraphMapper.java:284)
at org.nd4j.imports.graphmapper.tf.TFGraphMapper.importGraph(TFGraphMapper.java:141)
at org.nd4j.imports.graphmapper.tf.TFGraphMapper.importGraph(TFGraphMapper.java:87)
at org.nd4j.imports.graphmapper.tf.TFGraphMapper.importGraph(TFGraphMapper.java:73)
i cannot tell what’s the issue either way.
i appreciate it if you could point me in the right direction to debug this issue.
thank you
PS: from the log file mentioned above, here is a detailed stack trace:
--------------- T H R E A D ---------------
Current thread (0x00007fe408809000): JavaThread "main" [_thread_in_native, id=10499, stack(0x00007000096bc000,0x00007000097bc000)]
Stack: [0x00007000096bc000,0x00007000097bc000], sp=0x00007000097bb500, free space=1021k
Native frames: (J=compiled Java code, A=aot compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [libtensorflow_cc.so.1+0x4b4ecc4] _ZNK10tensorflow4Node4nameEv+0x4
C [libtensorflow_cc.so.1+0x78824] TF_SessionRun+0x264
C [libjnitensorflow.dylib+0xa97de0] Java_org_bytedeco_tensorflow_global_tensorflow_TF_1SessionRun__Lorg_bytedeco_tensorflow_TF_1Session_2Lorg_bytedeco_tensorflow_TF_1Buffer_2Lorg_bytedeco_tensorflow_TF_1Output_2Lorg_bytedeco_javacpp_PointerPointer_2ILorg_bytedeco_tensorflow_TF_1Output_2Lorg_bytedeco_javacpp_PointerPointer_2ILorg_bytedeco_javacpp_PointerPointer_2ILorg_bytedeco_tensorflow_TF_1Buffer_2Lorg_bytedeco_tensorflow_TF_1Status_2+0x3f0
j org.bytedeco.tensorflow.global.tensorflow.TF_SessionRun(Lorg/bytedeco/tensorflow/TF_Session;Lorg/bytedeco/tensorflow/TF_Buffer;Lorg/bytedeco/tensorflow/TF_Output;Lorg/bytedeco/javacpp/PointerPointer;ILorg/bytedeco/tensorflow/TF_Output;Lorg/bytedeco/javacpp/PointerPointer;ILorg/bytedeco/javacpp/PointerPointer;ILorg/bytedeco/tensorflow/TF_Buffer;Lorg/bytedeco/tensorflow/TF_Status;)V+0
j org.nd4j.tensorflow.conversion.graphrunner.GraphRunner.runTfTensor(Ljava/util/Map;)Ljava/util/Map;+1329
j org.nd4j.tensorflow.conversion.graphrunner.GraphRunner.run(Ljava/util/Map;)Ljava/util/Map;+102
j org.nd4j.tensorflow.conversion.graphrunner.GraphRunner.run(Ljava/util/Map;)Ljava/util/Map;+18
j com.tactile.aimodels.tf.TfModel.main([Ljava/lang/String;)V+56
v ~StubRoutines::call_stub
V [libjvm.dylib+0x3bf51e] _ZN9JavaCalls11call_helperEP9JavaValueRK12methodHandleP17JavaCallArgumentsP6Thread+0x220
V [libjvm.dylib+0x4034dc] _ZL17jni_invoke_staticP7JNIEnv_P9JavaValueP8_jobject11JNICallTypeP10_jmethodIDP18JNI_ArgumentPusherP6Thread+0x122
V [libjvm.dylib+0x4062fb] jni_CallStaticVoidMethod+0x17f
C [libjli.dylib+0x4831] JavaMain+0xad1
C [libjli.dylib+0x6be4] ThreadJavaMain+0x9
C [libsystem_pthread.dylib+0x6109] _pthread_start+0x94
C [libsystem_pthread.dylib+0x1b8b] thread_start+0xf
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j org.bytedeco.tensorflow.global.tensorflow.TF_SessionRun(Lorg/bytedeco/tensorflow/TF_Session;Lorg/bytedeco/tensorflow/TF_Buffer;Lorg/bytedeco/tensorflow/TF_Output;Lorg/bytedeco/javacpp/PointerPointer;ILorg
/bytedeco/tensorflow/TF_Output;Lorg/bytedeco/javacpp/PointerPointer;ILorg/bytedeco/javacpp/PointerPointer;ILorg/bytedeco/tensorflow/TF_Buffer;Lorg/bytedeco/tensorflow/TF_Status;)V+0
j org.nd4j.tensorflow.conversion.graphrunner.GraphRunner.runTfTensor(Ljava/util/Map;)Ljava/util/Map;+1329
j org.nd4j.tensorflow.conversion.graphrunner.GraphRunner.run(Ljava/util/Map;)Ljava/util/Map;+102
j org.nd4j.tensorflow.conversion.graphrunner.GraphRunner.run(Ljava/util/Map;)Ljava/util/Map;+18
j com.tactile.aimodels.tf.TfModel.main([Ljava/lang/String;)V+56
v ~StubRoutines::call_stub
siginfo: si_signo: 11 (SIGSEGV), si_code: 1 (SEGV_MAPERR), si_addr: 0x0000000000000090