Giter Site home page Giter Site logo

rotation-yolov5's Introduction

the rotation detection

Requirement

torch==1.6
shapely==1.7.1
opencv==4.2.0.34

inference

you can download the weights BaiduYun(password is 4ud5) or GoogleDrive for ship detection by my dataset(not DOTA) to test the demo.

$ python detect.py

image

train

what format my model need

Not much different from yolo dataset,just add an angle and we define the box attribute w is always longer than h!

So wo define the box label is (cls, c_x, c_y, Longest side,short side, angle)

Attention!we define angle is a classify question,so we define 180 classes for angle.

For Example: image Range for angle is [-90,90), so wo should add 90 in angle while make your dataset label and then your label's Range should be [0,179) image

modify yaml

models/yolov5m.yaml: set nc to your dataset class num; data/wheat0.yaml:set nc to your dataset class num, and set names to your dataset class name;

$ python train.py

update

2021.1.4---correct some BUG for training

details

If you have any question,welcome discuss with me by This or email to [email protected]

rotation-yolov5's People

Contributors

bosszard 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

rotation-yolov5's Issues

RuntimeError: cannot perform reduction function max on tensor with no elements because the operation does not have an identity

I am running the algorithm on a Mac OS and this is the error I get when I run the detect.py file

run code:
python detect.py --weights yolov5s.pt --source data/images/carpark1.jpg

error output:
Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.4, device='', img_size=1024, iou_thres=0.5, output='inference/output', save_txt=False, source='data/images/carpark1.jpg', update=False, view_img=False, weights=['yolov5s.pt'])
Using CPU

Fusing layers...
Model Summary: 140 layers, 7.45958e+06 parameters, 0 gradients
image 1/1 /Users/syazaniwahid/Documents/UROPS/YOLO/YOLOV5_RBB/rotation-yolov5/data/images/carpark1.jpg: Traceback (most recent call last):
File "detect.py", line 174, in
detect()
File "detect.py", line 79, in detect
pred = rotate_non_max_suppression(pred, opt.conf_thres, opt.iou_thres, classes=opt.classes, agnostic=True)
File "/Users/syazaniwahid/Documents/UROPS/YOLO/YOLOV5_RBB/rotation-yolov5/utils/general.py", line 845, in rotate_non_max_suppression
conf, j = x[:, 5:5 + nc].max(1, keepdim=True)
RuntimeError: cannot perform reduction function max on tensor with no elements because the operation does not have an identity

dota v1.5数据集训出来效果很差

           Class      Images     Targets           P           R      [email protected]  [email protected]:.95: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 115/115 [00:23<00:00,  4.92it/s]
             all         458    6.96e+04      0.0863       0.133       0.098      0.0347
           plane         458    2.55e+03       0.423       0.551       0.435       0.168
baseball-diamond         458         213       0.292       0.634       0.494       0.164
          bridge         458         466       0.114       0.337       0.157      0.0381

ground-track-field 458 145 0.225 0.407 0.324 0.128
small-vehicle 458 4.33e+04 0.327 0.198 0.159 0.0563
large-vehicle 458 5.14e+03 0 0 0 0
ship 458 1.08e+04 0 0 0 0
tennis-court 458 763 0 0 0 0
basketball-court 458 143 0 0 0 0
storage-tank 458 2.94e+03 0 0 0 0
soccer-ball-field 458 149 0 0 0 0
roundabout 458 185 0 0 0 0
harbor 458 2.1e+03 0 0 0 0
swimming-pool 458 576 0 0 0 0
helicopter 458 78 0 0 0 0
container-crane 458 14 0 0 0 0
基本上在val集上,没有识别出来,16个类
我是在train上训练了500epoch,不应该有问题啊,求解答。

detector.py问题

你好,你的这个项目很有参考价值。我使用了你的旋转框yolov5,我下载了你的权重文件,当我运行detect.py文件时,存在以下问题,请问怎么解决呢
/home/miki/anaconda3/envs/yolov5/bin/python /home/miki/project/object_detection/rotation-yolov5/detect.py
Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.4, device='', img_size=1024, iou_thres=0.5, output='inference/output', save_txt=False, source='inference/images', update=False, view_img=False, weights='weights/m-70.pt')
Using CUDA device0 _CudaDeviceProperties(name='GeForce GTX 1050 Ti', total_memory=4036MB)

