求助:关于tf.image.sample_distorted_bounding_box()遇到的问题

空气男孩 2019-09-29 04:26:03
tf.image.sample_distorted_bounding_box()函数输出的三个值:begin,size,bbox_for_draw。
其中bbox_for_draw是一个框用来可视化截取的部分的,通过tf.image.draw_bounding_boxes()函数实现。
而前面两个参数用于tf.slice()函数中来直接截取图像。
问题来了
为什么由bbox_for_draw得到的框中的区域,却不是tf.slice()裁剪后的区域的?

这是我的代码:
import tensorflow as tf
import matplotlib.pyplot as plt

image_raw_data=tf.gfile.FastGFile("/path/to/picture.jpg",'rb').read()

with tf.Session() as sess:
boxes = tf.constant([[[0.05,0.05,0.9,0.7],
[0.35,0.47,0.5,0.56]]])

begin, size, bbox_for_draw = tf.image.sample_distorted_bounding_box(
tf.shape(img_data), bounding_boxes=boxes, min_object_covered = 0.4)

batched = tf.expand_dims(tf.image.convert_image_dtype(img_data,tf.float32),0)

image_with_box = tf.image.draw_bounding_boxes(batched,bbox_for_draw)
plt.imshow(image_with_box[0].eval())
plt.show()

distorted_image = tf.slice(img_data,begin,size)
plt.imshow(distorted_image.eval())
plt.show()
...全文
101 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_52751924 2022-08-03
  • 打赏
  • 举报
回复

弄出来了,只需要将image_with_box[0]和distorted_image一起sess.run()即可

37,720

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