-
Notifications
You must be signed in to change notification settings - Fork 202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Caused by: java.lang.UnsatisfiedLinkError: C:\Users\liwan\.javacpp\cache\tensorflow-core-native-1.0.0-rc.1-windows-x86_64.jar\org\tensorflow\internal\c_api\windows-x86_64\jnitensorflow.dll: Can't find dependent libraries #543
Comments
Please follow the instructions at https://github.com/bytedeco/javacpp-presets/wiki/Debugging-UnsatisfiedLinkError-on-Windows |
根据工具解决了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. |
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. |
我是转成了.pb模型, 保存模型为.pbtf.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里运行报错 |
It has the same error as your earlier comment? |
是的 |
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. |
我使用官方方法 把模型转成onnx后,用onnx代码,可以推理并获得结果 try {
// 初始化 ONNX Runtime 环境
OrtEnvironment env = OrtEnvironment.getEnvironment();
// 加载 ONNX 模型
String modelPath = "E:\\Download\\mymodel\\onnxmodel1.onnx";
OrtSession.SessionOptions sessionOptions = new OrtSession.SessionOptions();
OrtSession session = env.createSession(modelPath, sessionOptions);
// 创建 TensorFlow FloatNdArray
FloatNdArray matrix3d = NdArrays.ofFloats(Shape.of(1, 512, 512, 3));
// 填充数据到 FloatNdArray(此处仅为示例,实际使用时应填充实际数据)
// for (int i = 0; i < 512 * 512 * 3; i++) {
// matrix3d.setFloat(1.0f, 0, i / (512 * 512), (i % (512 * 512)) / 512, i % 512);
// }
// 将 FloatNdArray 转换为 FloatBuffer
FloatBuffer floatBuffer = FloatBuffer.allocate((int) matrix3d.size());
matrix3d.scalars().forEachIndexed((coords, scalar) -> floatBuffer.put(scalar.getFloat()));
floatBuffer.flip();
// 创建 ONNX Tensor
long[] inputShape = new long[]{1, 512, 512, 3};
OnnxTensor inputTensor = OnnxTensor.createTensor(env, floatBuffer, inputShape);
// 构建输入映射
Map<String, OnnxTensor> inputs = new HashMap<>();
inputs.put("inputs", inputTensor); // 输入节点名称需要与你的模型匹配
// 运行推理
OrtSession.Result results = session.run(inputs);
// 获取输出 (根据你的模型调整输出节点名称)
OnnxValue outputValue = results.get(0);
float[] outputData = ((OnnxTensor) outputValue).getFloatBuffer().array();
// 打印输出
System.out.println("Model output:");
for (float value : outputData) {
System.out.println(value);
}
// 释放资源
inputTensor.close();
results.close();
session.close();
env.close();
} catch (OrtException e) {
e.printStackTrace();
} |
So it didn't change if you exported it after setting it into eval mode, but tf2onnx made a ONNX model which worked? |
#543 (comment) |
Caused by: java.lang.UnsatisfiedLinkError: C:\Users\liwan.javacpp\cache\tensorflow-core-native-1.0.0-rc.1-windows-x86_64.jar\org\tensorflow\internal\c_api\windows-x86_64\jnitensorflow.dll: Can't find dependent libraries
java 17
The text was updated successfully, but these errors were encountered: