java icon indicating copy to clipboard operation
java copied to clipboard

Version 0.4.0 not loading models from S3

Open dennisTS opened this issue 3 years ago • 5 comments
trafficstars

Dear TF team,

we are experiencing a weird issue with the latest version of TensorFlow for Java - after upgrade it stopped loading models from S3.

Here's an example setup:

Java 8, a single dependency:

    <dependency>
      <groupId>org.tensorflow</groupId>
      <artifactId>tensorflow-core-platform</artifactId>
      <version>0.4.0</version>
    </dependency>

A single class:

import org.tensorflow.SavedModelBundle;

public class App {

  public static void main(String[] args) {
    SavedModelBundle.load("s3://some/location", "serve");
  }
}

Environment variable: AWS_REGION=eu-central-1

Outcome:

2022-03-09 20:53:24.893857: I external/org_tensorflow/tensorflow/cc/saved_model/reader.cc:43] Reading SavedModel from: s3://some/location
2022-03-09 20:53:24.893896: I external/org_tensorflow/tensorflow/cc/saved_model/loader.cc:283] SavedModel load for tags { serve }; Status: fail: NOT_FOUND: Could not find SavedModel .pb or .pbtxt at supplied export directory path: s3://some/location. Took 49 microseconds.
Exception in thread "main" org.tensorflow.exceptions.TensorFlowException: Could not find SavedModel .pb or .pbtxt at supplied export directory path: s3://some/location
	at org.tensorflow.internal.c_api.AbstractTF_Status.throwExceptionIfNotOK(AbstractTF_Status.java:101)
	at org.tensorflow.SavedModelBundle.load(SavedModelBundle.java:623)
	at org.tensorflow.SavedModelBundle.access$000(SavedModelBundle.java:67)
	at org.tensorflow.SavedModelBundle$Loader.load(SavedModelBundle.java:97)
	at org.tensorflow.SavedModelBundle.load(SavedModelBundle.java:357)
	at App.main(App.java:6)

Either of the changes below "fixes" the issue:

  • changing from S3 to local
  • changing from 0.4.0 to 0.3.3

Question: has anything changed since the previous version? Are we missing some important point that would make integration with S3 possible?

Thank you!

dennisTS avatar Mar 09 '22 20:03 dennisTS

s3 support was removed from TF 2.6 (https://github.com/tensorflow/tensorflow/issues/51583) and split out into a separate TF IO package (https://github.com/tensorflow/io). If you download the appropriate version of TF IO, extract the so/dylib files from it, you should be able to register the filesystem plugin with org.tensorflow.internal.c_api.global.tensorflow.TF_RegisterFilesystemPlugin(String plugin_filename, TF_Status status). We don't provide a wrapper around that method like we do for library loading, because we hadn't noticed that upstream TF had split out the filesystem support into a separate package. We'll put it on the todo list.

Craigacp avatar Mar 09 '22 21:03 Craigacp

Understood, thanks for the clarification, @Craigacp !

dennisTS avatar Mar 10 '22 11:03 dennisTS

Hi @Craigacp and @dennisTS, I have the same problem. Could you mind to share the solution? Since I have downloaded the newest version of TF IO and installed it correctly, but I still found that issue?

rhps avatar Mar 16 '22 08:03 rhps

You need to supply the path to libtensorflow_io_plugins.so which will have been installed into your python environment as an argument to the TF_RegisterFilesystemPlugin method that I mentioned above.

Craigacp avatar Mar 16 '22 13:03 Craigacp

In v0.4.2 we added a method which makes it easier to load the native filesystem libraries. You'll still need to download the python wheel and extract it, but at least it's easier to load on the Java side now.

Craigacp avatar Sep 23 '22 16:09 Craigacp