{"id":13644276,"url":"https://github.com/yingkunwu/R-YOLOv4","last_synced_at":"2025-04-21T07:30:55.628Z","repository":{"id":37625391,"uuid":"346688506","full_name":"yingkunwu/R-YOLOv4","owner":"yingkunwu","description":"This is a PyTorch-based R-YOLOv4 implementation which combines YOLOv4 model and loss function from R3Det for arbitrary oriented object detection.","archived":false,"fork":false,"pushed_at":"2024-01-10T22:01:16.000Z","size":43721,"stargazers_count":113,"open_issues_count":3,"forks_count":19,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-05-22T07:52:18.250Z","etag":null,"topics":["oriented-object-detection","pytorch","yolov4"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yingkunwu.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-03-11T12:05:25.000Z","updated_at":"2024-05-20T10:55:29.000Z","dependencies_parsed_at":"2024-02-28T09:46:52.566Z","dependency_job_id":null,"html_url":"https://github.com/yingkunwu/R-YOLOv4","commit_stats":null,"previous_names":["yingkunwu/r-yolov4","kunnnnethan/r-yolov4"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yingkunwu%2FR-YOLOv4","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yingkunwu%2FR-YOLOv4/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yingkunwu%2FR-YOLOv4/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yingkunwu%2FR-YOLOv4/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yingkunwu","download_url":"https://codeload.github.com/yingkunwu/R-YOLOv4/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223779677,"owners_count":17201287,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["oriented-object-detection","pytorch","yolov4"],"created_at":"2024-08-02T01:02:00.359Z","updated_at":"2024-11-09T16:32:09.712Z","avatar_url":"https://github.com/yingkunwu.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# R-YOLOv4\n\n### Introduction\nThe objective of this project is to adapt YOLOv4 model to detecting oriented objects. As a result, modifying the original loss function of the model is required. I got a successful result by increasing the number of anchor boxes with different rotating angle and combining smooth-L1-IoU loss function proposed by [R3Det: Refined Single-Stage Detector with Feature Refinement for Rotating Object](https://arxiv.org/abs/1908.05612) into the original loss for bounding boxes.\n\n\n### Features\n\n---\n#### Loss Function (only for x, y, w, h, theta)\n\n\u003cimg src=\"https://i.imgur.com/zdA9RJj.png\" alt=\"loss\" height=\"90\"/\u003e\n\u003cimg src=\"https://i.imgur.com/Qi1XFXS.png\" alt=\"angle\" height=\"70\"/\u003e\n\n---\n\n#### **\\*UPDATE***\nThe followings are updated to the code to improve the performance of the original setting.\n* Circular Smooth Labeling\n* KFIoU\n* Yolov5\n* Yolov7\n\n### Setup\n\n1. Clone repository\n    ```\n    $ git clone https://github.com/kunnnnethan/R-YOLOv4.git\n    $ cd R-YOLOv4/\n    ```\n2. Create Environment\n\n* Conda\n    \n    1. Create virual environment\n        ```\n        $ conda create -n ryolo python=3.8\n        $ conda activate ryolo\n        ```\n    2. Install PyTorch and torchvision following the [official instructions](https://pytorch.org), e.g.,\n        ```\n        If you are using CUDA 11.8 version\n        $ conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia\n        ```\n    3. Install required libraries\n        ```\n        $ pip install -r requirements.txt\n        ```\n    4. Install detectron2 for calculating SkewIoU on GPU following the [official instructions](https://detectron2.readthedocs.io/en/latest/tutorials/install.html), e.g.,\n        ```\n        python -m pip install 'git+https://github.com/facebookresearch/detectron2.git'\n        ```\n        \n* Docker\n\n    ```\n    $ docker build -t ryolo docker/\n    $ sudo docker run -it --rm --gpus all --ipc=host --ulimit memlock=-1 -v ${your_path}:/workspace ryolo\n    ```\n\n6. Download  pretrained weights\u003c/br\u003e\n    [weights](https://drive.google.com/drive/folders/1PkVYTTN9YlToM3ZbNsUKbAs6RDwh94am?usp=share_link)\n    \n7. Make sure your files arrangment looks like the following\u003c/br\u003e\n    Note that each of your dataset folder in `data` should split into three files, namely `train`, `test`, and `detect`.\n    ```\n    R-YOLOv4/\n    ├── train.py\n    ├── test.py\n    ├── detect.py\n    ├── xml2txt.py\n    ├── environment.xml\n    ├── requirements.txt\n    ├── model/\n    ├── datasets/\n    ├── lib/\n    ├── outputs/\n    ├── weights/\n        ├── pretrained/ (for training)\n        └── UCAS-AOD/ (for testing and detection)\n    └── data/\n        └── UCAS-AOD/\n            ├── class.names\n            ├── train/\n                ├── ...png\n                └── ...txt\n            ├── test/\n                ├── ...png\n                └── ...txt\n            └── detect/\n                └── ...png\n    ```\n    \n### Train\n\nI have implemented methods to load and train three different datasets. They are UCAS-AOD, DOTA, and custom dataset respectively. You can check out how I loaded those dataset into the model at [/datasets](https://github.com/kunnnnethan/R-YOLOv4/tree/main/datasets). The angle of each bounding box is limited in `(- pi/2,  pi/2]`, and the height of each bounding box is always longer than it's width.\n\nCheck all the setting in .yaml files that you are going to use in the [/data](https://github.com/kunnnnethan/R-YOLOv4/tree/main/data) folder.\n\n```\n$ python train.py --model_name DOTA_yolov7_csl_800 --config data/hyp.yaml --img_size 800 --data data/DOTA.yaml --epochs 100 --mode csl --ver yolov7\n```\n\nYou can run [display_inputs.py](https://github.com/kunnnnethan/R-YOLOv4/blob/main/display_inputs.py) to visualize whether your data is loaded successfully.\n\n#### UCAS-AOD dataset\n\nPlease refer to [this repository](https://github.com/kunnnnethan/UCAS-AOD-benchmark) to rearrange files so that it can be loaded and trained by this model.\u003c/br\u003e\n\n\n#### DOTA dataset\n\nDownload the official dataset from [here](https://captain-whu.github.io/DOTA/dataset.html). The original files should be able to be loaded and trained by this model.\u003c/br\u003e\n\n#### Train with custom dataset\n1. Use [labelImg2](https://github.com/chinakook/labelImg2) to help label your data. labelImg2 is capable of labeling rotated objects.\n2. Move your data folder into the `R-YOLOv4/data` folder.\n3. Run xml2txt.py\n    1. generate txt files:\n    ```python xml2txt.py --data_folder your-path --action gen_txt```\n    2. delete xml files:\n    ```python xml2txt.py --data_folder your-path --action del_xml```\n\nA [trash](https://drive.google.com/uc?export=download\u0026id=1YBDtCoRXEVkPQUUcfoChWKq8WVzm7IF-) custom dataset that I made are provided for your convenience.\n\n### Test\n```\n$ python test.py --data data/DOTA.yaml --hyp data/hyp.yaml --weight_path weights/DOTA_yolov7_csl_800/best.pth --batch_size 8 --img_size 800 --mode csl --ver yolov7\n```\n\n### detect\n\n```\n$ python detect.py --data data/UCAS_AOD.yaml --hyp data/hyp.yaml --weight_path weights/DOTA_yolov7_csl_800/best.pth --batch_size 8 --img_size 800 --conf_thres 0.3 --mode csl --ver yolov7\n```\n\n#### Tensorboard\nIf you would like to use tensorboard for tracking traing process.\n\n* Open additional terminal in the same folder where you are running program.\n* Run command ```$ tensorboard --logdir=weights --port=6006``` \n* Go to [http://localhost:6006/]( http://localhost:6006/)\n\n### Results\n\n#### UCAS_AOD\n\n\u003cimg src=\"https://github.com/kunnnnethan/R-YOLOv4/blob/main/outputs/UCAS_AOD/P0292.png\" alt=\"car\" height=\"430\"/\u003e\n\u003cimg src=\"https://github.com/kunnnnethan/R-YOLOv4/blob/main/outputs/UCAS_AOD/P0769.png\" alt=\"plane\" height=\"413\"/\u003e\n\n#### DOTA\n\n\u003cimg src=\"https://github.com/kunnnnethan/R-YOLOv4/blob/main/outputs/DOTA/P0006.png\" alt=\"DOTA\" height=\"430\"/\u003e\u003cimg src=\"https://github.com/kunnnnethan/R-YOLOv4/blob/main/outputs/DOTA/P0031.png\" alt=\"DOTA\" height=\"430\"/\u003e\n\n#### trash (custom dataset)\n\n\n\u003cimg src=\"https://github.com/kunnnnethan/R-YOLOv4/blob/main/outputs/trash/480.jpg\" alt=\"garbage1\" height=\"410\"/\u003e\n\u003cimg src=\"https://github.com/kunnnnethan/R-YOLOv4/blob/main/outputs/trash/540.jpg\" alt=\"garbage2\" height=\"410\"/\u003e\n\n\n### References\n\n[WongKinYiu/yolov7](https://github.com/WongKinYiu/yolov7/tree/main)\u003c/br\u003e\n[ultralytics/yolov5](https://github.com/ultralytics/yolov5/tree/master/utils)\u003c/br\u003e\n[Tianxiaomo/pytorch-YOLOv4](https://github.com/Tianxiaomo/pytorch-YOLOv4)\u003c/br\u003e\n[yangxue0827/RotationDetection](https://github.com/yangxue0827/RotationDetection)\u003c/br\u003e\n[eriklindernoren/PyTorch-YOLOv3](https://github.com/eriklindernoren/PyTorch-YOLOv3)\u003c/br\u003e\n\n**YOLOv4: Optimal Speed and Accuracy of Object Detection**\n\n```\n@article{yolov4,\n  title={YOLOv4: Optimal Speed and Accuracy of Object Detection},\n  author={Alexey Bochkovskiy, Chien-Yao Wang, Hong-Yuan Mark Liao},\n  journal = {arXiv},\n  year={2020}\n}\n```\n\n**R3Det: Refined Single-Stage Detector with Feature Refinement for Rotating Object**\n\n```\n@article{r3det,\n  title={R3Det: Refined Single-Stage Detector with Feature Refinement for Rotating Object},\n  author={Xue Yang, Junchi Yan, Ziming Feng, Tao He},\n  journal = {arXiv},\n  year={2019}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyingkunwu%2FR-YOLOv4","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyingkunwu%2FR-YOLOv4","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyingkunwu%2FR-YOLOv4/lists"}