tf.image中的常用的几个函数

这个链接里面的是总结的比较好的中文api
http://www.tensorfly.cn/tfdoc/api_docs/python/image.html

1 tf.image.decode_jpeg(content, channels=3)

这里的content用tf.placeholder(tf.string,shape=[]),这里shape是不能带batch的,不然在decode函数里面就会报错。如果想批量操作,用tf.map_fn()

2 tf.image.pad_to_bounding_box
(image,
offset_height,
offset_width,
target_height,
target_width)
这个函数的作用是将突破通过pad全零行和列的方法,变大到你想要的尺寸
offset_height: Number of rows of zeros to add on top.
意思是你可以控制在上面加多少零行,相应的下面pad的零的行数目是target_height-offset_height-original_height
offset_width: Number of columns of zeros to add on the left.
理解方式同上。
如果你是将这批数据用来做目标检测的,那某些时候,尤其是测试阶段,为了简便起见,直接将offset_height, offset_width设置为0,那么这张pad之后预测出来的box坐标,和没有pad的原图的box坐标是一致的,不需要其他后处理。当然在训练阶段为了随机性可能这样并不太好。
相应的还有一个crop的函数
tf.image.crop_to_bounding_box
(image,
offset_height,
offset_width,
target_height,
target_width)
但是这个我没用过,所以懒得讲了,嘻嘻。

3 tf.image.non_max_suppression()
直接上代码了

keep = tf.image.non_max_suppression(
            boxes=before_nms_boxes,#[N,4] 矩阵 xmin ymin xmax ymax
            scores=scores,         #[N,]向量
            max_output_size=500,
            iou_threshold=0.6)

final_boxes = tf.gather(before_nms_boxes, keep)
final_probs = tf.gather(scores, keep)
final_probs = tf.reshape(final_probs, [-1, 1])
result = tf.concat((final_boxes, final_probs), axis=1)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值