我使用java重新加载tensorflow pb模型。我把模型放在资源包中(intellij IDEA)。当我在我的电脑上运行它时它工作正常。但是当我将它编译为.jar并在另一台计算机上运行时。它出错了如下:
Exception in thread "main" java.lang.IllegalArgumentException: Invalid GraphDef
at org.tensorflow.Graph.importGraphDef(Native Method)
at org.tensorflow.Graph.importGraphDef(Graph.java:130)
at org.tensorflow.Graph.importGraphDef(Graph.java:114)
at com.xunlei.algo.analysis.LstmSeqModel.<init>(LstmSeqModel.java:66)
at com.xunlei.algo.analysis.LstmSeqModel.main(LstmSeqModel.java:90)
我的代码如下所示:
InputStream is = LstmSeqModel.class.getResourceAsStream("/lstmSeq.pb");
int count = is.available();
System.out.println(count);
graphDef = new byte[count];
is.read(graphDef);
g.importGraphDef(graphDef);
sess = new Session(g);