This repository is based on Ultralytics/yolov5, with adjustments to enable rotate prediction boxes.

Overview

Rotate-Yolov5

This repository is based on Ultralytics/yolov5, with adjustments to enable rotate prediction boxes.

Section I. Description

The codes are based on Ultralytics/yolov5, and several functions are added and modified to enable rotate prediction boxes.

The modifications compared with Ultralytics/yolov5 and their brief descriptions are summarized below:

  1. data/rotate_ucas.yaml : Exemplar UCAS-AOD dataset to test the effects of rotate boxes

  2. data/images/UCAS-AOD : For the inference of rotate-yolov5s-ucas.pt

  3. models/common.py :
    3.1. class Rotate_NMS : Non-Maximum Suppression (NMS) module for Rotate Boxes
    3.2. class Rotate_AutoShape : Rotate Version of Original AutoShape, input-robust polygon model wrapper for passing cv2/np/PIL/torch inputs. Includes preprocessing, inference and Rotate_NMS
    3.3. class Rotate_Detections : Rotate detections class for Rotate-YOLOv5 inference results

  4. models/rotate_yolov5s_ucas.yaml : Configuration file of rotate yolov5s for exemplar UCAS-AOD dataset

  5. models/yolo.py :
    5.1. class Rotate_Detect : Detect head for rotate-yolov5 models with rotate box prediction
    5.2. class Rotate_Model : Rotate yolov5 models with rotate box prediction

  6. utils/iou_cuda : CUDA extension for iou computation of polygon boxes
    6.1. extensions.cpp : CUDA extension file
    6.2. inter_union_cuda.cu : CUDA code for computing iou of polygon boxes
    6.3. setup.py : for building CUDA extensions module polygon_inter_union_cuda, with two functions polygon_inter_union_cuda and polygon_b_inter_union_cuda

  7. utils/autoanchor.py :
    7.1. def rotate_check_anchors : Rotate version of original check_anchors
    7.2. def rotate_kmean_anchors : Create kmeans-evolved anchors from rotate-enabled training dataset

  8. utils/datasets.py :
    8.1. def polygon_random_perspective : Data augmentation for datasets with polygon boxes (augmentation effects: HSV-Hue, HSV-Saturation, HSV-Value, rotation, translation, scale, shear, perspective, flip up-down, flip left-right, mosaic, mixup)
    8.2. def polygon_box_candidates : Polygon version of original box_candidates
    8.3. def rotate_random_perspective : Data augmentation for datasets with rotate boxes (augmentation effects: HSV-Hue, HSV-Saturation, HSV-Value, rotation, translation, scale, shear, perspective, flip up-down, flip left-right, mosaic, mixup)
    8.4. class Rotate_LoadImagesAndLabels : Rotate version of original LoadImagesAndLabels
    8.5. def rotate_load_mosaic : Loads images in a 4-mosaic, with rotate boxes
    8.6. def rotate_load_mosaic9 : Loads images in a 9-mosaic, with rotate boxes
    8.7. def rotate_verify_image_label : Verify one image-label pair for rotate datasets
    8.8. def create_dataloader : Has been modified to include rotate datasets
    8.9. class Albumentations : For albumentation augmentation

  9. utils/general.py :
    9.1. def xyxyxyxyn2xyxyxyxy : Convert normalized xyxyxyxy or segments into pixel xyxyxyxy or segments
    9.2. def polygon_segment2box : Convert 1 segment label to 1 polygon box label
    9.3. def polygon_inter_union_cpu : iou computation (polygon) with cpu
    9.4. def polygon_box_iou : Compute iou of polygon boxes via cpu or cuda
    9.5. def polygon_b_inter_union_cpu : iou computation (polygon) with cpu
    9.6. def polygon_bbox_iou : Compute iou of polygon boxes via cpu or cuda
    9.7. def polygon_nms_kernel : Non maximum suppression kernel for polygon-enabled boxes
    9.8. def order_corners : Return sorted corners
    9.9. def xywhrm2xyxyxyxy : Convert rotate xywhrm into xyxyxyxy, suitable for both pixel-level or normalized
    9.10. def xyxyxyxy2xywhrm : Convert xyxyxyxy into rotate xywhrm, suitable for both pixel-level and normalized
    9.11. def xywhn2xywh : Convert normalized xywh into pixel xywh
    9.12. def rotate_segments2boxes : Convert segment labels to rotate box labels, i.e. (xy1, xy2, ...) to rotated boxes (x, y, w, h, re, im)
    9.13. def rotate_scale_coords : Rescale coords (x, y, w, h, re, im) from img1_shape to img0_shape
    9.14. def rotate_box_iou : Compute iou of rotate boxes via cpu or cuda
    9.15. def rotate_bbox_iou : Compute iou of rotated boxes for class Rotate_ComputeLoss in loss.py via cpu or cuda
    9.16. def rotate_non_max_suppression : Runs Non-Maximum Suppression (NMS) on inference results for rotated boxes

  10. utils/loss.py :
    10.1. class Rotate_ComputeLoss : Compute loss for rotate boxes

  11. utils/metrics.py :
    11.1. class Rotate_ConfusionMatrix : Rotate version of original ConfusionMatrix

  12. utils/plots.py :
    12.1. def polygon_plot_one_box : Plot one polygon box on image
    12.2. def polygon_plot_one_box_PIL : Plot one polygon box on image via PIL
    12.3. def polygon_plot_images : Polygon version of original plot_images
    12.4. def rotate_plot_one_box : Plot one rotate box on image
    12.5. def rotate_plot_one_box_PIL : Plot one rotate box on image via PIL
    12.6. def rotate_output_to_target : Convert model output format [x, y, w, h, re, im, conf, class_id] to target format [batch_id, class_id, x, y, w, h, re, im, conf]
    12.7. def rotate_plot_images : Rotate version of original plot_images
    12.8. def rotate_plot_test_txt : Rotate version of original plot_test_txt
    12.9. def rotate_plot_targets_txt : Rotate version of original plot_targets_txt
    12.10. def rotate_plot_labels : Rotate version of original plot_labels

  13. rotate_train.py : For training rotate-yolov5 models

  14. rotate_test.py : For testing rotate-yolov5 models

  15. rotate_detect.py : For detecting rotate-yolov5 models

  16. requirements.py : Added python model shapely

Section II. How Does Rotate Boxes Work? How Does Rotate Boxes Different from Polygon Boxes?

  1. Comparisons between Rotate-Yolov5 and Polygon-Yolov5

2. Model Head of Rotate-Yolov5

3. Illustration of Box Loss of Rotated Boxes

Section III. Installation

For the CUDA extension to be successfully built without error, please use CUDA version >= 11.2. The codes have been verified in Ubuntu 16.04 with Tesla K80 GPU.

# The following codes install CUDA 11.2 from scratch on Ubuntu 16.04, if you have installed it, please ignore
# If you are using other versions of systems, please check https://tutorialforlinux.com/2019/12/01/how-to-add-cuda-repository-for-ubuntu-based-oses-2/
# Install Ubuntu kernel head
sudo apt install linux-headers-$(uname -r)

# Pinning CUDA repo wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-ubuntu1604.pin sudo mv cuda-ubuntu1604.pin /etc/apt/preferences.d/cuda-repository-pin-600
# Add CUDA GPG key sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
# Setting up CUDA repo sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/ /"
# Refresh apt repositories sudo apt update
# Installing CUDA 11.2 sudo apt install cuda-11-2 -y sudo apt install cuda-toolkit-11-2 -y
# Setting up path echo 'export PATH=/usr/local/cuda-11.2/bin${PATH:+:${PATH}}' >> $HOME/.bashrc # You are done installing CUDA 11.2
# Check NVIDIA nvidia-smi # Update all apts sudo apt-get update sudo apt-get -y upgrade
# Begin installing python 3.7 curl -o ~/miniconda.sh -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh chmod +x ~/miniconda.sh ./miniconda.sh -b echo "PATH=~/miniconda3/bin:$PATH" >> ~/.bashrc source ~/.bashrc conda install -y python=3.7 # You are done installing python

