Giter Site home page Giter Site logo

r-centernet's Introduction

R-CenterNet(中文)

基于CenterNet的旋转目标检测

前言

本工作初衷是提供一个极其精简的CenterNet代码,并对旋转目标进行检测,1.0为:

 ${R-CenterNet_ROOT}
 |-- backbone
 `-- |-- dlanet.py
     |-- dlanet_dcn.py
 |-- Loss.py
 |-- dataset.py
 |-- train.py
 |-- predict.py

应读者需求,随后更新了2.0

 ${R-CenterNet_ROOT}
 |-- labelGenerator
 `-- |-- Annotations
     |-- voc2coco.py
 |-- evaluation.py

2.0以及data/airplane、imgs、ret文件夹都不是必须的,如果您只是想快速上手,1.0足够了。

demo

  • R-DLADCN(推荐)(DCN编译与原版CenterNet保持一致)
    • image
  • R-ResDCN(主干网用的ResNet而不是DLA)
    • image
  • R-DLANet(如果你不会编译DCN,就使用这个没有编译DCN的主干网)
    • image
  • DLADCN.jpg
    • image

常见问题

  • 我对CenterNet原版代码 进行了重构,使代码看起来更加简洁。
  • 如何编译DCN以及环境需求, 与CenterNet 原版保持一致。
  • 关于数据处理与更多细节, 可以参考 here
  • torch版本1.2,如果你用的0.4会发生报错。

训练自己的多分类网络

  • 打标签用labelGenerator文件夹里面的代码。
  • 修改代码中所有num_classes为你的类别数目,并且修改back_bone中hm的数目为你的类别数,如: def DlaNet(num_layers=34, heads = {'hm': your classes num, 'wh': 2, 'ang':1, 'reg': 2}, head_conv=256, plot=False):

Related projects

R-CenterNet(English)

detector for rotated-object based on CenterNet

preface

The original intention of this work is to provide a extremely compact code of CenterNet and detect rotating targets: 1.0

 ${R-CenterNet_ROOT}
 |-- backbone
 `-- |-- dlanet.py
     |-- dlanet_dcn.py
 |-- Loss.py
 |-- dataset.py
 |-- train.py
 |-- predict.py

At the request of readers, 2.0 was subsequently updated:2.0

 ${R-CenterNet_ROOT}
 |-- labelGenerator
 `-- |-- Annotations
     |-- voc2coco.py
 |-- evaluation.py

2.0 and the data/airplane, imgs, ret folders are not required. If you just want to get started quickly, 1.0 is enough。

demo

  • R-DLADCN(this code)(How to complie dcn refer to the original code of CenterNet)
    • image
  • R-ResDCN(just replace cnn in resnet with dcn)
    • image
  • R-DLANet(not use dcn if you don't know how to complie dcn)
    • image
  • DLADCN.jpg
    • image

notes

  • I refactored the original code to make codes more concise.
  • How to complie dcn and configure the environment, refer to the original code of CenterNet.
  • For data processing and more details, refer to here
  • torch version==1.2,don't use version==0.4!

train your data

  • label your data use labelGenerator;
  • modify all num_classes to your classes num, and modify the num of hm in your back_bone, such as: def DlaNet(num_layers=34, heads = {'hm': your classes num, 'wh': 2, 'ang':1, 'reg': 2}, head_conv=256, plot=False):

Related projects

r-centernet's People

Contributors

bjmwang avatar zeroe04 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

r-centernet's Issues

About the multiple categories in code

Dear Author:
When I use this code to train for multiple categories, I find the code in "dataset.py" about line 37 "self._valid_ids = [1]" .Does it need to be modified? For example, two categories, self._valid_ids = [1, 2].

x0n= (x0 -x)*cosA -(y0 - y)*sinA + x

Thanks for your great work
In the file of predict.py, why use this equation?

x0n= (x0 -x)*cosA -(y0 - y)*sinA + x
y0n = (x0-x)*sinA + (y0 - y)*cosA + y

x1n= (x1 -x)*cosA -(y1 - y)*sinA + x
y1n = (x1-x)*sinA + (y1 - y)*cosA + y

x2n= (x2 -x)*cosA -(y2 - y)*sinA + x
y2n = (x2-x)*sinA + (y2 - y)*cosA + y

x3n= (x3 -x)*cosA -(y3 - y)*sinA + x
y3n = (x3-x)*sinA + (y3 - y)*cosA + y

请问训练完成后如何进行detection

win10,显卡2080s,train.py训练正常,训练完成后运行predict出现错误。
Traceback (most recent call last):
File "D:/R-CenterNet-master/predict.py", line 237, in
output, dets, forward_time = process(images, return_time=True)
File "D:/R-CenterNet-master/predict.py", line 152, in process
output = model(images)
File "D:\Anaconda\envs\CenterNet2\lib\site-packages\torch\nn\modules\module.py", line 477, in call
result = self.forward(*input, **kwargs)
File "./backbone\dlanet.py", line 610, in forward
ret[head] = self.getattr(head)(x)
File "D:\Anaconda\envs\CenterNet2\lib\site-packages\torch\nn\modules\module.py", line 477, in call
result = self.forward(*input, **kwargs)
File "D:\Anaconda\envs\CenterNet2\lib\site-packages\torch\nn\modules\container.py", line 91, in forward
input = module(input)
File "D:\Anaconda\envs\CenterNet2\lib\site-packages\torch\nn\modules\module.py", line 477, in call
result = self.forward(*input, **kwargs)
File "D:\Anaconda\envs\CenterNet2\lib\site-packages\torch\nn\modules\conv.py", line 301, in forward
self.padding, self.dilation, self.groups)
RuntimeError: CUDA error: out of memory

角度是怎么定义的

角度是怎么定义的?
R-CenterNet-master/imgs/001.jpg
比如这张图,里面只有一个大飞机,对应的xml。
0.54
这里的0.54是啥,是什么和什么之间的夹角,最好用图画出来说明一下。这样才直观。

<annotation>
	<folder>img</folder>
	<filename>001.jpg</filename>
	<path>F:\CV\毕业设计\打标签\img\001.jpg</path>
	<source>
		<database>Unknown</database>
	</source>
	<size>
		<width>958</width>
		<height>808</height>
		<depth>3</depth>
	</size>
	<segmented>0</segmented>
	<object>
		<name>aircraft</name>
		<pose>Unspecified</pose>
		<truncated>0</truncated>
		<difficult>0</difficult>
		<robndbox>
			<cx>602.1491</cx>
			<cy>523.8509</cy>
			<w>93.0</w>
			<h>105.0</h>
			<angle>0.54</angle>
		</robndbox>
		<extra/>
	</object>
</annotation>

疑问

image

箭头框是车辆头尾图,1-2-3是labelimg2画的框
角度定义不明确,作者,你好,请在readme中详细定一下规则吧,tks

angle_loss无法收敛的原因,其他loss均收敛

使用不同backbone的情况下,在多种实验下表明,只有dla34_dcn的backbone的angle_loss可以收敛,其他backbone包括resdcn_50,101,以及dlav0_34,angle_loss均无法有效收敛,其他head的loss表现均不错,这个问题可能是什么?角度的量纲?感受野?还是?

去掉ang后evalution代码报错

作者你好!我尝试使用这个工程去做行人检测,由于数据集问题,我去掉了旋转角,修改后可以正常训练模型,但是在模型评估阶段,我同样去掉了ang相关的内容,使用普通的iou。但是all_pre_num和num的输出都是0。我尝试去寻找哪里出了问题,在evalution.py文件的get_pre_ret函数中打印res = np.delete(res, 0, 0)之后得到的res=[],这是为什么呢?
我将修改之后的evalution和predict代码放在了csdn里:
https://blog.csdn.net/weixin_43786395/article/details/121322506?spm=1001.2014.3001.5501

如果您能有时间有时间浏览,将会非常感谢!!!

代码数据读取部分

"bbox": [
506.5467,
124.2383,
62.0,
91.0,
3.3464944418634275
],
分别为目标中心点(x,y),以及宽度,长度,角度,角度是以12点钟为0°,顺时针旋转的角度
可是代码里面怎么还是和原版centernet解析x1,y1,x2,y2用的一样

        for k in range(num_objs):  # num_objs图中标记物数目  
            ann = anns[k]  # 第几个标记物的标签
            bbox, an = coco_box_to_bbox(ann['bbox']) 
            cls_id = int(self.cat_ids[ann['category_id']]) 
            bbox[:2] = affine_transform(bbox[:2], trans_output)    # 将box坐标转换到 128*128内的坐标
            bbox[2:] = affine_transform(bbox[2:], trans_output)
            bbox[[0, 2]] = np.clip(bbox[[0, 2]], 0, output_w - 1)  
            bbox[[1, 3]] = np.clip(bbox[[1, 3]], 0, output_h - 1)
            # 上面几行都是做数据扩充和resize之后的变换,不重要
            h, w = bbox[3] - bbox[1], bbox[2] - bbox[0]
            if h > 0 and w > 0:
                radius = gaussian_radius((math.ceil(h), math.ceil(w)))  
                radius = max(0, int(radius))
                ct = np.array([(bbox[0] + bbox[2]) / 2, (bbox[1] + bbox[3]) / 2], dtype=np.float32) 
                ct_int = ct.astype(np.int32) 
                draw_gaussian(hm[cls_id], ct_int, radius)
                wh[k] = 1. * w, 1. * h
                ang[k] = 1. * an
                ind[k] = ct_int[1] * output_w + ct_int[0]  
                reg[k] = ct - ct_int
                reg_mask[k] = 1
        ret = {'input': inp, 'hm': hm, 'reg_mask': reg_mask, 'ind': ind, 'wh': wh, 'ang':ang}

