2017-02-28 116 views
0

我使用concat來獲取張量作爲CNN的輸入。但得到的錯誤:張量清單時,單張量預計單張量預期的張量列表

image_raw = img.tobytes() 
image = tf.decode_raw(image_raw, tf.uint8) 
image = tf.reshape(image, [1, image_height, image_width, 3]) 

image_val = image 
for i in range(batch_size-1): 
    image_val = tf.concat(0,[image_val,image]) 
return image_val 

...我已經尋找這些問題的答案,加上 image_val = tf.stack([image_val],0)返回之前,但仍得到了同樣的錯誤,爲什麼呢?

**build environment:** 
TensorFlow version 0.12 
python 3.5 
+0

image_height或/和image_width是張量嗎? – lerner

回答

0

錯誤List of Tensors when single Tensor expected來自於你寫tf.concat(0,[image_val,image]),而不是tf.concat([image_val,image],0)的事實。

+0

這是tensorflow 0.1和0.12的不同API,不是這個問題的答案。而且,我改變了方法,但仍然有相同的錯誤。 – judyzha

+0

@judyzha請指定您在問題中使用的TensorFlow版本。 –

0

也許再次檢查image_height, image_width的類型,因爲有時需要將它們轉換爲整數dtype,例如, tf.cast(image_height, tf.int32)