Fusing layers...
Model Summary: 188 layers, 2.22122e+07 parameters, 0 gradients
image 1/1 /home/miki/project/object_detection/rotation-yolov5/inference/images/1.tif: Traceback (most recent call last):
File "/home/miki/project/object_detection/rotation-yolov5/detect.py", line 174, in
detect()
File "/home/miki/project/object_detection/rotation-yolov5/detect.py", line 79, in detect
pred = rotate_non_max_suppression(pred, opt.conf_thres, opt.iou_thres, classes=opt.classes, agnostic=True)
File "/home/miki/project/object_detection/rotation-yolov5/utils/general.py", line 869, in rotate_non_max_suppression
i = nms(boxes, scores)
File "/home/miki/project/object_detection/rotation-yolov5/utils/general.py", line 798, in nms
rotate_ious = rotate_iou(max_iou_boxes[-1], sort_boxes[1:])
File "/home/miki/project/object_detection/rotation-yolov5/utils/general.py", line 710, in rotate_iou
r_b1 = get_rotated_coors(box1[i])
File "/home/miki/project/object_detection/rotation-yolov5/utils/general.py", line 729, in get_rotated_coors
R[:2] = cv2.getRotationMatrix2D(angle=-a*180/math.pi, center=(cx,cy), scale=1)
TypeError: Argument 'angle' can not be treated as a double

Process finished with exit code 1
希望能得到你的回复,谢谢!

angle dataset

Hello. If my dataset have angle from -180 to 180, Can I use this repo?

dota test

Thanks for your sharing. I wonder what is your test result on the DOTA data set?

不同

作者,您好!我对您的工作非常感兴趣,我有些疑问:rotation-yolov5与yolov5模型有什么不同,修改哪一部分?

运行detect.py时遇到了问题,这该怎么解决呢

Fusing layers...
Model Summary: 188 layers, 2.22122e+07 parameters, 0 gradients
image 1/1 D:\Weld inspection\YOLOv5\rotation-yolov5-master\inference\images\1.tif: Traceback (most recent call last):
File "D:\Weld inspection\YOLOv5\rotation-yolov5-master\detect.py", line 174, in
detect()
File "D:\Weld inspection\YOLOv5\rotation-yolov5-master\detect.py", line 79, in detect
pred = rotate_non_max_suppression(pred, opt.conf_thres, opt.iou_thres, classes=opt.classes, agnostic=True)
File "D:\Weld inspection\YOLOv5\rotation-yolov5-master\utils\general.py", line 869, in rotate_non_max_suppression
i = nms(boxes, scores)
File "D:\Weld inspection\YOLOv5\rotation-yolov5-master\utils\general.py", line 797, in nms
rotate_ious = rotate_iou(max_iou_boxes[-1], sort_boxes[1:])
File "D:\Weld inspection\YOLOv5\rotation-yolov5-master\utils\general.py", line 710, in rotate_iou
r_b1 = get_rotated_coors(box1[i])
File "D:\Weld inspection\YOLOv5\rotation-yolov5-master\utils\general.py", line 729, in get_rotated_coors
R[:2] = cv2.getRotationMatrix2D(angle=-a*180/math.pi, center=(cx,cy), scale=1)
TypeError: Can't parse 'center'. Sequence item with index 0 has a wrong type

数据集制作

你好,我想问一下,标签文件里 cx,cy,w,h 是怎么算出来的,网上的数据标签处理只是针对无旋转的YOLOv5,现在我训练出来的结果很差,,基本都不能看,所以我怀疑是数据集制作的问题
image

Weights not available anymore

Hello,

When I clicked the download link you've given for weights, it says "Page does not exist". Please send me the '10.28-0.5angle.pt' file.
Thank you.

数据集格式问题