多类别训练问题

请问 多类别训练,除了更改num_classes变量,还需要更改其他的吗?

bbox annotation format?

Dear @ZeroE04 ,
Thank you for sharing your work.
I am not clear about the bbox annotation of your dataset. I guess it is in xc, yc, w, h, ang, but I do not know how w, h are measured, parallel to the image coordinates or from the cv2.minAreaRect?

def coco_box_to_bbox(box):

For my dataset

     rect = cv2.minAreaRect(hull)
     xc, yc = rect[0][0], rect[0][1]
     w, h = rect[1][0], rect[1][1]
     angle = rect[2]
     angle = ange_to_0_180(angle)
     rbbox = [xc, yc, w, h, angle]

So, with my bbox annotation, I do not have to use the coco_box_to_bbox function right?
Thank for your time.

训练时图片缩小4倍

你好,感谢您的分享,请问训练时图片缩小4倍的考虑时什么呢?为了提高小目标的检测率吗?谢谢。

Problem of angle prediction

Thanks for you r code.
I have trained this model on my dataset, but when i predict the targets, the angle prediction turns to be zero.
Furthermore, the loss did not converge when epoch=100.
Please give some suggestions.

有人成功用torch script生成了pt模型吗

我用的piou+centerOBB, trace成功了模型 但是模型不对,看网上有人说应该用script 但script只支持python的子集 需要修改forward的代码,修改到DLAUp的getAttr(self, "proj_" + str(startp - i)) 这种代码就修改不下去了,因为script不支持动态函数,请教大神们有成功把centernet这一类的模型给成功script的吗 (不是用trace的哈),可否参考一下script修改的forward源码 谢谢!

训练HRSC2016数据集

大佬您好,我训练HRSC2016数据集最终train loss和val loss维持在4左右就不变了,测试了demo发现预测效果也不好。能指点一二吗?谢谢了

Compare with CenterNet.

Hi! I am very interested in your work, Do you compare the performance of R-CenterNet in AirPlane datasets with that of orignal CenterNet?

img_size

How do I choose img_size for the model? Thanks you

the differences with centerNet?

centerNet papers shows, predicting heatmap+center points+cornel points, as pic bellow, but the code just only regress the center points and boxes width and height ?

image

关于角度的疑问

图片

centernet出来的是外接矩形,就是图片中蓝色框,然后角度是目标的倾斜角度(设为角度A)吗,然后是把蓝色的外接矩形的四个点根据目标中心旋转角度A吗?我看代码里面是这样

关于类别计算问题

图片
大佬你好,我想问一下关于predict里面的tmp_c是指这次预测的类别么?为啥要这么计算呢?不应该直接是i么,属于哪个类别热力图就算哪个类别

map计算

当种类训练,最终验证在evolations.py中怎么修改得到map的值

如何用Libtorch调用生成的pt文件

我将骨干网络改成了resnet18,并成功生成了pt格式(如以下代码),但是在Libtorch上调用时出错了,我怀疑是不是模型的输出接口用的是列表的形式,在Libtorch中无法识别,请问有什么样的解决办法吗?

//python生成pt格式模型:
model = ResNet(18)
model.load_state_dict(torch.load("ResNet18_best.pth"))
model.to("cpu")
traced_script_module = torch.jit.trace(model,torch.ones(1,3,512,512), strict=False)
traced_script_module.save("1.pt")

//Libtorch调用代码
torch::jit::script::Module model;
model = torch::jit::load("./1.pt");

//Libtorch调用时显示的错误:
Assertion failed: idx < size(), file C:\b\windows\pytorch\c10/util/SmallVector.h, line 201

dataset

The angle of my dataset is 0-180 or -90 to 90 ? thanks you

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.