gpt4 book ai didi

java - 线程 "main"java.lang.UnsatisfiedLinkError : Cannot find TensorFlow native library for OS: linux, 架构中的异常:x86_64

转载 作者:行者123 更新时间:2023-11-30 07:52:03 24 4
gpt4 key购买 nike

我正在尝试在 Eclipse Oxygen(操作系统:Ubuntu Linux 16.x)中设置 TensorFlow Java 应用程序。我安装了 Tensorflow 并遵循了过程 mentioned in official documentation用于 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)

应用程序.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() );
}
}

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>

我厌倦了这个错误,并尝试以一种老式的方式来做这件事。在单独的文件夹中创建 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$

最佳答案

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

<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>libtensorflow_jni</artifactId>
<version>1.1.0</version>
</dependency>

关于java - 线程 "main"java.lang.UnsatisfiedLinkError : Cannot find TensorFlow native library for OS: linux, 架构中的异常:x86_64,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46303270/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com