Code Monkey home page Code Monkey logo

s2anet's Introduction

S2ANet

A reimplementation of the S2ANet algorithm for Oriented Object Detection.

Note: Support DDP training and Auto Mixed Precision in Pytorch, so the training is faster!

We release the latest version !

  • To normalize the inputing data, the images are divided by 255.0, instead of using mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], so we don't need to storage the mean and std in inference.
  • In training phase, we don't freeze parameters in the first stage of ResNet, which will add a little more training time.
  • DDP training are more stable.

1. Environment dependency

Our environment: Ubuntu18.04 + pytorch1.7 + cuda10.2
We don't try other environment, but we recommend pytorch>=1.6 for DDP training.

2. Installation

(1)Clone the S2ANet repository

git clone https://github.com/chongkuiqi/S2ANet.git   
cd S2ANet  

(2)Install DOTA_devkit

sudo apt-get install swig  
cd DOTA_devkit/polyiou  
swig -c++ -python csrc/polyiou.i  
python setup.py build_ext --inplace  

(3)Compilate the C++ Cuda Library

cd S2ANet
python setup.py build_ext --inplace

3. Prepare datasets

We take the DOTA dataset for example.

(1)Dataset folder structure

We should download the DOTA dataset, then change the folder structure like so:

your_dir
├── DOTA
│   ├── train
│   │   ├── images
│   │   ├── labelTxt
│   ├── val
│   │   ├── images
│   │   ├── labelTxt

(2) Split images and and convert annotations format

The original images in DOTA have so large size, so we need to split them into chip images, like this:
note: the DOTA path and save path in 1_prepare_dota1_ms.py should be changed.

cd S2ANet/DOTA_devkit/
python 1_prepare_dota1_ms.py

Then convert the DOTA annotations to yolo format.
note: the DOTA_split path in 2_convert_dota_to_yolo.py should be changed.

python 2_convert_dota_to_yolo.py

Besides, val_split.txt is needed for evulate the model, this file records image names without extension. note: the path in 3_create_txts.py should be changed.

python 3_create_txt.py

(3) Config dota.yaml

The dota.yaml is also needed.
note: the path in dota.yaml should be changed.

Finally, the folder structure will be like this:

your_dir
├── DOTA
│   ├── train
│   │   ├── images
│   │   ├── labelTxt
│   ├── val
│   │   ├── images
│   │   ├── labelTxt
├── DOTA_split
│   ├── train
│   │   ├── empty_images
│   │   ├── empty_labels
│   │   ├── images
│   │   ├── labels
│   │   ├── labelTxt
│   ├── val
│   │   ├── images
│   │   ├── labels
│   │   ├── labelTxt
│   │   ├── val_split.txt

4. Train S2ANet model

Most of the time, there is no need to modify the learning rate when setting different batch-size.

(1) Single-GPU

cd S2ANet
python train.py

(2) Mutil-GPU

Note: We support pytorch Multi-GPU DistributedDataParallel Mode !

python -m torch.distributed.launch --nproc_per_node 2 train.py --device 0,1 --batch-size 16

If you get RuntimeError: Address already in use, use a different port number by adding --master_port like below,

python -m torch.distributed.launch --master_port 1234 --nproc_per_node 2 ...

5. Results and trained weights on DOTA dataset

Note: We only use the DOTA train set, and report the mAP50 on DOTA val set.

Model Backbone train mAP50 Download
S2ANet (paper) R-50-FPN train+val set 74.04(test set) ------
S2ANet (paper) R-50-FPN train set 70.2(val set) ------
S2ANet (this impl.) R-50-FPN train set 70.2(val set) model
S2ANet (latest) R-50-FPN train set 70.7(val set) model

6.Refenerce

s2anet's People

Contributors

cckyqf avatar chongkuiqi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

cckyqf sirliyang

s2anet's Issues

训练是数据集出现问题

AssertionError: train: No labels in /media/mjh/F674A9D874A99BBD/DOTA/train/labels.cache. Can not train without labels. See https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data
正式训练时候报出上面这个错误,文件路径并没有错,查到一种解决方法是改变文件目录层级
#└─ mydata

