确保JVM可以使用文件

时间:2017-09-26 18:00:41

标签: java netbeans tensorflow jvm

我尝试使用此Article在Windows 10上安装TensorFlow for Java 。我小心地按照步骤操作,但是Windows命令并没有和我一起工作,所以我决定手动完成。

第一个命令是创建类路径的.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"));
      }
    }
  }

}
有人可以帮忙吗?因为我使用TensorFlow的程序仍然有以下错误 enter image description here

图片中的文字是:

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中运行第一个命令后的结果:

enter image description here

在Windows PowerShell中运行第二个命令后的结果:

enter image description here

有什么建议吗?!

谢谢

1 个答案:

答案 0 :(得分:0)

第一个命令失败(javac)表明javac命令不在您的PATH环境变量中。例如,请参阅this StackOverflow question

对于第二次命令失败,我认为-D之后的空格正是霍尔格所建议的那样。

Eclipse等IDE也提供了为JVM设置java.library.path属性的方法(例如,参见this StackOverflow answer)。

背景:TensorFlow for Java由一个Java库(打包在.jar文件中)和一个本机库(.dll在Windows上,分布在.zip文件中)组成。您需要确保.jar文件位于类路径中,并且在执行程序时,包含.dll的目录包含在JVM的java.library.path中。

希望有所帮助。