线程“main”中出现异常 java.lang.UnsatisfiedLinkError:无法找到适用于操作系统:linux,架构:x86_64 的 TensorFlow 本机库

Ste*_*eve 4 java tensorflow

我正在尝试在 Eclipse Oxygen(操作系统:Ubuntu Linux 16.x)中设置 TensorFlow Java 应用程序。我安装了 Tensorflow,并按照 Java(Maven 项目)安装官方文档中提到的过程进行操作。我下载了 libtensorflow-1.3.0.jar、jni 文件并包含在构建路径中。当我执行该程序时,出现以下错误

Exception in thread "main" java.lang.UnsatisfiedLinkError: Cannot find TensorFlow native library for OS: linux, architecture: x86_64. 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.TensorFlow.init(TensorFlow.java:36)
at org.tensorflow.TensorFlow.<clinit>(TensorFlow.java:40)
at com.tensorflow.malwaredetection.App.main(App.java:13)
Run Code Online (Sandbox Code Playgroud)

应用程序.java

package com.tensorflow.malwaredetection;

import org.tensorflow.TensorFlow;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World!"+ TensorFlow.version() );
    }
}
Run Code Online (Sandbox Code Playgroud)

POM.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>TensorFlow</groupId>
  <artifactId>MalwareDetection</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>MalwareDetection</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <exec.mainClass>App</exec.mainClass>
       <!-- The sample code requires at least JDK 1.7. -->
       <!-- The maven compiler plugin defaults to a lower version -->
       <maven.compiler.source>1.8</maven.compiler.source>
       <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.tensorflow</groupId>
      <artifactId>libtensorflow</artifactId>
      <version>1.3.0</version>
    </dependency>


  </dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)

我厌倦了这个错误,并尝试以老式的方式做到这一点。在单独的文件夹中创建 App.java 并在同一目录中包含 jar、jni 文件。当我从命令行执行此操作时,出现不同的错误

dev@ubuntu:~/Downloads$ javac -cp libtensorflow-1.3.0.jar Test1.java
dev@ubuntu:~/Downloads$ java -cp libtensorflow-1.3.0.jar:. -Djava.library.path=./jni Test1
Error: Could not find or load main class Test1
dev@ubuntu:~/Downloads$ 
Run Code Online (Sandbox Code Playgroud)

小智 7

我认为你需要在你的 pom.xml 中包含 jni 库依赖项。

<dependency>
    <groupId>org.tensorflow</groupId>
    <artifactId>libtensorflow_jni</artifactId>
    <version>1.1.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)