You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
根据工具解决了dll缺失问题,但是运行还是报错,ptions.TFFailedPreconditionException: Could not find variable batch_normalization_170/moving_mean. This could mean that the variable has been deleted. In TF1, it can also mean the variable is uninitialized. Debug info: container=localhost, status error message=Resource localhost/batch_normalization_170/moving_mean/class tensorflow::Var does not exist.
在python代码里可以正常推理,模型使用的是:https://github.com/KichangKim/DeepDanbooru,
这个模型的.h5 和 .pb 在python里 都能正常推理,但是tfjava 就是报错
是的
2024-06-14 11:31:35.282952: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable TF_ENABLE_ONEDNN_OPTS=0.
2024-06-14 11:31:35.477578: I tensorflow/cc/saved_model/reader.cc:83] Reading SavedModel from: E:\Download\mymodel\deepdanbooru-v3-20211112
2024-06-14 11:31:35.533223: I tensorflow/cc/saved_model/reader.cc:51] Reading meta graph with tags { serve }
2024-06-14 11:31:35.533251: I tensorflow/cc/saved_model/reader.cc:146] Reading SavedModel debug info (if present) from: E:\Download\mymodel\deepdanbooru-v3-20211112
2024-06-14 11:31:35.533351: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: SSE SSE2 SSE3 SSE4.1 SSE4.2 AVX2 AVX_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
2024-06-14 11:31:36.092973: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:388] MLIR V1 optimization pass is not enabled
2024-06-14 11:31:36.136289: I tensorflow/cc/saved_model/loader.cc:234] Restoring SavedModel bundle.
2024-06-14 11:31:37.619728: I tensorflow/cc/saved_model/loader.cc:218] Running initialization op on SavedModel bundle at path: E:\Download\mymodel\deepdanbooru-v3-20211112
2024-06-14 11:31:38.008834: I tensorflow/cc/saved_model/loader.cc:317] SavedModel load for tags { serve }; Status: success: OK. Took 2531231 microseconds.
DenseTFloat32(shape=[1, 512, 512, 3])
2024-06-14 11:31:40.720244: W tensorflow/core/framework/local_rendezvous.cc:404] Local rendezvous is aborting with status: FAILED_PRECONDITION: Could not find variable batch_normalization_89/beta. This could mean that the variable has been deleted. In TF1, it can also mean the variable is uninitialized. Debug info: container=localhost, status error message=Resource localhost/batch_normalization_89/beta/class tensorflow::Var does not exist.
[[{{function_node __inference_serving_default_11824}}{{node resnet_custom_v3_1/batch_normalization_89_1/Cast_3/ReadVariableOp}}]]
Exception in thread "main" org.tensorflow.exceptions.TFFailedPreconditionException: Could not find variable batch_normalization_89/beta. This could mean that the variable has been deleted. In TF1, it can also mean the variable is uninitialized. Debug info: container=localhost, status error message=Resource localhost/batch_normalization_89/beta/class tensorflow::Var does not exist.
[[{{function_node __inference_serving_default_11824}}{{node resnet_custom_v3_1/batch_normalization_89_1/Cast_3/ReadVariableOp}}]]
at org.tensorflow.internal.c_api.AbstractTF_Status.throwExceptionIfNotOK(AbstractTF_Status.java:84)
at org.tensorflow.Session.run(Session.java:835)
at org.tensorflow.Session$Runner.runHelper(Session.java:558)
at org.tensorflow.Session$Runner.run(Session.java:485)
at com.drsle3.douzhanpro.qingfeng.common.PredictNN.main(PredictNN.java:26)
Batch norm can be a pain in Keras, can you try setting the model so it's not trainable before saving out the SavedModel in Python? I think it's failing to find a variable that should be fixed after training, but it might have saved the training version of the model. Alternatively, it looks like it might also behave a little differently saved on GPU vs CPU, so you could try loading it directly into a GPU with the config options.
Activity
saudet commentedon Jun 13, 2024
Please follow the instructions at https://github.com/bytedeco/javacpp-presets/wiki/Debugging-UnsatisfiedLinkError-on-Windows
LEEay commentedon Jun 14, 2024
根据工具解决了dll缺失问题,但是运行还是报错,ptions.TFFailedPreconditionException: Could not find variable batch_normalization_170/moving_mean. This could mean that the variable has been deleted. In TF1, it can also mean the variable is uninitialized. Debug info: container=localhost, status error message=Resource localhost/batch_normalization_170/moving_mean/class tensorflow::Var does not exist.
在python代码里可以正常推理,模型使用的是:https://github.com/KichangKim/DeepDanbooru,
这个模型的.h5 和 .pb 在python里 都能正常推理,但是tfjava 就是报错
LEEay commentedon Jun 14, 2024
https://github.com/KichangKim/DeepDanbooru
Craigacp commentedon Jun 14, 2024
TF-Java doesn't support h5 files. If you load the model in in TF Python then save it as a TF SavedModel then it should work.
LEEay commentedon Jun 14, 2024
我是转成了.pb模型,
`import tensorflow as tf
import tf2onnx
loaded_model = tf.keras.models.load_model(r"E:\Download\model-resnet_custom_v3.h5", compile=False)
保存模型为.pb
tf.saved_model.save(loaded_model, r"E:\Download\mymodel\deepdanbooru-v3-20211112")
加载已保存的模型
loaded_model = tf.saved_model.load(r"E:\Download\mymodel\deepdanbooru-v3-20211112\saved_model.pb")`
使用的是https://github.com/KichangKim/DeepDanbooru/tags 里面的 v3-20211112-sgd-e28
转化后在tfjava里运行报错
Session session = SavedModelBundle.load("E:\\Download\\mymodel\\deepdanbooru-v3-20211112", "serve").session(); FloatNdArray matrix3d = NdArrays.ofFloats(org.tensorflow.ndarray.Shape.of(1, 512, 512, 3)); TFloat32 rank3Tensor = TFloat32.tensorOf(matrix3d); System.out.println(rank3Tensor.toString()); Tensor resultTensor = session.runner() .feed("serving_default_inputs:0", rank3Tensor) .fetch("StatefulPartitionedCall:0") .run().get(0); System.out.println(resultTensor.shape()); session.close();Craigacp commentedon Jun 14, 2024
It has the same error as your earlier comment?
LEEay commentedon Jun 14, 2024
是的
2024-06-14 11:31:35.282952: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable
TF_ENABLE_ONEDNN_OPTS=0.2024-06-14 11:31:35.477578: I tensorflow/cc/saved_model/reader.cc:83] Reading SavedModel from: E:\Download\mymodel\deepdanbooru-v3-20211112
2024-06-14 11:31:35.533223: I tensorflow/cc/saved_model/reader.cc:51] Reading meta graph with tags { serve }
2024-06-14 11:31:35.533251: I tensorflow/cc/saved_model/reader.cc:146] Reading SavedModel debug info (if present) from: E:\Download\mymodel\deepdanbooru-v3-20211112
2024-06-14 11:31:35.533351: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: SSE SSE2 SSE3 SSE4.1 SSE4.2 AVX2 AVX_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
2024-06-14 11:31:36.092973: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:388] MLIR V1 optimization pass is not enabled
2024-06-14 11:31:36.136289: I tensorflow/cc/saved_model/loader.cc:234] Restoring SavedModel bundle.
2024-06-14 11:31:37.619728: I tensorflow/cc/saved_model/loader.cc:218] Running initialization op on SavedModel bundle at path: E:\Download\mymodel\deepdanbooru-v3-20211112
2024-06-14 11:31:38.008834: I tensorflow/cc/saved_model/loader.cc:317] SavedModel load for tags { serve }; Status: success: OK. Took 2531231 microseconds.
DenseTFloat32(shape=[1, 512, 512, 3])
2024-06-14 11:31:40.720244: W tensorflow/core/framework/local_rendezvous.cc:404] Local rendezvous is aborting with status: FAILED_PRECONDITION: Could not find variable batch_normalization_89/beta. This could mean that the variable has been deleted. In TF1, it can also mean the variable is uninitialized. Debug info: container=localhost, status error message=Resource localhost/batch_normalization_89/beta/class tensorflow::Var does not exist.
[[{{function_node __inference_serving_default_11824}}{{node resnet_custom_v3_1/batch_normalization_89_1/Cast_3/ReadVariableOp}}]]
Exception in thread "main" org.tensorflow.exceptions.TFFailedPreconditionException: Could not find variable batch_normalization_89/beta. This could mean that the variable has been deleted. In TF1, it can also mean the variable is uninitialized. Debug info: container=localhost, status error message=Resource localhost/batch_normalization_89/beta/class tensorflow::Var does not exist.
[[{{function_node __inference_serving_default_11824}}{{node resnet_custom_v3_1/batch_normalization_89_1/Cast_3/ReadVariableOp}}]]
at org.tensorflow.internal.c_api.AbstractTF_Status.throwExceptionIfNotOK(AbstractTF_Status.java:84)
at org.tensorflow.Session.run(Session.java:835)
at org.tensorflow.Session$Runner.runHelper(Session.java:558)
at org.tensorflow.Session$Runner.run(Session.java:485)
at com.drsle3.douzhanpro.qingfeng.common.PredictNN.main(PredictNN.java:26)
Craigacp commentedon Jun 14, 2024
Batch norm can be a pain in Keras, can you try setting the model so it's not trainable before saving out the SavedModel in Python? I think it's failing to find a variable that should be fixed after training, but it might have saved the training version of the model. Alternatively, it looks like it might also behave a little differently saved on GPU vs CPU, so you could try loading it directly into a GPU with the config options.
LEEay commentedon Jun 17, 2024
我使用官方方法 把模型转成onnx后,用onnx代码,可以推理并获得结果
onnx代码
Craigacp commentedon Jun 17, 2024
So it didn't change if you exported it after setting it into eval mode, but tf2onnx made a ONNX model which worked?
LEEay commentedon Jun 17, 2024
#543 (comment)
转成pb格式后
python -m tf2onnx.convert --saved-model mymodel/deepdanbooru-v3-20211112/ --output mymodel/onnxmodel1.onnx --opset 9
使用命令转成onnx,然后用onnx的java代码简单推理可以正常使用
winne42 commentedon Jan 4, 2025
@LEEay @Craigacp can this issue be closed?