简体   繁体   English

确保文件可用于JVM

[英]Ensuring files are available to the JVM

I'm trying to install TensorFlow for Java on Windows 10 using this Article . 我想对Java在Windows 10使用该安装TensorFlow 文章 I followed the steps carefully but the windows commands didn't work with me so I decided to do it manually. 我仔细地遵循了这些步骤,但是Windows命令对我不起作用,因此我决定手动进行操作。

The first command is to make the .jar part of the classpath and I did it manually 第一个命令是使.jar成为类路径的一部分,我是手动完成的

but the second step was to ensure that the following two files are available to the JVM: the .jar file and the extracted JNI library 但是第二步是确保以下两个文件可用于JVM:.jar文件和提取的JNI库

but I don't know how to do that manually 但我不知道该如何手动

The code: 编码:

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"));
      }
    }
  }

}

could someone help? 有人可以帮忙吗? cuz my program that uses TensorFlow still have the following error 因为我使用TensorFlow的程序仍然存在以下错误 在此处输入图片说明

The text in the image is : 图片中的文字为:

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)

The result after running the first command in cmd: 在cmd中运行第一个命令后的结果:

在此处输入图片说明

The result after running the second command in Windows PowerShell: 在Windows PowerShell中运行第二个命令后的结果:

在此处输入图片说明

Any suggestions?! 有什么建议么?!

Thank you 谢谢

The first command failure ( javac ) suggests that the javac command is not in your PATH environment variables. 第一个命令失败( javac )表明javac命令不在您的PATH环境变量中。 See for example, this StackOverflow question 例如,参见此StackOverflow问题

For the second command failure, I believe the space after -D is what is causing you trouble as Holger suggested. 对于第二个命令失败,我相信-D后面的空格会像Holger所建议的那样引起您的麻烦。

IDEs like Eclipse and others also provide a means to set the java.library.path property for the JVM (see this StackOverflow answer for example). 诸如Eclipse之类的IDE和其他IDE也提供了一种设置JVM的java.library.path属性的方法(例如,请参见此StackOverflow答案 )。

Background: TensorFlow for Java consists of a Java library (packaged in a .jar file) and a native library ( .dll on Windows, distributed in a .zip file). 背景:TensorFlow for Java由Java库(打包成.jar文件)和本机库(Windows上的.dll ,分布于.zip文件)组成。 You need to ensure that the .jar file is in the classpath and the directory containing the .dll is in included in the java.library.path of the JVM when executing a program. 执行程序时,您需要确保.jar文件位于类路径中,并且包含.dll的目录位于JVM的java.library.path中。

Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM