-
Notifications
You must be signed in to change notification settings - Fork 654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
java.nio.ReadOnlyBufferException when calling TensorFlow model. #570
Comments
Hi @macster110, I was not able to reproduce the If I directly run your code with the model provided I get 2 errors, I was able to fix them and run successfully. 1. Data type error
This is due to the model expect float32 data type as input, but you are passing double (created in preprocess in the translator). You can fix by generate specgramFlat as float[] or convert the NDArray to float32 type like this:
2. Shape Error
The model accepts any batch size as the required input shape is After fixing these 2 errors, I was able to run it.
|
Hi @roywei. thanks very much for taking the time to check this out. Unfortunately after fixing those errors I am still getting the same issue. I am using Mac OS but tried on Windows and got the same error (see full message below) I am using Maven to run the project - the project and POM file is here - but as far as I can tell I'm using the latest version of the djl tensorflow libraries. I'm totally stumped...any more ideas at what could be going on? Thanks again for the help. [PyTorch, TensorFlow] |
Hi @macster110 which Java version did you use? |
Good point. I am using 14.0.2 from AdoptOpenJDK. This could possibly a Java 11+ problem... |
Hi @lanking520 and @roywei. This is indeed a Java issue. Java 8 works and Java 14 and 15 do not. The project I'm working on really requires Java 11+ so would be great if there was a workaround somehow? Any ideas? |
Java 11 works. We haven't cover much tests on Java 14, will take a look today. |
Quick update, I tried Java 11 and it still has the same error on my machine? It was only Java 8 that worked for me...? |
Hi, following is my test results: Tried Java 8,11,12,15, 11 and 15 used Amazon Corretto version, but I think it should not matter. All version works. Could you try
SystemMacOS 10.15.7 Code:https://gist.github.com/roywei/69763254d5b73a524b1eec6cf28e7dc1 Java 8
Java 11
Java 12
Java 15
|
@macster110 Do you think it might be an OS issue? Which OS are you running with? |
Thanks @roywei and @lanking520 for bearing with on this issue. So the issue seems to be the Java version and in versions that do not work (8+) then the problem is that the engine remains Pytorch. That seems weird to me because the model loads just fine but I am using MacOS 11.1 (20C69), Java 14.0.2 from AdoptOpenJDK and running the code in Eclipse 2020-12 4.18.0. Updated code is here. I'm guessing that this will be solved if we figure out the engine remaining PyTorch but unsure why this might be? Thanks again for your help with this. It's much appreciated.
|
@macster110 If you have multiple engine in the classpath, the default engine is undefined, it's purely depends on the order or the class is get loaded. I just create a PR to address this issue, with latest code, the default engine will be deterministic. But this seems not related to the issue you are facing. It looks like the issue here is:
If we can reproduce this, then there is a bug somewhere when multiple engine are loaded. You can try "-Dai.djl.default_engine=TensorFlow" and see if your issue goes awasy. |
This is a really strange error. I was able to load PyTorch and TF engine together and run successfully with your latest code. Actually, all 3 engines loaded together also work. Since the NDArray creation is in Translators preprocessInput, it uses the context manager, which is specified to use TF engine during model loading. So we are NOT feeding any NDArray created by PyTorch to TFModel. Next step we will try upgrading MacOS to 11.1 and see if we can reproduce it. Are you using Mac with M1 chips?
|
Thanks @roywei. I am using an Intel Mac but I also tried this on Windows a little earlier (not with the latest code) and got the same error. Making me think that this could be something to do with the way Maven is setting up it's dependencies or something? I'll maybe try to run this in a new project with a minimal POM just to check. I also see in your output that PyTorch is getting printed out as the engine - so if the code works for you then this isn't necessarily an issue? |
That could also be the reason, I was using DJL's example folder to test your code, which use gradle Regarding the Engines, DJL is designed to allow multiple engines work together. If you have multiple engine as dependencies, there will be a default engine automatically chosen if you. In 0.9.0 it's not deterministic, in latest master code it's deterministic after #603. You can override auto engine selection to specific one by adding It will print |
Thanks @roywei . I just made a new project with exactly the same code and a minimal POM and it worked! So this means that there is a dependency in the larger project which is stopping stuff working. I'm going to do some trial and error work and figure out which one. Will post here once I figure out some more. |
Hi @roywei and all. I have found the issue - if you include a module-info file then this produces the ReadOnlyBuffer Exception . If not, then the error disappears. I have no idea why but as far as I can tell "api" is generated from the djl library and that is an seriously unstable name to use in a module-info file. Thanks for all your help - I would not have thought to try this without everyone's suggestions and tests.
|
I guess javacpp is using some reflection that is blocked by module. We can try to dig more. DJL currently compiled target to java 8, it's not be modularized for java 9. At runtime, it will be auto modularized by your JVM at runtime, and it's using the jar file's name as module name. That's why you see We have not yet decided to move to java9+ yet. If you want a stable module name for DJL, you need to rename the jar file to something like: |
@macster110 I created a PR to address module name issue, now each jar has a unique automatic module name: #627 |
Great, thanks again for all the help - I will now close the issue. |
Question
I am trying to call a Tensorflow model and keep getting a ReadOnlyBufferException. Originally this was an .hdf5 model which I converted to .pb file to use with djl as per instructions here.
The model input (in python) is a float64 numpy array of shape (N, 40,40,1). The model loads fine using djl and I've created a translator which inputs a double[][] array of the same shape but when calling
NDArray array = manager.create(specgramFlat, shape);
I get a ReadOnlyBufferException error.A minimal reproducible example is below and you can download the zipped model https://1drv.ms/u/s!AkNvdu-1_rHOgahqrZwrhu6V8v3TFA?e=0BR4a3.
Am I going about loading this model the right way? Any help on this would be much appreciated. Thanks!
The text was updated successfully, but these errors were encountered: