java-从hdfs读取tensorflow模型(pb文件)

s4n0splo  于 2021-06-01  发布在  Hadoop
关注(0)|答案(0)|浏览(492)

我看到了 SavedModelBundle.load 不从hdfs读取。我正在做以下操作从hdfs读取文件 Byte array 并将其作为图形导入。

hdfs = FileSystem.get(new URI(configuration.get("fs.defaultFS")), configuration);
    if (hdfs.exists(location)) {
        FSDataInputStream hdfsInputStream = hdfs.open(location);
        int length = (int) hdfs.getFileStatus(location).getLen();
        byte[] model = new byte[hdfsInputStream.available()];
        hdfsInputStream.read(model);

        hdfsInputStream.close();
        final Graph g = new Graph();
        g.importGraphDef(model);
        Session session = new Session(g);
}

我也试过 hdfsInputStream.readfully(model) . 它给出了相同的以下错误:

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)

我的问题是:
有java等价物吗 SavedModelBundle.load 对于hdfs?
另一种选择是什么?我怎么读 .pb 文件为 byte array 并正确导入为tensorflow 图?
注意:如果我从本地文件系统中使用 SavedModelBundle.load(path) 功能。从本地,我无法正确读取字节数组并转换为图形。然而,阅读 bundle 工作正常,输出正确。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题