您好,我自己制作数据集后,在训练时在wheat0.yaml中要按照什么样的方式进行排放呢?

预测问题

你好请问一下我用hrsc2016数据集训练完之后预测得到的box有的变成一条直线是怎么回事,就像照片中这种情况
9d82aef52d8ad0f9a43d63006077829

retanglelabel2mylabel.py

请问 retanglelabel2mylabel.py,w,h是不是写反了?还有原始图片是不是必须得是长方形?

数据集制作

你好,我想问一下,标签文件里 cx,cy,w,h 是怎么算出来的,网上的数据标签处理只是针对无旋转的YOLOv5,现在我训练出来的结果很差,,基本都不能看,所以我怀疑是数据集制作的问题
image

预训练有关事宜

你好,我在查看了你的代码之后,发现你的代码似乎不适合用作预训练使用
rotation-yolov5中的最后一维是[x,y,w,h,class_num(5),angle(180)]
如果我的class_num n<5,我的输出变为[x,y,w,h,class_num(n),angle(180)]那么前4+n维都是正确的,用于预测xywh和class,但是后面[4+n:4+n+180]将使用原来用于预测类和角度的维度作为预训练,而不是使用原来的后180个维度作为预训练,似乎不符合预训练的原理。
所以应该将代码修改为[x,y,w,h,angle(180),class_num]
不知道我的理解是否正确,如果正确的话,我想将COCO数据集进行旋转之后获得一个合适的数据集,将rotation-yolov5在上面训练得到一个预训练模型,然后再在我的数据集上进行训练,这个想法是正确的吗?

Can't get attribute 'SiLU'

Traceback (most recent call last):
File "train.py", line 456, in
train(hyp, opt, device, tb_writer)
File "train.py", line 69, in train
ckpt = torch.load(weights, map_location=device) # load checkpoint
File "/home/yuanweiqiao/anaconda3/envs/CL/lib/python3.7/site-packages/torch/serialization.py", line 584, in load
return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
File "/home/yuanweiqiao/anaconda3/envs/CL/lib/python3.7/site-packages/torch/serialization.py", line 842, in _load
result = unpickler.load()
AttributeError: Can't get attribute 'SiLU' on <module 'torch.nn.modules.activation' from '/home/yuanweiqiao/anaconda3/envs/CL/lib/python3.7/site-packages/torch/nn/modules/activation.py'>

Yolov5 version

Hello. I use your repo then see my dataloader image with labels not corresponding to each other? Can you re-check your repo?
Thanks very much

一个BUG?

ttheta = torch.zeros_like(ps[:, 10:])

这里设置了ttheta的形状,应该是根据后面的 t = torch.full_like(ps[:, 5:10], cn, device=device)来设置的
这里的t是设置为跟cls形状相同,但是默认固定为原始的5个类别,所以如果只是修改了yaml里的类别为其他,而不修改这里就会报错,这里是不是要修改一下弄成跟yaml联系才行
我在打算把这个模型用在我的自定义数据集上发现了这个问题,我是只有一个类别要识别的,我是最近才接触的目标检测,如果是我理解错了,希望能提出纠正一下。

test,py

Can I using test.py in your repo to test with rotated bounding box ?

train.py 运行到第二轮报运行时错误

