Cannot invoke "java.io.File.getCanonicalPath()" because "path[i]" is null When initialize org.bytedeco.tensorflow-platform
mihneaburlacu opened this issue · 9 comments
I want to load a python model in my Java Class.
This are my dependencies:
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>cpython-platform</artifactId>
<version>3.12.1-1.5.10</version>
</dependency>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>tensorflow-platform</artifactId>
<version>1.15.5-1.5.8</version>
</dependency>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>numpy-platform</artifactId>
<version>1.26.3-1.5.10</version>
</dependency>
This is my error:
Warning: Versions of org.bytedeco:javacpp:1.5.10 and org.bytedeco:tensorflow:1.15.5-1.5.8 do not match.
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.io.File.getCanonicalPath()" because "path[i]" is null
at org.bytedeco.cpython.helper.python.Py_Initialize(python.java:112)
at entities.Model.useModel(Model.java:78)
at MainClass.main(MainClass.java:17)
This is the line where I am getting the error:
Py_Initialize(org.bytedeco.tensorflow.global.tensorflow.cachePackages());
Warning: Versions of org.bytedeco:javacpp:1.5.10 and org.bytedeco:tensorflow:1.15.5-1.5.8 do not match.
Yeah, don't mix with 1.5.10, that probably won't work.
and what version should I use?
1.5.8 is fine for that
@saudet I resolve the warning with the version and I still have the error at: Py_Initialize(org.bytedeco.tensorflow.global.tensorflow.cachePackages());
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.io.File.getCanonicalPath()" because "path[i]" is null
at org.bytedeco.cpython.helper.python.Py_Initialize(python.java:112)
at entities.KerasMNIST.main(KerasMNIST.java:18)
If you're trying to use the Python build, the last one published was 1.5.4:
https://central.sonatype.com/search?q=tensorflow-platform-python
The problem is at the path: .javacpp\cache\tensorflow-1.15.5-1.5.8-windows-x86_64.jarr\org\bytedeco\tensorflow\windows-x86_64 I have only the file jnitensorflow.dll, not a folder named python as it requires here in the class tensorflow.class: public static synchronized File cachePackage() throws IOException {
if (packageFile != null) {
return packageFile;
} else {
Loader.load(python.class);
String path = Loader.load(tensorflow.class);
if (path != null) {
path = path.replace(File.separatorChar, '/');
int i = path.indexOf("/org/bytedeco/tensorflow/" + Loader.getPlatform());
int j = path.lastIndexOf("/");
packageFile = Loader.cacheResource(path.substring(i, j) + "/python/");
}
return packageFile;
}
}
Like I said, please try 1.5.4
I tried but I have another problem with 1.5.4: Exception in thread "main" java.lang.UnsatisfiedLinkError: no jnitensorflow in java.library.path: C:\Program Files\Java\jdk-17\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\Git\cmd;C:\Program Files\MATLAB\R2021b\bin;C:\Program Files\dotnet;C:\Program Files\nodejs;C:\Program Files\ghc-9.2.5-x86_64-unknown-mingw32\bin;C:\Program Files\Docker\Docker\resources\bin;C:\Program Files\MySQL\MySQL Shell 8.0\bin;C:\Users\LeGion\AppData\Local\Microsoft\WindowsApps;C:\Users\LeGion\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\LeGion\AppData\Roaming\npm;C:\Program Files\apache-maven-3.9.5\bin;;.
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2429)
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:818)
at java.base/java.lang.System.loadLibrary(System.java:1989)
at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1825)
at org.bytedeco.javacpp.Loader.load(Loader.java:1416)
at org.bytedeco.javacpp.Loader.load(Loader.java:1227)
at org.bytedeco.javacpp.Loader.load(Loader.java:1203)
at org.bytedeco.tensorflow.global.tensorflow.(tensorflow.java:15)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:467)
at org.bytedeco.javacpp.Loader.load(Loader.java:1282)
at org.bytedeco.javacpp.Loader.load(Loader.java:1227)
at org.bytedeco.javacpp.Loader.load(Loader.java:1219)
at entities.Model.useModel(Model.java:109)
at MainClass.main(MainClass.java:17)
Caused by: java.lang.UnsatisfiedLinkError: C:\Users\LeGion.javacpp\cache\tensorflow-1.15.3-1.5.4-windows-x86_64-python.jar\org\bytedeco\tensorflow\windows-x86_64-python\jnitensorflow.dll: Can't find dependent libraries
at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:384)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:228)
at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:170)
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2389)
at java.base/java.lang.Runtime.load0(Runtime.java:755)
at java.base/java.lang.System.load(System.java:1953)
at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1772)
... 11 more
Please follow the instructions at https://github.com/bytedeco/javacpp-presets/wiki/Debugging-UnsatisfiedLinkError-on-Windows