Using ops from Tensorflow.contrb on Windows via Java API - java

I would like to load an op from tf.contrib, specifically "_beam_search_ops". I use Tensorflow 1.6 from Maven.
Following the answer at Issue while loading/serving tensorflow model in java using estimators , I'm able to do so on Ubuntu 17.10.
The code looks like so:
TensorFlow.loadLibrary("_beam_search_ops.so");
Then I try to do the same in Windows 10 with code
TensorFlow.loadLibrary("_beam_search_ops.dll");
And it fails with
java.lang.UnsatisfiedLinkError: D:\Users\ALEXAN~1\AppData\Local\Temp\deep_api_plugin\_beam_search_ops.dll not found
at org.tensorflow.TensorFlow.loadLibrary(TensorFlow.java:47)
So what is the reason for this?

While I was writing and researching the question, I've stumbled on the solution.
In order to resolve the problem, a _pywrap_tensorflow_internal.pyd file should be copied to the folder where _beam_search_ops.dll resides. I understand that this is also some kind of dll, but do not understand why it is necessary for Windows and not for Ubuntu. If anyone happens to know, please enlighten me.
Also I understand that this sort of additional information should be provided in a comment to the original answer, but unfortunately I do not have enough reputation to comment and thought this answer could help someone.
Edit: I was too quick to celebrate. With this answer a library is loaded without exception, but the model cannot seem to use it, failing with
Exception in thread "main" org.tensorflow.TensorFlowException: Op type not registered 'GatherTree' in binary running on DESKTOP-EB6GIDR. Make sure the Op and Kernel are registered in the binary running in this process.
at org.tensorflow.SavedModelBundle.load(Native Method)
at org.tensorflow.SavedModelBundle.load(SavedModelBundle.java:39)
Search for answer should continue.

Related

How do I track what java is actually looking for as it traverses CLASSPATH?

