这个链接里面的是总结的比较好的中文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)