...很多如下错误
/opt/conda/conda-bld/pytorch_1603729062494/work/aten/src/ATen/native/cuda/IndexKernel.cu:84: operator(): block: [60,0,0], thread: [60,0,0] Assertion index >= -sizes[i] && index < sizes[i] && "index out of bounds" failed.
/opt/conda/conda-bld/pytorch_1603729062494/work/aten/src/ATen/native/cuda/IndexKernel.cu:84: operator(): block: [60,0,0], thread: [61,0,0] Assertion index >= -sizes[i] && index < sizes[i] && "index out of bounds" failed.
/opt/conda/conda-bld/pytorch_1603729062494/work/aten/src/ATen/native/cuda/IndexKernel.cu:84: operator(): block: [60,0,0], thread: [62,0,0] Assertion index >= -sizes[i] && index < sizes[i] && "index out of bounds" failed.
/opt/conda/conda-bld/pytorch_1603729062494/work/aten/src/ATen/native/cuda/IndexKernel.cu:84: operator(): block: [60,0,0], thread: [63,0,0] Assertion index >= -sizes[i] && index < sizes[i] && "index out of bounds" failed.
2/59 2.59G 0.0773 0.04795 0.05063 0.2194 0.3953 1 1024: 93%|█████▌| 12214/13191 [1:37:05<07:46, 2.10it/s]
Traceback (most recent call last):
File "train.py", line 456, in
train(hyp, opt, device, tb_writer)
File "train.py", line 269, in train
loss, loss_items = compute_loss(pred, targets.to(device), model) # loss scaled by batch_size
File "/home/cao/Downloads/rotation-yolov5-master/utils/general.py", line 530, in compute_loss
tobj[b, a, gj, gi] = (1.0 - model.gr) + model.gr * iou.detach().clamp(0).type(tobj.dtype) # iou ratio
RuntimeError: CUDA error: device-side assert triggered

预测的问题

请问怎么在预测的时候显示概率和类别呢?

problem while downloading weights I 下载权重时出现问题

Hi, I am trying to download the trained weights which you have added here. Could you help, to get them, please.

嗨,我正在尝试下载您在此处添加的经过训练的砝码。 您能帮忙,请得到他们。

PS: I don't understand Chinese)

角度问题

请问下你使用分类的方法求目标的角度吗?0-180°对应180个类别

AttributeError: 'LineString' object has no attribute 'exterior'

请问这个是什么原因呢

Traceback (most recent call last):
  File "detect.py", line 175, in <module>
    detect()
  File "detect.py", line 116, in detect
    plot_one_box(xywh, im0, label=label, color=colors[int(cls)], line_thickness=3, path=path)
  File "D:\master\code\car_detection\rotation-yolov5-master\utils\general.py", line 1332, in plot_one_box
    _x, _y = poly_box.intersection(maxbox).exterior.coords.xy
AttributeError: 'LineString' object has no attribute 'exterior'

图片形状问题

你好,请问图片必须是正方形1024*1024吗?可以是长方形的图片吗?

BUG?

ttheta = torch.zeros_like(ps[:, 5+class_num:])

我进行DEBUG的时候,发现compute_loss里的p的shape是[batch,3,128,128,5+180+class]
但是yolov5里的是[batch,3,128,128,4+class],所以shape最后一个维度应该是4(x,y,w,h)+1(confidence)+1(angle)+class才对啊,这里的180是哪里来的,这样angle就是有180个维度了,但是应该是只有一个才对啊
输出的p应该是[batch,3,128,128,4+1+1+class]
并且ttheta = torch.zeros_like(ps[:, 5])才对吧 而不是ttheta = torch.zeros_like(ps[:, 5])

the function of def rectlong2opencv(boxes)

可以解释一下这个函数吗?

def rectlong2opencv(boxes):

    boxes_ = boxes.copy()
    boxes_[boxes[..., 4] < 0, 2] = boxes[boxes[..., 4] < 0, 3]
    boxes_[boxes[..., 4] < 0, 3] = boxes[boxes[..., 4] < 0, 2]
    boxes_[boxes[..., 4] >= 0, 4] = boxes[boxes[..., 4] >= 0, 4] - 90
    gt_box = boxes_.copy()
    gt_box[..., 2] = boxes_[..., 3]
    gt_box[..., 3] = boxes_[..., 2]
    return gt_box
boxes_[boxes[..., 4] < 0, 2] = boxes[boxes[..., 4] < 0, 3]
boxes_[boxes[..., 4] < 0, 3] = boxes[boxes[..., 4] < 0, 2]
这里第三四个参数互换,然后下面又换了过来
gt_box[..., 2] = boxes_[..., 3]
gt_box[..., 3] = boxes_[..., 2]

数据标签制作问题

请问在标签文件中的cx, cy是指中心点坐标还是左上角坐标,角度在制作的过程中做了什么归一化操作吗

