【发布时间】:2018-04-26 20:39:50
【问题描述】:
我使用人口普查数据并使用 tensorflow 中的估算器 api 创建了一个广泛而深入的模型。在 Java 中加载模型时,似乎出现了一个错误,导致模型无法加载。异常看起来像
Exception in thread "main" org.tensorflow.TensorFlowException: Op type not
registered 'SparseFeatureCross' in binary running on gmalhotra-mba-2.local.
Make sure the Op and Kernel are registered in the binary running in this
process.
at org.tensorflow.SavedModelBundle.load(Native Method)
at org.tensorflow.SavedModelBundle.load(SavedModelBundle.java:39)
at deeplearning.DeepLearningTest.main(DeepLearningTest.java:32)
请在下面找到用于保存模型的 python 代码: https://gist.github.com/gaganmalhotra/cd6a5898b9caf9005a05c8831a9b9153
使用的Java代码如下:
public static void main(String[] args) {
try (SavedModelBundle b = SavedModelBundle.load("/Users/gagandeep.malhotra/Documents/SampleTF_projects/temporaryModel/1510624417/", "serve")) {
Session sess = b.session();
//Create the input sensor
float[][] mat=new float[1][1];
mat[0]=new float[]{0.5f};
// create tensors specific to inputs ....
Tensor<?> x = (Tensor<?>) Tensor.create(mat);
//run the model
float[][] y = sess.runner()
.feed("input", x)
.fetch("output")
.run()
.get(0)
.copyTo(new float[1][1]);
//print the result
System.out.println(y[0][0]);
}
PS:使用的 Tensorflow 版本:1.3
【问题讨论】:
标签: java tensorflow tensorflow-serving