How is the java utility that begins the process of launching a class told to "spill its guts" on what it's doing as it tries to load classes?
In particular, what file paths is it TRYING to access, only to perhaps discover whatever it's looking for is not there, at least as it interprets the specification given? There was a way to get that information, but I can't find it now.
Note that this is Java version "1.8.0_333" on Windows 10.
I've tried every flag known to me, via the -h and -X flags, and I strongly suspect what I'm looking for is (was) an X flag that's been removed, just as the -X help output warns. And so, there must be an OS way to figure this out, I sure hope!
You might ask why? Whatever for? What are you trying to do? Well, that's the bulk of this question's text. To wit:
As one of the very early users of Java (I started with 1.1) way back in the '90s, I had an issue moving an application suite I'd written for my company on Linux to MS Windows and I got it working by using Cygwin. Along the way, this same sort of issue came up and I quite vividly recall having found a mechanism for getting the Java launcher to articulate just what file specifications - paths - it was actually using in searching for the appropriate class. And through using this, I found that the CLASSPATH was being specified incorrectly, and with some experimentation, I got it working reliably. Now I need to do that again!
This flag I'd used was immensely helpful in figuring out just what the file specification format CLASSPATH needed to be (we're not talking semicolons here) this combination of OS, Java, and Cygwin. After some hours of what I hope was reasonable hunting, I'm wondering if this capability has been removed at some point? Either that or "I'm looking for the wrong thing." Heck, since the source is available (I think!), maybe some brave soul has hacked the java utility to do such a thing?
It may help to understand that for this application I wrote for my company, it was a major goal to have the source work pretty much the same on all Windows and Linux / Unix systems (and at the time, macOS), and just use a configuration file to tell the code what's different. And that wasn't easy to figure out, but with this flag, it wasn't that hard, either.
But, unfortunately, I haven't needed this knowledge since I figured it all out all those years ago, and apparently, this little kernel of knowledge is very hard to find today. Or, it's no longer pertinent to the modern version(s).
I don't think this has anything much to do with the actual problem, but it may help in people's thinking if they understood the scenario: The current situation is that I have a fully functional installation of this software on Windows 7 to use as a comparison for how to configure things on Windows 10 (and hopefully younger). The Windows 7 is running a pretty modern Cygwin installation and very nearly the most modern Java - just a sub-version away from the new installation from last week on a Windows 10 box. (Everything's bright and shiny new on the new box.)
The required format for CLASSPATH on the nearly identical but fully functional Windows 7 system is:
CLASSPATH="C:/opt/OurInstallationDir/lib"
And that's it.
This value is picked up in several places as the code later needs to launch Java itself to do some unusual things. However, the java command that gets it all going is launched from a C program - not that that matters for this problem - but the C program (compiled under Cygwin, but perfectly runnable from any Windows environment) helps ensure that the Java environment is secured (policy file contents and so forth) before getting into Java, else it refuses. And this program on Windows 11 launches Java just fine, it's just giving it a CLASSPATH that isn't useful, apparently, even though the files are there where they should be, etc.
Configuring things as before just doesn't work, even from the command line. No version of specifying CLASSPATH seems to work if it's more than a dot; the only thing that works, is being in the /lib directory when starting and using "-cp ." ... But that's just not going to fly for so many reasons! To be a little more clear, I've tried reversing the slashes, using /cygdrive/c/, and whatever else I could think of. But, at least we know that if you're in the directory and use -cp, it will find and launch the program. So, there's nothing wrong with the Java, just pointing the java utility at it.
Again: How is the java utility that begins the process of launching a class told to "spill its guts" on what it's doing as it's trying to load classes?
You use this construct on the JVM:
java -XX:+TraceClassPaths -cp "C:\opt\SomeDirectory\lib" myClass
I was able to get confirmation of what Java was using, not only for my CLASSPATH, but "internally" by using the above.
The fact that it echoed back both what I was doing and what it was doing somehow gave me the insight to check everything about it. Java itself doesn't work (at all) if it's installed in a location that it thinks has a link in it, and it's own fetches go right back to the system disk specification.
From that I found that Java on Windows won't take a CLASSPATH that has a link in it!
Simply ensuring that the whole tree was specified "from the top" of the drive it's on works. If it's not, it won't.
It's now working happily using the syntax noted above.
This is quite different from every other application I've seen on Windows. But, well, it's Java!
This really came from a pointer from Mark Rotteveel who commented above about this article: How to track when class is loaded and destroyed in jvm? And therein I learned how to get the list of all the options the presently in-use JVM supports. All Java developers should be aware of this in my opinion, so thanks to Mark for that.

issue when run deeplearning4J example

I am learning deep learning, and use deeplearning4J tuts.
But when i run example code, some issue there :
Caused by: java.lang.UnsatisfiedLinkError: no jnind4j in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:727)
at org.bytedeco.javacpp.Loader.load(Loader.java:502)
at org.nd4j.nativeblas.NativeOps.<clinit>(NativeOps.java:37)
... 18 more
i have tried some solutions on web but it doesnot work.
So, if you know how to fix it, help me.
You need to unzip cuda-9.1-7.1-1.4.1-windows-x86_64.jar and nd4j-cuda-9.1-1.0.0-beta-windows-x86_64.jar somewhere, and add the paths to the native dlls to the java.library.path property when launching your app.
For example:
-Djava.library.path=C:\<path where you unzipped>\cuda-9.1-7.1-1.4.1-windows-x86_64\org\bytedeco\javacpp\windows-x86_64;C:\<path where you unzipped>\nd4j-cuda-9.1-1.0.0-beta-windows-x86_64\org\nd4j\nativeblas\windows-x86_64
I had the same problem. But the issue was I was using the wrong import , nd4j-native. Instead of that I used nd4j-native-platform import and it fixed the problem.
Hope it helps.
I will try to answer this here, but usually this is where the chat comes in handy (a lot of asking about your environment and back and forth here..)
I'd try to answer this here, but the native code (especially with the examples) should run fine.
You could also try filing an issue: https://github.com/deeplearning4j/dl4j-examples/issues
In the mean time, read up on what an nd4j backend is:
http://nd4j.org/backend.html
This SHOULD be the only dependency you need to run:
http://search.maven.org/#artifactdetails%7Corg.nd4j%7Cnd4j-native-platform%7C0.6.0%7Cjar
The examples run out of the box for everyone we've talked to.
You don't seem to be doing anything out of the ordinary.
An alternative might just be using the nd4j-native artifact id with the appropriate classifier.
This is where you modify the nd4j backend:
https://github.com/deeplearning4j/dl4j-examples/blob/master/dl4j-examples/pom.xml#L64
You can try just getting rid of this and replacing it with 1 of the artifact ids I told you about. If that doesn't fix it, I would recommend coming in to gitter.
Please come in to gitter: https://gitter.im/deeplearning4j/deeplearning4j
for real time help.

