欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

yolo loss 将图像标注的真实事坐标转换到anchor坐标

发布时间:2025/4/5 编程问答 51 豆豆
生活随笔 收集整理的这篇文章主要介绍了 yolo loss 将图像标注的真实事坐标转换到anchor坐标 小编觉得挺不错的,现在分享给大家,帮大家做个参考.
最近在看yolov3 的源码,在看yolo_loss的时候遇到了一个卡点,就是将真是标注的box终点坐标转换
到anchor点的坐标
true_xy = true_xy * tf.cast(grid_size, tf.float32) - tf.cast(grid, tf.float32) raw_true_xy = y_true[l][..., :2] * grid_shapes[l][:] - grid import tensorflow as tfimport numpy as np#anchor box=13*13 grid_size=13 grid = tf.meshgrid(tf.range(grid_size), tf.range(grid_size)) grid = tf.expand_dims(tf.stack(grid, axis=-1), axis=2)#batch_size=8 box=13*13 ,每一种规格的anchor box 对应3个box ,中点坐标是2维 T_xy=np.zeros([8, 13, 13, 3, 2])*1.0T_xy[6,4,2]=[0.309,0.46212122]T_xy=tf.constant(T_xy,dtype=tf.float32)true_xy = T_xy * tf.cast(grid_size, tf.float32) - tf.cast(grid, tf.float32)print(true_xy) [[[[ 0. 0.][ 0. 0.][ 0. 0.]][[ -1. 0.][ -1. 0.][ -1. 0.]][[ -2. 0.][ -2. 0.][ -2. 0.]]......[[-10. -12.][-10. -12.][-10. -12.]][[-11. -12.][-11. -12.][-11. -12.]][[-12. -12.][-12. -12.][-12. -12.]]]]], shape=(8, 13, 13, 3, 2), dtype=float32) xy_loss = obj_mask * box_loss_scale * \tf.reduce_sum(tf.square(true_xy - pred_xy), axis=-1) obj_mask=np.zeros([8, 13, 13, 3])obj_mask[0,6,4,2]=1obj_mask=tf.constant(obj_mask,dtype=tf.float32)
发现这样处理后计算loss,有大量常量数值1,…11,12等,感觉会有问题因为用了tf.reduce_sum(tf.square(true_xy - pred_xy)
实际上没关系,因为在前面乘以了obj_mask ,对于yolo_loss中,中点坐标的loss ,只会计算有标记的对应anchor 的loss其余点loss会设置为0

总结

以上是生活随笔为你收集整理的yolo loss 将图像标注的真实事坐标转换到anchor坐标的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。