![](/img/trans.png)
[英]How to create tensor with shape(?,) and dtype=string from image with tensorflow in python
[英]How to set image shape in Python for Tensorflow prediction?
我正在處理以下錯誤:
ValueError: Cannot feed value of shape (32, 32, 3) for Tensor 'Placeholder:0', which has shape '(?, 32, 32, 3)'
占位符設置為: x = tf.placeholder(tf.float32, (None, 32, 32, 3))
並且圖像(運行print(img1.shape)
)的輸出為: (32, 32, 3)
print(img1.shape)
(32, 32, 3)
運行時如何更新圖像以使其對齊: print(sess.run(correct_prediction, feed_dict={x: img1}))
程序中的占位符x
代表一批 32x32(大概是)RGB圖像,將在單個步驟中計算出預測。 如果要對單個圖像(即形狀(32, 32, 3)
32、32、3 (32, 32, 3)
的陣列)計算預測,則必須對其進行重塑以具有額外的引導尺寸。 有很多方法可以做到這一點,但是np.newaxis
是一種很好的方法:
img1 = ... # Array of shape (32, 32, 3)
img1_as_batch = img1[np.newaxis, ...] # Array of shape (1, 32, 32, 3)
print(sess.run(correct_prediction, feed_dict={x: img1_as_batch}))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.