2017-04-04 63 views
0

首先,當我嘗試LabelImage example與啓動模型版本5,一切都很好。java tensorflow api:無效的JPEG數據,大小0

然後我嘗試了一個較舊的初始模型(ver3),我看到兩個模型都有不同的輸入和輸出。

在版本5中,我們的輸入張量名稱是:「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和版本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

+0

好,任何一個能幫助我嗎? – voxter

+0

如果我誤解了你的意圖,請糾正我的錯誤:你想給v3提供一個圖像,並且它正在做一些解碼作爲其輸入流水線的一部分?在這種情況下,我建議在* DecodeJpeg操作之後提供*,因爲它聽起來像有一個已經解碼的圖像(您可以爲任何操作提供值,而不僅僅是佔位符,並且懸掛佔位符應該不會太長因爲數據是在它們的「上游」饋送的)。 –

回答

0

這兩個模型似乎是不同的,並採取不同的輸入。特別是,DecodeJpeg op takes as input the raw contents of the JPEG image,這就是爲什麼它返回一個錯誤,說它沒有被饋送JPEG編碼的圖像。

所以,你會想要做的事,如:

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

非常感謝 – voxter

相關問題