![](/img/trans.png)
[英]java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0, TensorFlow on Android
[英]java tensorflow api : Invalid JPEG data, size 0
首先,当我尝试使用初始模型版本5的LabelImage 示例时,一切都很好。
然后,我尝试使用一个较旧的初始模型(ver3),我发现这两个模型具有不同的输入和输出。
在ver5中,我们的输入张量名称为:“ Input”,其dtype = FLOAT。
在版本3中,我们的输入张量名称为“ DecodeJpeg / contents”,其中dtype = STRING。
所以我用新名称为输入和输出更改LabelExample示例: Tensor result = s.runner().feed("input", string_tensor_image).fetch("output")
>> s.runner().feed("DecodeJpeg/contents", image).fetch("softmax")
。
另外,我更改了为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;
当我同时打印两个张量时看起来不错:
FLOAT tensor with shape [1, 224, 224, 3]
STRING tensor with shape []
但是在馈入图形之后,我得到了这个错误: 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"]
我已经尽力了,但没有结果。 我该如何解决? 这是初始模型ver3和ver 5:
ver5: https ://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip
版本3: http : //download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz
两种模型似乎有所不同,并且采用了不同的输入。 特别是, DecodeJpeg
op将JPEG图像的原始内容作为输入 ,这就是为什么它返回错误的原因,表明它没有被馈入JPEG编码图像。
因此,您想要执行以下操作:
byte[] input = Files.readAllBytes(Paths.get("/path/to/image.jpg"));
Tensor image = Tensor.create(input);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.