[英]java tensorflow api : Invalid JPEG data, size 0
First, when i tried LabelImage example with inception model ver 5, everything was good. 首先,当我尝试使用初始模型版本5的LabelImage 示例时,一切都很好。
Then i tried with an older inception model ( ver3 ) and i saw that both model have different input and output. 然后,我尝试使用一个较旧的初始模型(ver3),我发现这两个模型具有不同的输入和输出。
In ver5, our input tensor name is : "Input" , with dtype = FLOAT. 在ver5中,我们的输入张量名称为:“ Input”,其dtype = FLOAT。
In ver 3, our input tensor name is "DecodeJpeg/contents" , with dtype = STRING. 在版本3中,我们的输入张量名称为“ DecodeJpeg / contents”,其中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")
. 所以我用新名称为输入和输出更改LabelExample示例:
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 : 另外,我更改了为STRING类型创建新的图像张量:
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"]
但是在馈入图形之后,我得到了这个错误:
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 :
这是初始模型ver3和ver 5:
ver5 : https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip 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 版本3: http : //download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz
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. 特别是,
DecodeJpeg
op将JPEG图像的原始内容作为输入 ,这就是为什么它返回错误的原因,表明它没有被馈入JPEG编码图像。
So you'd want to do something like: 因此,您想要执行以下操作:
byte[] input = Files.readAllBytes(Paths.get("/path/to/image.jpg"));
Tensor image = Tensor.create(input);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.