确保文件可用于JVM
问题描述:
我试图在Windows 10上使用此Article 安装TensorFlow for Java。我仔细地遵循了这些步骤,但windows命令不适用于我,所以我决定手动完成。确保文件可用于JVM
的第一个命令是使类路径的.jar一部分,我手工做的
但第二步是确保以下两个文件都可以在JVM:.jar文件和提取JNI库
,但我不知道该怎么做手工
代码:
package securityapplication;
import org.tensorflow.TensorFlow;
import org.tensorflow.Graph;
import org.tensorflow.Session;
import org.tensorflow.Tensor;
public class SecurityApplication {
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"));
}
}
}
}
会有人帮助吗?的Cuz使用TensorFlow我的程序仍然有以下错误
图像中的文字是:
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/tensorflow/java/README.md for possible solutions (such as building the library from source). Additional information on attempts to find the native library can be obtained by adding org.tensorflow.NativeLibrary.DEBUG=1 to the system properties of the JVM.
at org.tensorflow.NativeLibrary.load(NativeLibrary.java:66)
at org.tensorflow.NativeLibrary.load(NativeLibrary.java:66)
at org.tensorflow.TensorFlow.init(TensorFlow.java:36)
at org.tensorflow.TensorFlow.<clinit>(TensorFlow.java:40)
at org.tensorflow.Graph.<clinit>(Graph.java:194)
at securityapplication.SecurityApplication.main(SecurityApplication.java:15) Java Result: 1 BUILD SUCCESSFUL (total time: 4 seconds)
在cmd中运行第一个命令后的结果:
在Windows PowerShell中运行第二个命令后的结果:
有什么建议吗?
谢谢
答
的第一个命令失败(javac
)表明javac
命令是不是在你的PATH
环境变量。例如,请参阅this StackOverflow question
对于第二个命令失败,我相信-D
之后的空格是Holger建议的问题。
像Eclipse和其他IDE这样的IDE也提供了为JVM设置java.library.path
属性的方法(例如参见this StackOverflow answer)。背景:TensorFlow for Java由Java库(封装在.jar
文件中)和本地库(Windows上的.dll
,分布在.zip
文件中)组成。在执行程序时,需要确保.jar
文件在类路径中,并且包含.dll
的目录包含在JVM的java.library.path
中。
希望有所帮助。
构建输出非常小,几乎不可读。请将文本输出包含为文本(最好以缩进的预格式化块),而不是图像。 – VGR
是这样的结果:javac -cp libtensorflow-1.3.0.jar HelloTF.java? – Tom
@VGR我做到了。谢谢 –