├─ images
│ ├─ test # 下面放测试集图片
│ ├─ train # 下面放训练集图片
│ └─ val # 下面放验证集图片
└─ labels
├─ test # 下面放测试集标签
├─ train # 下面放训练集标签
├─ val # 下面放验证集标签
但是这个文件目录层级与README中不同,我试了一下报出了这个错误
Exception: train: Error loading data from /home/mjh/文档/DOTA/images/train : train: /home/mjh/文档/DOTA/images/train does not exist
See https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data
我参考这篇博客,修改了一下https://blog.csdn.net/weixin_46085845/article/details/127903878
运行过后报错为
File "/home/mjh/文档/S2ANet-main/utils/general.py", line 415, in check_dataset
raise Exception('Dataset not found.')
Exception: Dataset not found.
找不到数据集位置了,请问有什么解决方法吗

关于训练的问题

您好!在训练开始后出现以下问题,请问这个文件何时生成的,谢谢!
2022-09-09 00-36-57屏幕截图

同样是运行2(3)时出错

更改主动旋转滤波器的cuda源码,将#include <THC/THC.h>注释掉,把THCudaCheck替换为AT_CUDA_CHECK,并替换THCCeilDiv(x,y)为(x+y-1)/y,完成以上操作之前我试了一下再次运行python setup.py build_ext --inplace观察是否为原本的THC问题,但是报出错误变成了IndexError: list index out of range,完成THC更改的操作后,运行同样出现了这个错误,使用了python setup.py clean命令再运行仍然报错,部分报错代码如下File "/home/mjh/anaconda3/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 1694, in _get_cuda_arch_flags
arch_list[-1] += '+PTX'
IndexError: list index out of range
麻烦作者大大了,感谢感谢

更换骨干网络

您好,我想请教一个问题,我已经将骨干网络替换成CSPDarket-53,但是不想下载初始权重文件,希望网络从0开始训练(对比试验的特殊需求),我应该修改backbone.py和train.py中的哪一部分呢,删除哪些类呢?望您在百忙之中给予指点,谢谢!

训练完成后如何使用

模型训练完成,但是没有找到可以输入空图片输出目标检测结果的.py文件,请问应该运行哪个文件

正式训练时报错

AssertionError: train: No labels in /media/mjh/F674A9D874A99BBD/DOTA/train/labels.cache. Can not train without labels. See https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data
正式训练时候报出上面这个错误,文件路径并没有错,查到一种解决方法是改变文件目录层级
#└─ mydata

├─ images

│ ├─ test # 下面放测试集图片

│ ├─ train # 下面放训练集图片

│ └─ val # 下面放验证集图片

└─ labels

├─ test # 下面放测试集标签

├─ train # 下面放训练集标签

├─ val # 下面放验证集标签

但是这个文件目录层级与README中不同,我试了一下报出了这个错误
Exception: train: Error loading data from /home/mjh/文档/DOTA/images/train : train: /home/mjh/文档/DOTA/images/train does not exist
See https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data
我参考这篇博客,修改了一下https://blog.csdn.net/weixin_46085845/article/details/127903878
运行过后报错为
File "/home/mjh/文档/S2ANet-main/utils/general.py", line 415, in check_dataset
raise Exception('Dataset not found.')
Exception: Dataset not found.
找不到数据集位置了,请问有什么解决方法吗

测试集检测图片后输出在哪设置

您好,请问在val.py中使用test模式,测试集文件路径如何设置呢,我多次尝试未能成功,检测图片后输出的图片路径如何设置呢?期待您的回复,谢谢!
2022-10-02 14-28-02屏幕截图
2022-10-02 14-28-16屏幕截图

训练时找不到标签

前面所有过程运行都没有问题了,运行train.py时出现这个错误
No labels in {cache_path}. Can not train without labels. See {HELP_URL}'
AssertionError: train: No labels in /home/mjh/图片/S2ANet/data/DOTA/train/labels.cache. Can not train without labels. See https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data
把labels.cache文件删除再来也还是不行,请问有什么办法吗

运行2(3)Compilate the C++Cuda Library时报错

models/orn/src/cuda/ActiveRotatingFilter_cuda.cu:5:10: fatal error: THC/THC.h: 没有那个文件或目录
5 | #include <THC/THC.h>
| ^~~~~~~~~~~
compilation terminated.
error: command '/usr/local/cuda/bin/nvcc' failed with exit code 1
我的配置是RTX3060,torch1.12.1+cu116

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.