【发布时间】:2017-04-30 20:34:56
【问题描述】:
我正在尝试根据此链接上的建议安装 Tensorflow for java...
https://www.tensorflow.org/install/install_java#install_on_windows
说明说明下载 .jar 文件和 .dll 的单独文件。我已将 jar 文件包含到 netbeans 项目中,并设置了上述网页上列出的代码。
package tensorflowtest;
import org.tensorflow.Graph;
import org.tensorflow.Session;
import org.tensorflow.Tensor;
import org.tensorflow.TensorFlow;
public class TensorFlowTest {
public static void main(String[] args) throws Exception {
try (Graph g = new Graph()) {
final String value = "Hello from " + TensorFlow.version();
// Construct the computation graph with a single operation, a constant
// named "MyConst" with a value "value".
try (Tensor t = Tensor.create(value.getBytes("UTF-8"))) {
// The Java API doesn't yet include convenience functions for adding operations.
g.opBuilder("Const", "MyConst").setAttr("dtype", t.dataType()).setAttr("value", t).build();
}
// Execute the "MyConst" operation in a Session.
try (Session s = new Session(g);
Tensor output = s.runner().fetch("MyConst").run().get(0)) {
System.out.println(new String(output.bytesValue(), "UTF-8"));
}
}
}
}
运行时出现错误
Exception in thread "main" java.lang.UnsatisfiedLinkError: Cannot find TensorFlow native library for OS: windows, architecture: x86. See https://github.com/tensorflow/tensorflow/tree/master/java/README.md for possible solutions (such as building the library from source).
at org.tensorflow.NativeLibrary.load(NativeLibrary.java:66)
at org.tensorflow.TensorFlow.init(TensorFlow.java:27)
at org.tensorflow.TensorFlow.<clinit>(TensorFlow.java:31)
at org.tensorflow.Graph.<clinit>(Graph.java:194)
at tensorflowtest.TensorFlowTest.main(TensorFlowTest.java:11)
我知道这是因为找不到 .dll 文件,但我尝试将 .dll 放在所有根文件中,我尝试将 dll 添加到我的源和/或库中,并且我尝试添加命令 -Djava.library.path=。到我在 Netbeans 中的 VM 选项并尝试添加 System.setProperty("java.library.path", ".");到我的主要功能开始,一切都没有成功。我还尝试以“C:\Path\To\File”的形式给出 dll 的直接路径
任何有关如何解决此问题的建议将不胜感激。
【问题讨论】:
标签: java netbeans dll tensorflow