The following codes set you up with the Rotate Yolov5.

# clone git repo
git clone https://github.com/XinzeLee/RotateObjectDetection
cd RotateObjectDetection/rotate-yolov5
# install python package requirements
pip install -r requirements.txt
# install CUDA extensions
cd utils/iou_cuda
python setup.py install
# cd back to rotate-yolov5 folder
cd .. && cd ..

Section IV. Rotate-Tutorial 1: Deploy the Rotate Yolov5s

Try Rotate Yolov5s Model by Following Rotate-Tutorial 1

  1. Inference
     $ python rotate_detect.py --weights rotate-yolov5s-ucas.pt --img 1024 --conf 0.75 \
         --source data/images/UCAS-AOD --iou-thres 0.4 --hide-labels

  2. Test
     $ python rotate_test.py --weights rotate-yolov5s-ucas.pt --data rotate_ucas.yaml \
         --img 1024 --iou 0.65 --task val

  3. Train
     $ python rotate_train.py --weights rotate-yolov5s-ucas.pt --cfg rotate_yolov5s_ucas.yaml \
         --data rotate_ucas.yaml --hyp hyp.ucas.yaml --img-size 1024 \
         --epochs 3 --batch-size 12 --noautoanchor --rotate --cache
  4. Performance
    4.1. Confusion Matrix

    4.2. Precision Curve

    4.3. Recall Curve

    4.4. Precision-Recall Curve

    4.5. F1 Curve

Section V. Rotate-Tutorial 2: Transform COCO Dataset to Rotate Labels Using Segmentation

Transform COCO Dataset to Rotate Labels by Following Rotate-Tutorial 2

Transformed Exemplar Figure

Section VI. References

