[英]Why does not the bounding box and clipped picture match using tf.image.sample_distorted_bounding_box?
我希望得到一個邊框 ,並根據邊框剪輯的圖片,所以我用tf.image.sample_distorted_bounding_box
。 但是我失敗了,我做錯了什么? 我的結果看起來像
邊框並根據邊界框不匹配所剪輯的圖片。
我的代碼:
with tf.Session() as sess:
boxes = tf.constant([[[0.05, 0.05, 0.9, 0.7], [0.35, 0.47, 0.5, 0.56]]])
image_float = tf.image.convert_image_dtype(img_data, tf.float32) # uint8 -> float
# resize image
image_small = tf.image.resize_images(image_float, [180, 267], method=0)
# Generate a single distorted bounding box.
begin, size, bbox_for_draw = tf.image.sample_distorted_bounding_box(
tf.shape(image_small),
bounding_boxes=boxes,
min_object_covered=0.1)
# Draw the bounding box in an image summary.
image_with_box = tf.image.draw_bounding_boxes(tf.expand_dims(image_small, 0),
bbox_for_draw)
tf.summary.image('images_with_box', image_with_box)
# Employ the bounding box to distort the image.
distorted_image = tf.slice(image_small, begin, size)
plt.figure(figsize = (30, 20))
plt.subplot(3, 1, 1)
plt.title("image with a random box")
plt.imshow(image_with_box[0].eval())
plt.subplot(3, 1, 2)
plt.title("destorted image")
plt.imshow(distorted_image.eval())
plt.show()
這是因為每次調用.eval()
觸發圖形的新運行,因此會產生一個新的隨機邊界框。
為了獲得一致的輸出,您需要同時運行運算符,例如
res = sess.run([image_with_box[0], distorted_image])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.