-
Notifications
You must be signed in to change notification settings - Fork 214
The method create(float[][][][]) is undefined for the type Tensor (tensorflow-core-api version 0.3) #258
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
Comments
Thank you very much solved the problem! |
Sorry, clicked "enter" too fast. So that being said, there are more efficient ways to do this. For example, you could allocate your float tensors right away and copy the buffered image into it, without passing by a standard array, since you already know the shape of it:
There should be also a way to convert directly your |
No problem! BTW, 0.3.1 has been released, you should probably use this version now. |
Let's try to fix it quickly before reopening an issue. Please make sure to follow the instructions for adding TF to your dependencies. Especially make sure that you don't only depend on A good trick is to simply depend on a platform that will import everything for you, e.g.
|
Finally, I could manage the first step in loading the model and predicting the image in Java! Thank you very much! I reported the problem here (#259) as well, now I will close it. |
I had the problem that a network trained in TF 2.5.0 and exported as a protobuf .pb for using in TF1.5.0 in java would not allow dropout layers. But in the end it turned out only that the output of a layer would throw IllegalArgumentException when calling toString() on the layer output. The MLP still runs fine in java with the dropout layers. What follows is the method that loads the MLP following by logging output. Note the try/catch around the toString on layer output. I cannot tell if the network is actually utilizing the dropout or not, but the accuracy seems OK.
Logging output
|
I am trying to convert an image to Tensor. For that first I convert the buffered image to float[][][][] array as below.
File inputImage = new File(inputName); BufferedImage bufferedImage = ImageIO.read(inputImage); int imgHeight = bufferedImage.getHeight(); int imgWidth = bufferedImage.getWidth(); int numberOfChannels = bufferedImage.getTransparency(); float[][][][] floatImage = new float[1][imgHeight][imgWidth][numberOfChannels]; for(int i = 0; i < imgHeight; i++) { for(int j = 0; j < imgWidth; j++) { for(int k = 0; k < numberOfChannels; k++) { floatImage[0][i][j][k] = (float) (bufferedImage.getData().getSample(i, j, k)/255.0); } } }
Then, I try to convert the float array to Tensor using
Tensor inputTensor = Tensor.create(floatImage)
.Is there a way to convert an buffered image to Tensor? I am using ´tensorflow-core-api´ version ´0.3´.
Note: Converting the buffered as above takes longer, maybe there is a faster way to do it in Java.
The text was updated successfully, but these errors were encountered: