yolo loss 将图像标注的真实事坐标转换到anchor坐标
生活随笔
收集整理的這篇文章主要介紹了
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坐标的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: yolo_model to output
- 下一篇: tf.where 用法