Giter Site home page Giter Site logo

lx-cly / yolov5_obb_kld Goto Github PK

View Code? Open in Web Editor NEW
45.0 1.0 10.0 9.41 MB

KLD实现旋转目标检测

License: GNU General Public License v3.0

Dockerfile 0.31% Shell 0.63% Python 62.35% Makefile 0.01% C++ 30.80% Cython 0.13% Cuda 2.63% SWIG 0.03% Jupyter Notebook 3.12%

yolov5_obb_kld's Introduction

YOLOv5_OBB_KLD

img

img

img

代码实现了基于YOLOv5的遥感旋转框检测。利用CSL和KLD实现角度的学习,并且加入注意力机制提高检测效果。

数据集和权重文件

项目安装 (支持Linux系统)

1. Python 3.8 with all requirements.txt dependencies installed, including torch==1.6, opencv-python==4.1.2.30, To install run:

pip install -r requirements.txt

2. Install swig

cd  \.....\yolov5_OBB_KLD\utils
sudo apt-get install swig

3. Create the c++ extension for python

swig -c++ -python polyiou.i
python setup.py build_ext --inplace

训练

  • train.py. Note:修改.\models\yolo.pyDetect类中初始化函数的self.angle = 180 #CSL对应180 KLD对应1,默认使用CSL.
python train.py --weights weights/yolov5m.pt --cfg models/yolov5m.yaml --use_kld False --device 0 --epochs 300 --batch_size 4 --workers 4 --logdir runs/    

评估

  • detect.py. Detect and visualize the detection result. Get the detection result txt.

  • evaluation.py. Merge the detection result and visualize it. Finally evaluate the detector

python detect.py --weights runs/exp/weights/best.pt --source 'dataset path' --output 'output path' --conf_thres 0.35 --iou_thres 0.4 --device 0 --kld False 
python evaluation.py 
''' example
检测结果已merge
检测结果已按照类别分类
校验数据集名称文件已生成
classname: ship
P: 0.8550878121966288
R: 0.900046446818393
[email protected]: 0.8889719225631516
classaps:  [     88.897]
原始存在文件,删除
检测结果已按照类别分类
校验数据集名称文件已生成
classname: ship
P: 0.8511538986754063
R: 0.8677432827509397
[email protected]: 0.8096364184338725
classaps:  [     80.964]
'''

结果展示

数据集图片尺寸裁剪为1024*1024,gap为10%。实验中NMS时统一使用的置信度阈值是0.35,IoU阈值是0.4。

img

感激

感谢以下的项目,排名不分先后

关于作者

  Name  : "lx"
  describe myself:"good man"

yolov5_obb_kld's People

Contributors

lx-cly avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

yolov5_obb_kld's Issues

question

请问你的yolov5s_decoupled head.yaml 里面说要增加分支 请问应该怎么去增加分支 来实现解耦头?
谢谢

关于KLD损失的疑问

作者你好,感谢你分享的工作,在阅读源码时有几个问题。
您给出的KLD损失绘图如下,显示分类损失一直为0,而角度损失一直下降。
image
但是,我在阅读compute_loss_KLD中,langle 初始值为0 ,
image
而后,langle 未参与其他计算,就到达最后损失计算,langle *= h['angle'] *S,所以 langle=0,即 langle 一直为0,角度仅在Box损失计算中参与Iou的计算。如下图
image
我试着训练DOTA数据集,效果不好。想知道您给的数据集label是什么格式(poly的4点坐标,还是由poly经过CV外接最小矩形的带角度的坐标,由OpenCV法转化为长边法的代码在哪里喃),谢谢
PS,这是我用CSL测全部16类后,得到的ship:0.8941434649109584, 但是现在KLD得到效果不好

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:

image

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?

2023-02-07_15-22-32

训练过程

你好,请问你在训练过程中出现精度振荡范围大的情况吗

KLD训练得到权重后,在检测时发现角度信息相差不大

KLD训练得到权重后,在检测时发现角度信息相差不大,请问是标签或者是其他地方需要调整吗。
这是三个不同图片检测出来的结果,经过换算后,他们的角度信息几乎一致,检测结果看起来像是水平框检测
((876.5000610351562, 768.5), (462.3126525878906, 404.125), -87.8736572265625)
((862.5, 677.5000610351562), (275.181640625, 507.555908203125), -87.9666748046875)
((696.5, 1057.5001220703125), (185.2694854736328, 233.78030395507812), -87.05175018310547)

角度输出

作者你好!我想请问一下,想要在验证的时候保存目标框的旋转角度的话,需要在哪里改动呢?感谢!

detect报错

大佬大佬,请问要怎么样解决?
使用TPH训练,使用检测命令加载该训练权重时 python detect.py --weights runs_swin/exp/weights/best.pt 出现报错
Fusing layers...
Traceback (most recent call last):
File "detect.py", line 350, in
detect(kld_flag=opt.kld)
File "detect.py", line 54, in detect
model = attempt_load(weights, map_location=device) # load FP32 model
File "/content/drive//YOLOv5_OBB_KLD/models/experimental.py", line 150, in attempt_load
model.append(torch.load(w, map_location=map_location)['model'].float().fuse().eval()) # load FP32 model
File "/content/drive/
/YOLOv5_OBB_KLD/models/yolo_new.py", line 165, in fuse
if isinstance(m, (Conv, DWConv)) and hasattr(m, 'bn'): # 如果函数层名为Conv标准卷积层,且同时 层中包含‘bn’属性名
TypeError: isinstance() arg 2 must be a type or tuple of types

GPU问题

你好,请问一下你跑dota数据集有没有使用多gpu训练

训练损失不收敛是什么情况?

大佬,训练YOLOv5m模型,根据您的开源数据集,开源模型及代码,训练三十多epochs total_loss从0.6左右上升到5,不会收敛,请问什么情况?
1709791884502_15012AF5-E7A2-45eb-8847-517EA259EDCC

多目标训练超参数设置问题

您好,非常感谢您提供的资源和教程。我自己的数据集本来就是yolo、VOC格式的,我将其转换成DOTA格式,因此相比您提供的数据集,我的检测目标大很多,就没有做图像切割,以符合您提供的kld相关的脚本。我的数据集是多目标的,且是缺陷检测,边缘不是很明确,目标有很大的也有很小的。使用detect.py将置信度调低,发现先验框anchors产生的旋转方框,相比我的目标小很多,训练效果很差,甚至损失函数增大乃至发散。想请问一下,如何调整超参数来优化。

数据集预处理

你好 我按照流程切割DOTA1.5的数据集不能用于训练,大佬数据集处理的代码能看一下吗

new question

大佬您好,这个KLD是损失函数的计算吧,在那个yaml文件关于文件的定义中,不用体现出来嘛

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.