簡體   English   中英

java tensorflow api:無效的JPEG數據,大小為0

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM