--- comments: true --- # Rotated Object Detection Module Usage Tutorial ## I. Overview Rotated object detection is a derivative of the object detection module, specifically designed for detecting rotated objects. Rotated bounding boxes (Rotated Bounding Boxes) are commonly used for detecting rectangles with angle information, where the width and height of the rectangle are no longer parallel to the image coordinate axes. Compared to horizontal bounding boxes, rotated bounding boxes generally include less background information. Rotated box detection is often used in scenarios such as remote sensing. ## II. Supported Model List
ModelModel Download Link mAP(%) GPU Inference Time (ms) CPU Inference Time (ms) Model Storage Size (M) Introduction
PP-YOLOE-R-LInference Model/Training Model 78.14 20.7039 157.942 211.0 M PP-YOLOE-R is an efficient single-stage Anchor-free rotated box detection model. Based on PP-YOLOE, PP-YOLOE-R introduces a series of useful designs to improve detection accuracy with minimal parameters and computational cost.

Note: The above accuracy metrics are on the DOTA validation set mAP(0.5:0.95)。All model GPU inference times are based on an NVIDIA TRX2080 Ti machine, with precision type F16, and CPU inference speeds are based on an Intel(R) Xeon(R) Gold 5117 CPU @ 2.00GHz, with 8 threads and precision type FP32.

> ❗ The above listed are the rotated object detection models currently supported by paddleX,actually PaddleDetection supports10rotated object detection models, For a detailed model list, please refer to PaddleDetection ## III. Quick Integration > ❗ Before quick integration, please install the PaddleX wheel package. For details, please refer to [PaddleX Local Installation Tutorial](../../../installation/installation.en.md) After completing the installation of the wheel package, a few lines of code can complete the inference of the rotated object detection module. You can switch models under this module at will, and you can also integrate the model inference of the rotated object detection module into your project. Before running the following code, please download the [sample image](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/rotated_object_detection_001.png) to your local machine. ```python from paddlex import create_model model = create_model("PP-YOLOE-R-L") output = model.predict("rotated_object_detection_001.png", batch_size=1) for res in output: res.print(json_format=False) res.save_to_img("./output/") res.save_to_json("./output/res.json") ``` For more usage methods of the single model inference API in PaddleX, please refer to [PaddleX Single Model Python Script Usage Instructions](../../instructions/model_python_API.en.md). ## IV. Secondary Development If you are pursuing higher accuracy with existing models, you can use PaddleX's secondary development capabilities to develop better rotated object detection models. Before using PaddleX to develop rotated object detection models, please ensure that you have installed the model training plugins related to rotated object detection in PaddleX. The installation process can be referred to [PaddleX Local Installation Tutorial](../../../installation/installation.en.md) ### 4.1 Data Preparation Before model training, you need to prepare the dataset for the corresponding task module. PaddleX provides data verification functionality for each module, only data that passes the verification can be used for model training. Additionally, PaddleX provides a Demo dataset for each module, which you can use to complete subsequent development. If you wish to use a private dataset for subsequent model training, you can refer to [PaddleX Object Detection Task Module Data Annotation Tutorial](../../../data_annotations/cv_modules/object_detection.en.md). #### 4.1.1 Demo Data Download You can refer to the following command to download the Demo dataset to the specified folder: ```bash wget https://paddle-model-ecology.bj.bcebos.com/paddlex/data/rdet_dota_examples.tar -P ./dataset tar -xf ./dataset/rdet_dota_examples.tar -C ./dataset/ ``` After decompression, the dataset directory structure is as follows:: ```bash - dataset/DOTA-sampled200_crop1024_data - annotations - instance_train.json - instance_val.json - images - img1.png - img2.png - img3.png ... ``` #### 4.1.2 Data Verification A single command can complete data verification: ```bash python main.py -c paddlex/configs/rotated_object_detection/PP-YOLOE-R-L.yaml \ -o Global.mode=check_dataset \ -o Global.dataset_dir=./dataset/DOTA-sampled200_crop1024_data ``` After executing the above command, PaddleX will verify the dataset and count the basic information of the dataset. After the command runs successfully, the log will print `Check dataset passed !`. The verification result file is saved in `./output/check_dataset_result.json`, and the related outputs are saved in the`./output/check_dataset`directory under the current directory, including visualized sample images and sample distribution histograms.
👉 Verification Result Details (Click to Expand)

The specific content of the verification result file is:

{
  "done_flag": true,
  "check_pass": true,
  "attributes": {
    "num_classes": 15,
    "train_samples": 1892,
    "train_sample_paths": [
      "check_dataset\/demo_img\/P2610__1.0__0___0.png",
      "check_dataset\/demo_img\/P1137__1.0__0___0.png",
      "check_dataset\/demo_img\/P1122__1.0__5888___1648.png",
      "check_dataset\/demo_img\/P0543__1.0__0___0.png",
      "check_dataset\/demo_img\/P0518__1.0__0___91.png",
      "check_dataset\/demo_img\/P0961__1.0__1648___87.png",
      "check_dataset\/demo_img\/P1732__1.0__0___824.png",
      "check_dataset\/demo_img\/P2766__1.0__4421___0.png",
      "check_dataset\/demo_img\/P2582__1.0__674___725.png",
      "check_dataset\/demo_img\/P1529__1.0__2976___1648.png"
    ],
    "val_samples": 473,
    "val_sample_paths": [
      "check_dataset\/demo_img\/P2342__1.0__890___0.png",
      "check_dataset\/demo_img\/P1386__1.0__2472___1648.png",
      "check_dataset\/demo_img\/P0961__1.0__824___87.png",
      "check_dataset\/demo_img\/P1651__1.0__824___824.png",
      "check_dataset\/demo_img\/P1529__1.0__824___2976.png",
      "check_dataset\/demo_img\/P0961__1.0__4944___87.png",
      "check_dataset\/demo_img\/P0725__1.0__634___0.png",
      "check_dataset\/demo_img\/P1679__1.0__1648___1648.png",
      "check_dataset\/demo_img\/P2726__1.0__824___1578.png",
      "check_dataset\/demo_img\/P0457__1.0__379___0.png",
    ]
  },
  "analysis": {
    "histogram": "check_dataset/histogram.png"
  },
  "dataset_path": "./dataset/DOTA-sampled200_crop1024_data",
  "show_type": "image",
  "dataset_type": "COCODetDataset"
}

In the above verification result, check_pass is true, indicating that the dataset format meets the requirements. The explanations for other indicators are as follows:

Additionally, the dataset verification also analyzes the distribution of sample quantities for all categories in the dataset and draws a distribution histogram (histogram.png):

#### 4.1.3 Dataset Format Conversion/Dataset Splitting (Optional) After completing the data verification, you can convert the dataset format or re-split the training/validation ratio of the dataset by modifying the configuration file or adding hyperparameters.
👉 Format Conversion/Dataset Splitting Details (Click to Expand))

(1)Dataset Format Conversion

Rotated object detection does not support dataset format conversion, only standard DOTA COCO data format

(2)Dataset Splitting

The parameters for dataset splitting can be set by modifying the fields under CheckDataset in the configuration file. Some example explanations for the parameters in the configuration file are as follows:

......
CheckDataset:
  ......
  split:
    enable: True
    train_percent: 90
    val_percent: 10
  ......

Then execute the command:

python main.py -c paddlex/configs/rotated_object_detection/PP-YOLOE-R-L.yaml \
    -o Global.mode=check_dataset \
    -o Global.dataset_dir=./dataset/DOTA-sampled200_crop1024_data

After the dataset splitting is executed, the original annotation files will be renamed to xxx.bak.

The above parameters also support setting through adding command line parameters:

python main.py -c paddlex/configs/rotated_object_detection/PP-YOLOE-R-L.yaml \
    -o Global.mode=check_dataset \
    -o Global.dataset_dir=./dataset/DOTA-sampled200_crop1024_data \
    -o CheckDataset.split.enable=True \
    -o CheckDataset.split.train_percent=90 \
    -o CheckDataset.split.val_percent=10
