Open WittyLLL opened 3 years ago
What happens if you run the init_all_tables
target from Java after you've built the session?
What happens if you run the
init_all_tables
target from Java after you've built the session?
I am not sure how to run the init_all_tables
target from Java, could you provide me with a demo?It will be very helpful to me.
sess.runner().addTarget("init_all_tables").run()
sess.runner().addTarget("init_all_tables").run()
thank you for your patience,i try to add the init_all_tables
target in Java,But it seems does not work.
here is my code
package ctest;
import org.tensorflow.Graph;
import org.tensorflow.Session;
import org.tensorflow.Tensor;
import java.nio.file.Files;
import java.nio.file.Paths;
public class Ttest {
public static void main(String[] args) throws Exception {
predict();
}
public static void predict() throws Exception {
try (Graph graph = new Graph()) {
graph.importGraphDef(Files.readAllBytes(Paths.get(
"/opt/resources/hash_table.pb"
)));
try (Session sess = new Session(graph)) {
byte[][] matrix = new byte[1][];
matrix[0] = "a".getBytes("UTF-8");
Tensor< ? > out = sess.runner().addTarget("init_all_tables")
.feed("graph/data:0", Tensor.create(matrix)).fetch("graph/output:0").run().get(0);
float[][] output = new float[1][(int) out.shape()[1]];
out.copyTo(output);
for(float i:output[0])
System.out.println(i);
}
}
}
}
here is the error
2021-01-18 13:44:39.626529: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2021-01-18 13:44:39.670960: W tensorflow/core/framework/op_kernel.cc:1651] OP_REQUIRES failed at lookup_table_op.cc:809 : Failed precondition: Table not initialized.
Exception in thread "main" java.lang.IllegalStateException: Table not initialized.
[[{{node graph/hash_table_Lookup/LookupTableFindV2}}]]
at org.tensorflow.Session.run(Native Method)
at org.tensorflow.Session.access$100(Session.java:48)
at org.tensorflow.Session$Runner.runHelper(Session.java:326)
at org.tensorflow.Session$Runner.run(Session.java:276)
at ctest.Ttest.predict(Ttest.java:22)
at ctest.Ttest.main(Ttest.java:11)
Try running it separately before you try to access the table, but within the same session.
I am trying to use the tensorflow model in java,I convert a text classification model (with tf.lookup) to fomat .pb and want to load it in JAVA.But got "Table not initialized" error.
here is my code: In PYTHON
In JAVA
Any suggestions would be greatly appreciated.