Comments
  • IndexError: index 6 is out of bounds for dimension 1 with size 6I

    IndexError: index 6 is out of bounds for dimension 1 with size 6I

    I have modified my label into the format (class, cx, cy, w, h, cos, sin),and I sucessfully train UCAS-AOD you provided, but I meet this problem when I train my own dataset. my label is as follows: 0 1244.5523 399.0501 86.4318 225.7462 0.3616157183568731 0.9323272345251117 image

    Traceback (most recent call last): File "rotate_train.py", line 553, in train(hyp, opt, device, tb_writer, rotate=opt.rotate) File "rotate_train.py", line 103, in train model = Model(opt.cfg, ch=3, nc=nc, anchors=hyp.get('anchors')).to(device) # create File "/home/cdzk/LanXin/R-yolov5/rotate-yolov5/models/yolo.py", line 341, in init super(Rotate_Model, self).init(cfg, ch, nc, anchors) File "/home/cdzk/LanXin/R-yolov5/rotate-yolov5/models/yolo.py", line 110, in init self._initialize_biases() # only run once File "/home/cdzk/LanXin/R-yolov5/rotate-yolov5/models/yolo.py", line 366, in _initialize_biases b.data[:, 6] += math.log(8 / (640 / s) ** 2) # obj (8 objects per 640 image) IndexError: index 6 is out of bounds for dimension 1 with size 6

    image

    could you know what can I do to revise this ? Thank you for your help!

    opened by AllieLan 3
  • polygon_nms_kernel use exclusive nested for loop?

    polygon_nms_kernel use exclusive nested for loop?

    Hello, First I want to say Thank you for the effort. I have my own dataset and I labeled it as you mentioned, I trained it on a CPU I haven't tried using GPU yet. In the training set it finished the first epoch without any issue but when it started to calculate the mAP it got lost in the polygon_nms_kernel in general.py specific on the while loop at the 934. line In some way I ended up having x_.shape like (16939,10) and inside the loop, there is a polygon_box_iou that contains polygon_inter_union_cpu which is itself a 16939 lens. So my dummy question is, Is it normal to have that much of an exclusive computation 16939*16939 = 286M iteration. just to calculate the mAP and do nms?

    opened by muhammedakyuzlu 2
  • Inference not working

    Inference not working

    Hey @XinzeLee, Tutorial-1 colab does not detect bounding boxes.

    Steps to reproduce:

    1. !git clone https://github.com/XinzeLee/RotateObjectDetection
    2. %cd /content/RotateObjectDetection/rotate-yolov5
    3. !pip install -r requirements.txt
    4. %cd /content/RotateObjectDetection/rotate-yolov5/utils/iou_cuda
    5. !python setup.py install
    6. %cd /content/RotateObjectDetection/rotate-yolov5
    7. Below code
    from IPython.display import Image
    
    !python rotate_detect.py --weights rotate-yolov5s-ucas.pt --img 1024 --conf 0.75 \
        --source data/images/UCAS-AOD --iou-thres 0.4 --hide-labels
    # Image(filename='runs/detect/exp/1070.png', width=1024)
    
    1. Check out images under runs/detect/exp
    opened by satpalsr 1
  • Allowing full rotation [-180, 180]

    Allowing full rotation [-180, 180]

    Thank you for sharing your work. I've been trying to solve a rotated object detection problem, but in my case I want to predict full rotation or θ [-180, 180] degrees. For example, it matters if the object is pointing up or down.

    Would allowing the cos output to have values from [-1,1] (tanh activation in both model and loss) achieve this? Do you have any suggestion on this? I am looking forward to your input!

    opened by gzamps 0
  • I encountered 'Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!' when I train my own data

    I encountered 'Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!' when I train my own data

    Traceback (most recent call last): File "rotate_train.py", line 553, in train(hyp, opt, device, tb_writer, rotate=opt.rotate) File "rotate_train.py", line 314, in train loss, loss_items = compute_loss(pred, targets.to(device)) # loss scaled by batch_size File "/root/yolo/RotateObjectDetection-main/rotate-yolov5/utils/loss.py", line 269, in call iou = rotate_bbox_iou(pbox, tbox[i], CIoU=True, device=device) # iou(prediction, target) File "/root/yolo/RotateObjectDetection-main/rotate-yolov5/utils/general.py", line 1072, in rotate_bbox_iou return polygon_bbox_iou(boxes1_xyxyxyxy, boxes2_xyxyxyxy, GIoU, DIoU, CIoU, eps, device) # IoU File "/root/yolo/RotateObjectDetection-main/rotate-yolov5/utils/general.py", line 907, in polygon_bbox_iou alpha = v / (v - iou + (1 + eps)) RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!

    opened by Zivid99 1
  • cuda extension build on Windows fails

    cuda extension build on Windows fails

    I get a ton of errors running the iou_cuda setup script. I have visual studio 2019, and cuda 11.2. Did anyone have success compiling this on windows?

    Just the last part of the errors include:

    C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\include\sm_32_intrinsics.hpp(123): error: asm operand type size(8) does not match type/size implied by constraint 'r'

    C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\include\sm_32_intrinsics.hpp(124): error: asm operand type size(8) does not match type/size implied by constraint 'r'

    Error limit reached. 100 errors detected in the compilation of "/RotateObjectDetection-main/rotate-yolov5/utils/iou_cuda/inter_union_cuda.cu". Compilation terminated.

    opened by sequoiagrove 1
  •     raise EnvironmentError('CUDA_HOME environment variable is not set. ' OSError: CUDA_HOME environment variable is not set. Please set it to your CUDA install root.

    raise EnvironmentError('CUDA_HOME environment variable is not set. ' OSError: CUDA_HOME environment variable is not set. Please set it to your CUDA install root.

    when I run setup.py, I encounter this problem Traceback (most recent call last): File "setup.py", line 20, in <module> '-gencode=arch=compute_75,code=sm_75', '-gencode=arch=compute_80,code=sm_80', File "D:\anaconda_location\envs\zivid_py37\lib\site-packages\torch\utils\cpp_extension.py", line 800, in CUDAExtension library_dirs += library_paths(cuda=True) File "D:\anaconda_location\envs\zivid_py37\lib\site-packages\torch\utils\cpp_extension.py", line 899, in library_paths paths.append(_join_cuda_home(lib_dir)) File "D:\anaconda_location\envs\zivid_py37\lib\site-packages\torch\utils\cpp_extension.py", line 1827, in _join_cuda_home raise EnvironmentError('CUDA_HOME environment variable is not set. ' OSError: CUDA_HOME environment variable is not set. Please set it to your CUDA install root.

    By the way, I build my project in win10, no GPU, only with cuda 11.2.162 driver and my torch vision is 1.7.1+cu101 in anaconda.

    opened by Zivid99 0
  • Same no of training labels predicted

    Same no of training labels predicted

    Hey @XinzeLee, I followed Rotate-tutorial 1 colab to train the model for 100 epochs but I observe the same low number of labels predicted at each epoch: image

    I have also tried it for my custom dataset & a similar problem persists. What are your thoughts on it? image

    opened by satpalsr 0
  •  CUDA error: no kernel image is available at polygon_b_inter_union_cuda

    CUDA error: no kernel image is available at polygon_b_inter_union_cuda

    Hi, thanks for you great work. I managed to train my custom dataset,, but the inclusion of the function 'polygon_b_inter_union_cuda' is problematic. The error thrown is: File "/usr/local/etc/rotate-yolov5/utils/general.py", line 890, in polygon_bbox_iou union += eps RuntimeError: CUDA error: no kernel image is available for execution on the device CUDA is installed and available. If I use the CPU-version 'polygon_b_inter_union_cpu' everything works flawlessly, but the training is very slow. Do you know what the problem might be? I use python 3.7.10, torch 1.10.0, cuda 11.3 on ubuntu 18.04

    opened by UeFrog 0
Releases(v1.0)
Owner
xinzelee
xinzelee
Transfer SemanticKITTI labeles into other dataset/sensor formats.

LiDAR-Transfer Transfer SemanticKITTI labeles into other dataset/sensor formats. Content Convert datasets (NUSCENES, FORD, NCLT) to KITTI format Minim

Photogrammetry & Robotics Bonn 64 Nov 21, 2022
3D dataset of humans Manipulating Objects in-the-Wild (MOW)

MOW dataset [Website] This repository maintains our 3D dataset of humans Manipulating Objects in-the-Wild (MOW). The dataset contains 512 images in th

Zhe Cao 28 Nov 06, 2022
Create and implement a deep learning library from scratch.

In this project, we create and implement a deep learning library from scratch. Table of Contents Deep Leaning Library Table of Contents About The Proj

Rishabh Bali 22 Aug 23, 2022
An implementation of "Optimal Textures: Fast and Robust Texture Synthesis and Style Transfer through Optimal Transport"

Optex An implementation of Optimal Textures: Fast and Robust Texture Synthesis and Style Transfer through Optimal Transport for TU Delft CS4240. You c

Hans Brouwer 33 Jan 05, 2023
A fast Protein Chain / Ligand Extractor and organizer.

Are you tired of using visualization software, or full blown suites just to separate protein chains / ligands ? Are you tired of organizing the mess o

Amine Abdz 9 Nov 06, 2022
Assessing the Influence of Models on the Performance of Reinforcement Learning Algorithms applied on Continuous Control Tasks

Assessing the Influence of Models on the Performance of Reinforcement Learning Algorithms applied on Continuous Control Tasks This is the master thesi

Giacomo Arcieri 1 Mar 21, 2022
WaveFake: A Data Set to Facilitate Audio DeepFake Detection

WaveFake: A Data Set to Facilitate Audio DeepFake Detection This is the code repository for our NeurIPS 2021 (Track on Datasets and Benchmarks) paper

Chair for Sys­tems Se­cu­ri­ty 27 Dec 22, 2022
PyTorch Implementation of CycleGAN and SSGAN for Domain Transfer (Minimal)

MNIST-to-SVHN and SVHN-to-MNIST PyTorch Implementation of CycleGAN and Semi-Supervised GAN for Domain Transfer. Prerequites Python 3.5 PyTorch 0.1.12

Yunjey Choi 401 Dec 30, 2022
PointPillars inference with TensorRT

A project demonstrating how to use CUDA-PointPillars to deal with cloud points data from lidar.

NVIDIA AI IOT 315 Dec 31, 2022
Official Pytorch Implementation of Adversarial Instance Augmentation for Building Change Detection in Remote Sensing Images.

IAug_CDNet Official Implementation of Adversarial Instance Augmentation for Building Change Detection in Remote Sensing Images. Overview We propose a

53 Dec 02, 2022
Repository containing the PhD Thesis "Formal Verification of Deep Reinforcement Learning Agents"

Getting Started This repository contains the code used for the following publications: Probabilistic Guarantees for Safe Deep Reinforcement Learning (

Edoardo Bacci 5 Aug 31, 2022
Multiwavelets-based operator model

Multiwavelet model for Operator maps Gaurav Gupta, Xiongye Xiao, and Paul Bogdan Multiwavelet-based Operator Learning for Differential Equations In Ne

Gaurav 33 Dec 04, 2022
Pseudo-mask Matters in Weakly-supervised Semantic Segmentation

Pseudo-mask Matters in Weakly-supervised Semantic Segmentation By Yi Li, Zhanghui Kuang, Liyang Liu, Yimin Chen, Wayne Zhang SenseTime, Tsinghua Unive

33 Oct 14, 2022
Single/multi view image(s) to voxel reconstruction using a recurrent neural network

3D-R2N2: 3D Recurrent Reconstruction Neural Network This repository contains the source codes for the paper Choy et al., 3D-R2N2: A Unified Approach f

Chris Choy 1.2k Dec 27, 2022
This repository contains the code for the paper ``Identifiable VAEs via Sparse Decoding''.

Sparse VAE This repository contains the code for the paper ``Identifiable VAEs via Sparse Decoding''. Data Sources The datasets used in this paper wer

Gemma Moran 17 Dec 12, 2022
A tensorflow implementation of GCN-LPA

GCN-LPA This repository is the implementation of GCN-LPA (arXiv): Unifying Graph Convolutional Neural Networks and Label Propagation Hongwei Wang, Jur

Hongwei Wang 83 Nov 28, 2022
Wikidated : An Evolving Knowledge Graph Dataset of Wikidata’s Revision History

Wikidated Wikidated 1.0 is a dataset of Wikidata’s full revision history, which encodes changes between Wikidata revisions as sets of deletions and ad

Lukas Schmelzeisen 11 Aug 16, 2022
Simulator for FRC 2022 challenge: Rapid React

rrsim Simulator for FRC 2022 challenge: Rapid React out-1.mp4 Usage In order to run the simulator use the following: python3 rrsim.py [config_path] wh

1 Jan 18, 2022
Simple STAC Catalogs discovery tool.

STAC Catalog Discovery Simple STAC discovery tool. Just paste the STAC Catalog link and press Enter. Details STAC Discovery tool enables discovering d

Mykola Kozyr 21 Oct 19, 2022
Reinforcement learning models in ViZDoom environment

DoomNet DoomNet is a ViZDoom agent trained by reinforcement learning. The agent is a neural network that outputs a probability of actions given only p

Andrey Kolishchak 126 Dec 09, 2022