### 4.2 Model Training A single command can complete model training, taking the training of the rotated object detection model `PP-YOLOE-R-L` as an example: ```bash python main.py -c paddlex/configs/rotated_object_detection/PP-YOLOE-R-L.yaml \ -o Global.mode=train \ -o Global.dataset_dir=./dataset/DOTA-sampled200_crop1024_data ``` The following steps are required: * Specify the path of the model's `.yaml` configuration file (here it is `PP-YOLOE-R-L.yaml`. When training other models, you need to specify the corresponding configuration file. The correspondence between models and configuration files can be found in [PaddleX Model List (CPU/GPU))](../../../support_list/models_list.en.md)) * Specify the mode as model training: `-o Global.mode=train` * Specify the training dataset path: `-o Global.dataset_dir` Other related parameters can be set by modifying the fields under Global and Train in the `.yaml` configuration file, or by adding parameters in the command line. For example, specify the first 2 GPU cards for training: `-o Global.device=gpu:0,1`; set the number of training epochs to 10: `-o Train.epochs_iters=10`. For more modifiable parameters and detailed explanations, please refer to the configuration file instructions for the corresponding task module [PaddleX Common Model Configuration File Parameter Instructions.](../../instructions/config_parameters_common.en.md).
👉 More Explanations (Click to Expand)
## 4.3 Model Evaluation After completing model training, you can evaluate the specified model weights file on the validation set to verify the model's accuracy. Using PaddleX for model evaluation can be done with a single command: ```bash python main.py -c paddlex/configs/rotated_object_detection/PP-YOLOE-R-L.yaml \ -o Global.mode=evaluate \ -o Global.dataset_dir=./dataset/DOTA-sampled200_crop1024_data ``` Similar to model training, the following steps are required: * Specify the `.yaml` configuration file path for the model (here it is `PP-YOLOE-R-L.yaml`) * Specify the mode as model evaluation: `-o Global.mode=evaluate` * Specify the path to the validation dataset: `-o Global.dataset_dir`. Other related parameters can be set by modifying the `Global` and `Evaluate` fields in the `.yaml` configuration file. For details, refer to [PaddleX Common Model Configuration File Parameter Description](../../instructions/config_parameters_common.en.md).
👉 More Details (Click to Expand)

When evaluating the model, you need to specify the model weights file path. Each configuration file has a default weight save path built-in. If you need to change it, simply set it by appending a command line parameter, such as -o Evaluate.weight_path=./output/best_model/best_model.pdparams.

After completing the model evaluation, an evaluate_result.json file will be generated, which records the evaluation results, specifically whether the evaluation task was completed successfully and the model's evaluation metrics, including AP.

### 4.4 Model Inference and Integration After completing model training and evaluation, you can use the trained model weights for inference predictions or Python integration. #### 4.4.1 Model Inference * To perform inference predictions through the command line, use the following command. Before running the following code, please download the [demo image](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/rotated_object_detection_001.png) to your local machine. ```bash python main.py -c paddlex/configs/rotated_object_detection/PP-YOLOE-R-L.yaml \ -o Global.mode=predict \ -o Predict.model_dir="./output/best_model/inference" \ -o Predict.input="rotated_object_detection_001.png" ``` Similar to model training and evaluation, the following steps are required: * Specify the `.yaml` configuration file path for the model (here it is `PP-YOLOE-R-L.yaml`) * Specify the mode as model inference prediction: `-o Global.mode=predict` * Specify the model weights path: `-o Predict.model_dir="./output/best_model/inference"` * Specify the input data path: `-o Predict.input="..."` Other related parameters can be set by modifying the `Global` and `Predict` fields in the `.yaml` configuration file. For details, refer to [PaddleX Common Model Configuration File Parameter Description](../../instructions/config_parameters_common.en.md). #### 4.4.2 Model Integration The model can be directly integrated into the PaddleX pipelines or directly into your own project. 2.Module Integration The weights you produce can be directly integrated into the object detection module. Refer to the Python example code in [Quick Integration](#iii-quick-integration), and simply replace the model with the path to your trained model.