Running android java's native libraries under linux

I have well-working simple android app(graphically does nothing, but calculates some data), that uses native libraries, those libraries is for x86, so I am hoping to make that code work under x86 ubuntu as a simple compiled java binary.
So after finding all library dependencies compiler tells me:
Exception in thread "main" java.lang.UnsatisfiedLinkError:
lib/libgnustl_shared.so: lib/libgnustl_shared.so: undefined symbol: __sF
After a bit googling I found that __sF is some kind of android specified parameters array, that accesible in the android env(or elsewhere, I actually don't know).
libgnustl_shared.so depends from libm.so and libdl.so, that comes with ubuntu.
Should I try to find android x86 libm.so and libdl.so? Or try to implement some how __sF in java code?
(main point is to solve issue with libgnustl_shared.so, other libraries is written manually by my co-worker so I dont expect any harm from them)
I hope someone has the sacred knowledge to help me make it work. Appreciate any help.

How do I check a clients Java Version?

I want to create an Executable Jar file that when run, checks the currently installed version of Java on that computer and displays it for the user. I have searched online but in vain, I cannot find any code that allows a Jar file to check. I know that the Java website has it ( http://www.java.com/en/download/installed.jsp) I can't find a way to replicate it in Java Code. Any help would be very much appreciated.
Note: Sorry if this question is really stupid and has a really simple answer... I just spent half an hour trying to find a solution and I couldn't so I need your help! Thanks
Edit: I don't need the code for displaying it, just to get the version is enough for me thanks!
System.getProperty("java.version");
Calling System.getProperty("java.version"); will give you version of the installed JRE which is what you want. Also take a look at other System properties, you may find some of them also useful.

Run Java ScreenGrabber example

I'm trying to test the Screen Grabber sample from JMF. Could anyone tell me how to write the main method to run this example?.
I have reviewed a lot in Google and have not found a way to make it work. because I do not know which of the two classes (LiveStream or DataSource) I must to use in the main method.
otherwise, I tried running the command:
java JMStudio screen://0,0,160,120/10
But it shows me the following exception:
UNABLE_CREATE_PLAYER*javax.media.NoPlayerException: Cannot find a Player for :screen://0,0,160,120/10
Thanks for the help.
Greetings!
Don't.
JMF never really worked out and has been abandon. (Google: "JMF is dead".) Find another mechanism for screen grabbing.
it's a late answer, but with the same hopes as Lobo, i'd like to add some constructive info :
1) JMF is old but also an old gun. it's working
2) it's pure Java, and if you are a Java guy, it will be helpful, this way or that way
3) use the methods you mentioned, if you can. follow the tutorial. otherwise, there is a free package that can be downloaded from http://www.kemottron.com, MODERATOR-CONFERENCE, you can try. pure Java, and it captures your desktop and broadcast to the Internet.
regards,

Categories