about torch version and requirements

Hi,我在anachonda3中完成环境配置,尝试运行detect.py时遇到了以下问题,这些问题可能来源于torch版本或者其他的冲突
CUDA=10.0, cudnn=7.6.5, python=3.7, opencv-python=4.2.0.34
测试环境1:torch=1.6, torchvision=0.7, 其他包均从requirement.txt文件安装,运行detect.py报错:
TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

测试环境2:torch=1.7, torchvision=0.8.1, 其他包均遵从U版yolov5 requirement.txt,降低opencv-python版本至4.2。i.e.标准yolov5环境,并测试通过yolov5。加装shapely。运行detect.py报错:
torch.nn.modules.module.ModuleAttributeError: 'Hardswish' object has no attribute 'inplace'
根据网上说法,这个问题需将torch降低至1.6,所以该问题死循环了。

the definition of angle?

the longside clockwise to x-axis is positive angle?
the final angle is the longside to x-axis and then add 90?
so the final angle of the three example you gave is 0+90, 40+90, -90+90, is this right?

AttributeError: 'Hardswish' object has no attribute 'inplace'

(yolov5rbb) C:\Users\PC\Documents\UROPS\YOLOV5_RBB\rotation-yolov5>python detect.py --weights yolov5s.pt --source data/images/carpark2.jpg
Namespace(weights=['yolov5s.pt'], source='data/images/carpark2.jpg', output='inference/output', img_size=1024, conf_thres=0.4, iou_thres=0.5, device='', view_img=False, save_txt=False, classes=None, agnostic_nms=False, augment=False, update=False)
Using CPU

Fusing layers...
Model Summary: 140 layers, 7.45958e+06 parameters, 0 gradients
image 1/1 C:\Users\PC\Documents\UROPS\YOLOV5_RBB\rotation-yolov5\data\images\carpark2.jpg: Traceback (most recent call last):
File "C:\Users\PC\Documents\UROPS\YOLOV5_RBB\rotation-yolov5\detect.py", line 174, in
detect()
File "C:\Users\PC\Documents\UROPS\YOLOV5_RBB\rotation-yolov5\detect.py", line 75, in detect
pred = model(img, augment=opt.augment)[0]
File "C:\Users\PC\anaconda3\envs\yolov5rbb\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl
return forward_call(*input, **kwargs)
File "C:\Users\PC\Documents\UROPS\YOLOV5_RBB\rotation-yolov5\models\yolo.py", line 116, in forward
return self.forward_once(x, profile) # single-scale inference, train
File "C:\Users\PC\Documents\UROPS\YOLOV5_RBB\rotation-yolov5\models\yolo.py", line 136, in forward_once
x = m(x) # run
File "C:\Users\PC\anaconda3\envs\yolov5rbb\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl
return forward_call(*input, **kwargs)
File "C:\Users\PC\Documents\UROPS\YOLOV5_RBB\rotation-yolov5\models\common.py", line 89, in forward
return self.conv(torch.cat([x[..., ::2, ::2], x[..., 1::2, ::2], x[..., ::2, 1::2], x[..., 1::2, 1::2]], 1))
File "C:\Users\PC\anaconda3\envs\yolov5rbb\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl
return forward_call(*input, **kwargs)
File "C:\Users\PC\Documents\UROPS\YOLOV5_RBB\rotation-yolov5\models\common.py", line 33, in fuseforward
return self.act(self.conv(x))
File "C:\Users\PC\anaconda3\envs\yolov5rbb\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl
return forward_call(*input, **kwargs)
File "C:\Users\PC\anaconda3\envs\yolov5rbb\lib\site-packages\torch\nn\modules\activation.py", line 472, in forward
return F.hardswish(input, self.inplace)
File "C:\Users\PC\anaconda3\envs\yolov5rbb\lib\site-packages\torch\nn\modules\module.py", line 1207, in getattr
raise AttributeError("'{}' object has no attribute '{}'".format(
AttributeError: 'Hardswish' object has no attribute 'inplace'

How do I resolve the hardwish error

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.