0
votes

First, when i tried LabelImage example with inception model ver 5, everything was good.

Then i tried with an older inception model ( ver3 ) and i saw that both model have different input and output.

In ver5, our input tensor name is : "Input" , with dtype = FLOAT.

In ver 3, our input tensor name is "DecodeJpeg/contents" , with dtype = STRING.

So i change LabelExample example with new name for both input and output : Tensor result = s.runner().feed("input", string_tensor_image).fetch("output") >> s.runner().feed("DecodeJpeg/contents", image).fetch("softmax") .

Also, i changed create new Image tensor for STRING type :

Tensor float_tensor = s.runner().fetch(output.op().name()).run().get(0);
byte[] bytes = new byte[float_tensor.numBytes()*64];
ByteBuffer buffer = ByteBuffer.wrap(bytes);
res.writeTo(buffer);
long[] shape = {};
Tensor string_tensor = Tensor.create(DataType.STRING, shape, buffer);
return string_tensor;

It looked good when i printed both tensor :

FLOAT tensor with shape [1, 224, 224, 3]
STRING tensor with shape []

But after feeding to the graph, i get this error : Exception in thread "main" java.lang.IllegalArgumentException: Invalid JPEG data, size 0 [[Node: DecodeJpeg = DecodeJpeg[acceptable_fraction=1, channels=3, dct_method="", fancy_upscaling=true, ratio=1, try_recover_truncated=false, _device="/job:localhost/replica:0/task:0/cpu:0"]

I have tried everything i can, but no results. How can i fix it ? This is both inception model ver3 and ver 5 :

ver5 : https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip

ver 3 : http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz

1
well, any one can help me ? - voxter
Please correct me if I've misunderstood your intention: you'd like to feed an image to v3, and it's doing some decoding as part of its input pipeline? In which case I would recommend feeding after the DecodeJpeg op, since it sounds like you have an image which is already decoded (you can feed a value for any operation, not just a placeholder, and dangling placeholders shouldn't matter as long as data is fed "upstream" of them). - Allen Lavoie

1 Answers

0
votes

The two models seem to be different and take different inputs. In particular, the DecodeJpeg op takes as input the raw contents of the JPEG image, which is why it is returning an error saying that it isn't being fed a JPEG-encoded image.

So you'd want to do something like:

byte[] input = Files.readAllBytes(Paths.get("/path/to/image.jpg"));
Tensor image = Tensor.create(input);