RotationDetection
RotationDetection copied to clipboard
Angular definition problem
My derivation of your repo (SSTato's +Yolov7OBB) 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?