2016-03-08 80 views
0

我的目標是爲數據增強目的引入隨機縮放和轉換。爲什麼`tf.image.resize_images`設置圖像形狀?

distorted_image = tf.image.resize_images(distorted_image, random_scale, random_scale) 
distorted_image = tf.image.crop_to_bounding_box(distorted_image, random_y, random_x, 299, 299) 

這種失敗'image' must be fully defined.交換行工作,但並沒有做什麼,我真正需要的。

distorted_image = tf.image.crop_to_bounding_box(distorted_image, random_y, random_x, 299, 299) 
distorted_image = tf.image.resize_images(distorted_image, random_scale, random_scale) 

所以好像resize_images失去了像張量的形狀,然後crop_to_bouding_box失敗。這是故意的,我錯過了什麼?調整大小後random_crop如何工作,但crop_to_bounding_box不是?

回答

2

tf.image.resize_images() op 確實設置圖像形狀,在this line的實現。 (這在TensorFlow 0.7添加。)

然而,如果任一new_heightnew_width參數是動態值,然後TensorFlow不能推斷該維度單個形狀,因此使用None該維度。我注意到在你的代碼中,新的高度和寬度值被稱爲random_scale:如果在每個步驟上繪製一個新的隨機值,那麼該形狀對於高度和寬度尺寸將具有None

注意,在這種情況下,運算tf.image.crop_to_bounding_box()不會因爲工作—作爲錯誤消息指示—當前的實現要求輸入的形狀來完全定義。正如我在a recent answer中指出的那樣,最好的解決方法可能是使用實施tf.image.crop_to_bounding_box()的低層操作(特別是帶有計算指數的tf.slice())。

+0

我結束了內聯'random_crop'並做了小的修改,並且像魅力一樣工作。謝謝! – Clash