Skip to content

DataType 20 is not recognized in Java (version 1.15.0) #249

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

Closed
micosacak opened this issue Mar 21, 2021 · 5 comments
Closed

DataType 20 is not recognized in Java (version 1.15.0) #249

micosacak opened this issue Mar 21, 2021 · 5 comments

Comments

@micosacak
Copy link

micosacak commented Mar 21, 2021

I am trying to write a FiJi plugin in java. I have trained models in Python Tensorflow Version 2.2.0. However, when I try to perform prediction in Java I have the following problem:

`test_images\test_00001.png
28-28
1
4
inputTensor is: FLOAT tensor with shape [1, 28, 28, 1]
FLOAT

1.15.0
2021-03-21 18:12:47.782329: I tensorflow/cc/saved_model/reader.cc:31] Reading SavedModel from: CreateModelWithPythonTensorflow/model
2021-03-21 18:12:48.073847: I tensorflow/cc/saved_model/reader.cc:54] Reading meta graph with tags { serve }
2021-03-21 18:12:48.079446: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2021-03-21 18:12:48.110611: I tensorflow/cc/saved_model/loader.cc:202] Restoring SavedModel bundle.
2021-03-21 18:12:48.294807: I tensorflow/cc/saved_model/loader.cc:151] Running initialization op on SavedModel bundle at path: CreateModelWithPythonTensorflow/model
2021-03-21 18:12:48.316435: I tensorflow/cc/saved_model/loader.cc:311] SavedModel load for tags { serve }; Status: success. Took 534069 microseconds.
predicting...

Exception in thread "main" java.lang.IllegalArgumentException: DataType 20 is not recognized in Java (version 1.15.0)
at org.tensorflow.DataType.fromC(DataType.java:85)
at org.tensorflow.Tensor.fromHandle(Tensor.java:540)
at org.tensorflow.Session$Runner.runHelper(Session.java:343)
at org.tensorflow.Session$Runner.run(Session.java:276)
at TfDataTypeIssue.main(TfDataTypeIssue.java:43)`

The full code can be found on similar issues (#41212 (tensorflow/tensorflow#41212) or #1079 (xamarin/XamarinComponents#1079) or in this file ReportProblem.zip
. I used to get a trained model in Python in CreateModelWithPythonTensorflow and Java Maven Project when run gives the above error.

@rnett
Copy link
Contributor

rnett commented Mar 21, 2021

It looks like you're still using the TF1 Java bindings (1.15.0), which doesn't support resource variables (DataType 20), as they don't exist in TF1. You'll want to use one of the newer artifacts from this repo (see the README). We don't support resource variables yet on an API level, but the ops (i.e. readVariableOp are there. The DataType enum is here, FYI.

If you still have issues when using the artifacts from this repo, please update this issue, as this is definitely something we should support.

@micosacak
Copy link
Author

micosacak commented Mar 21, 2021

As seen in (tensorflow/tensorflow#41212) and (xamarin/XamarinComponents#1079), this is a common issue. Even when one uses tensorflow-lite.

I am using Tensorflow 2.2 in Python to create the model and saving it as model.save("model").

In Java the latest version is for org.tensorflow is 1.15.0. Am I wrong?

I have attached the full code I am using (Python and Java). It can be used to reproduce the issue and solve the problem. In case there is a solution, what should I change in the pom.xml file. Sorry, I am new in Java. A direct help in editing my code will be more helpful.

thanks.

@micosacak
Copy link
Author

if I use add the following to the pom.xml;
<repositories> <repository> <id>imagej.public</id> <url>http://maven.imagej.net/content/groups/public</url> </repository> <repository> <id>tensorflow-snapshots</id> <url>https://oss.sonatype.org/content/repositories/snapshots/</url> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <dependencies> <dependency> <!-- Example of dependency, see section above for more options --> <groupId>org.tensorflow</groupId> <artifactId>tensorflow-core-api</artifactId> <version>0.3.0</version> </dependency> <dependency> <groupId>net.imagej</groupId> <artifactId>ij</artifactId> <version>1.53h</version> </dependency> </dependencies>

then I have problem convertin float to tensor;
`Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method create(float[][][][], Class) is undefined for the type Tensor

at TfDataTypeIssue.getTensoredImage(TfDataTypeIssue.java:66)
at TfDataTypeIssue.main(TfDataTypeIssue.java:19)`

@Craigacp
Copy link
Collaborator

Craigacp commented Mar 21, 2021

The TF 1.15 bindings are old and no longer supported. This project is for the newer Java bindings which track the upstream TF Python releases. Our most recent release v0.3.0 uses TensorFlow 2.4.1. There have been many API changes between the old TF 1.15.0, and the new TF Java 0.3.0, so you'll need to update your code. The 0.3.0 release just came out, so we've not had chance to update the example models yet, but the tests in this repo are all up to date. The documentation for the Java API on tensorflow.org is in the process of being updated to the latest version.

@micosacak
Copy link
Author

micosacak commented Mar 30, 2021

Here is the solution; (#258)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants