YOLOv5_OBB_KLD
YOLOv5_OBB_KLD copied to clipboard
Angular definition problem
My derivation of your repo is here: https://github.com/Suppersine/YOLOv7_obb_KFIOU
According to MMRotate, the CSL loss function abides by the "Long edge" angular definition, ranging from [-pi/, & pi/2, while the KLD & KFIOU loss functions abide by the "Old OpenCV (OOCV)" definition, ranging from [-pi/2, 0). To convert between these. I have written the function inside the rboxs_utils.py file below:
def regular_theta(theta, mode='180', start=-pi/2):
"""
limit theta ∈ [-pi/2, pi/2)
"""
assert mode in ['360', '180']
cycle = 2 * pi if mode == '360' else pi
theta = theta - start
theta = theta % cycle
return theta + start
def lebox2ocbox(x, y, w, h, theta):
x, y, = x, y #ocbox[:2] = lebox[:2]
#ocbox[-2:] = lebox[-2:]
if theta < 0:
return x, y, w, h, theta
else:
w, h = h, w
theta -= pi/2
return x, y, w, h, theta
def ocbox2lebox(x, y, w, h, theta):
x, y, = x, y #lebox[:2] = ocbox[:2]
#lebox[-2:] = ocbox[-2:]
if w == max(w, h):
return x, y, w, h, theta
else:
w, h = h, w
theta += pi/2
return x, y, w, h, theta
and changed the "poly2rbox" by adding the highlighted section below to switch to OOCV angular definition:
In the loss file in the training phase under the KLD loss mode, however, when I printed out the predicted angles, they were supposed to be all-negative, but sometimes their max angles show positive values. (I guess I may not have changed their angular definition). I want to ask you... Since I can change the truth boxes' angular definition by the process above, where can I change the predicted boxes' angular definition?
My derivation of your repo is here: https://github.com/Suppersine/YOLOv7_obb_KFIOU
According to MMRotate, the CSL loss function abides by the "Long edge" angular definition, ranging from [-pi/, & pi/2, while the KLD & KFIOU loss functions abide by the "Old OpenCV (OOCV)" definition, ranging from [-pi/2, 0). To convert between these. I have written the function inside the rboxs_utils.py file below:
def regular_theta(theta, mode='180', start=-pi/2): """ limit theta ∈ [-pi/2, pi/2) """ assert mode in ['360', '180'] cycle = 2 * pi if mode == '360' else pi theta = theta - start theta = theta % cycle return theta + start def lebox2ocbox(x, y, w, h, theta): x, y, = x, y #ocbox[:2] = lebox[:2] #ocbox[-2:] = lebox[-2:] if theta < 0: return x, y, w, h, theta else: w, h = h, w theta -= pi/2 return x, y, w, h, theta def ocbox2lebox(x, y, w, h, theta): x, y, = x, y #lebox[:2] = ocbox[:2] #lebox[-2:] = ocbox[-2:] if w == max(w, h): return x, y, w, h, theta else: w, h = h, w theta += pi/2 return x, y, w, h, theta
and changed the "poly2rbox" by adding the highlighted section below to switch to OOCV angular definition:
In the loss file in the training phase under the KLD loss mode, however, when I printed out the predicted angles, they were supposed to be all-negative, but sometimes their max angles show positive values. (I guess I may not have changed their angular definition). I want to ask you... Since I can change the truth boxes' angular definition by the process above, where can I change the predicted boxes' angular definition?
Hello sir, I am getting the following error when using your code YOLOv7_obb_KFIOU, [Errno 2] No such file or directory: 'savevars.pkl', I looked at the code and found that the --mode parameter in train.py stores the CSL, KLD,KFIOU parameters, but I can't find savevars.pkl. Can you give me some advice?
root@autodl-container-3b34119352-a2e11eab:~# python YOLOv7_obb_KFIOU-master/train.py Traceback (most recent call last): File "YOLOv7_obb_KFIOU-master/train.py", line 27, in import val # for end-of-epoch mAP File "/root/YOLOv7_obb_KFIOU-master/val.py", line 19, in from utils.rboxs_utils import poly2hbb, rbox2poly File "/root/YOLOv7_obb_KFIOU-master/utils/rboxs_utils.py", line 11, in lmode = loadvar() File "/root/YOLOv7_obb_KFIOU-master/utils/optsave.py", line 13, in loadvar with open('savevars.pkl', 'rb') as file: FileNotFoundError: [Errno 2] No such file or directory: 'savevars.pkl'
我对你的回购的推导在这里:https://github.com/Suppersine/YOLOv7_obb_KFIOU
根据MMRotate的说法,CSL损失函数遵循“长边”角度定义,范围从[-pi/和pi/2,而KLD和KFIOU损失函数遵守“Old OpenCV(OOCV)”定义,范围从[-pi/2,0)。在这些之间转换。我已经在下面的rboxs_utils.py文件中编写了函数:
def regular_theta(theta, mode='180', start=-pi/2): """ limit theta ∈ [-pi/2, pi/2) """ assert mode in ['360', '180'] cycle = 2 * pi if mode == '360' else pi theta = theta - start theta = theta % cycle return theta + start def lebox2ocbox(x, y, w, h, theta): x, y, = x, y #ocbox[:2] = lebox[:2] #ocbox[-2:] = lebox[-2:] if theta < 0: return x, y, w, h, theta else: w, h = h, w theta -= pi/2 return x, y, w, h, theta def ocbox2lebox(x, y, w, h, theta): x, y, = x, y #lebox[:2] = ocbox[:2] #lebox[-2:] = ocbox[-2:] if w == max(w, h): return x, y, w, h, theta else: w, h = h, w theta += pi/2 return x, y, w, h, theta
并通过添加下面突出显示的部分来更改“poly2rbox”以切换到 OOCV 角度定义:
然而,在 KLD 损失模式下训练阶段的损失文件中,当我打印出预测的角度时,它们应该是全负的,但有时它们的最大角度显示正值。(我想我可能没有改变他们的角度定义)。我想问你...由于我可以通过上述过程更改真值框的角度定义,因此在哪里可以更改预测框的角度定义?
My derivation of your repo is here: https://github.com/Suppersine/YOLOv7_obb_KFIOU
According to MMRotate, the CSL loss function abides by the "Long edge" angular definition, ranging from [-pi/, & pi/2, while the KLD & KFIOU loss functions abide by the "Old OpenCV (OOCV)" definition, ranging from [-pi/2, 0). To convert between these. I have written the function inside the rboxs_utils.py file below:
def regular_theta(theta, mode='180', start=-pi/2): """ limit theta ∈ [-pi/2, pi/2) """ assert mode in ['360', '180'] cycle = 2 * pi if mode == '360' else pi theta = theta - start theta = theta % cycle return theta + start def lebox2ocbox(x, y, w, h, theta): x, y, = x, y #ocbox[:2] = lebox[:2] #ocbox[-2:] = lebox[-2:] if theta < 0: return x, y, w, h, theta else: w, h = h, w theta -= pi/2 return x, y, w, h, theta def ocbox2lebox(x, y, w, h, theta): x, y, = x, y #lebox[:2] = ocbox[:2] #lebox[-2:] = ocbox[-2:] if w == max(w, h): return x, y, w, h, theta else: w, h = h, w theta += pi/2 return x, y, w, h, theta
and changed the "poly2rbox" by adding the highlighted section below to switch to OOCV angular definition:
In the loss file in the training phase under the KLD loss mode, however, when I printed out the predicted angles, they were supposed to be all-negative, but sometimes their max angles show positive values. (I guess I may not have changed their angular definition). I want to ask you... Since I can change the truth boxes' angular definition by the process above, where can I change the predicted boxes' angular definition?
Hello!
- I think the calculation of KLD loss function has nothing to do with the definition of boundary box. It only needs to be defined in the same way throughout the project. ref: https://www.zhihu.com/people/flyyoung-68/posts
- If you change the definition of boundary box,maybe you should still change "general.py --function: non_max_suppression_obb_kld -- variable:theta_pred" and "loss_kld.py --ComputeLoss_kld --angele" .