yihong1120 / YOLOv8-PostProcessing-PRCurve

This repository contains code for post-processing techniques and PR curve visualization for object detection using YOLOv8. The project aims to improve object detection results through advanced post-processing methods and provides an analysis of precision and recall using PR curves.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

YOLOv8-PostProcessing-PRCurve

This repository contains code for post-processing techniques and PR curve visualization for object detection using YOLOv8. The project aims to improve object detection results through advanced post-processing methods and provides an analysis of precision and recall using PR curves.

The YOLOv8 model used in this project is sourced from the Ultralytics repository.

Contents

File Organisation

The repository is organised as follows:

YOLOv8-PostProcessing-PRCurve/
├── images/
│   ├── yolov8_postprocess.png
│   └── PR-curves.png
├── scripts/
│   ├── yolo_label_converter.py
│   ├── yolo_inference_and_postprocessing.py
│   ├── pr_curve_validation.py
│   └── run_scripts.sh
├── README.md
├── requirements.txt
├── y_preds.pkl
└── y_true.pkl
  • The 'images' folder contains images related to the project, such as the process flowchart ('yolov8_postprocess.png') and the PR curves ('PR-curves.png').

  • The 'scripts' folder contains the following Python scripts:

    • 'yolo_label_converter.py': Converts YOLOv8 labels to regular bounding box coordinates.
    • 'yolo_inference_and_postprocessing.py': Performs object detection and post-processing using YOLOv8.
    • 'pr_curve_validation.py': Calculates precision and recall values and plots PR curves.
    • 'run_scripts.sh': Bash script for running the necessary scripts in the correct order.
  • The 'README.md' file is the project's main documentation.

  • The 'requirements.txt' file lists the required dependencies for the project.

  • The 'y_preds.pkl' and 'y_true.pkl' files contain the predicted and ground truth bounding box data, respectively.

Installation

  1. Clone the repository:
git clone https://github.com/yihong1120/YOLOv8-PostProcessing-PRCurve.git
cd YOLOv8-PostProcessing-PRCurve
  1. Install the required dependencies:
pip install -r requirements.txt

Label Conversion

The 'yolo_label_converter.py' file provides functions to convert YOLOv8 coordinates to regular bounding box coordinates. It reads text files containing bounding box information and converts them to a pickle file for further processing.

To use the label converter, modify the 'folder_path' variable in the 'main()' function to point to the directory containing the label files. Then run the script:

python scripts/yolo_label_converter.py

The converted labels will be saved as 'y_true.pkl'.

Inference and Post-processing

The 'yolo_inference_and_postprocessing.py' file extends the YOLOv8 'detect/val.py' script. It performs object detection on images using a trained YOLOv8 model and applies post-processing techniques such as OCR and aspect ratio correction.

To use the inference and post-processing script, make sure to update the 'model' and 'source' variables in the 'predict()' function with the appropriate paths. Then run the script:

python scripts/yolo_inference_and_postprocessing.py

The predicted results will be saved as 'y_preds.pkl'. The process flowchart illustrating the post-processing steps in the 'yolo_inference_and_postprocessing.py' script is shown below:

here

The flowchart above illustrates the post-processing steps performed in the 'yolo_inference_and_postprocessing.py' script. It shows the sequence of operations, including OCR, aspect ratio correction, and other specific post-processing tasks.

PR Curve Validation

The 'pr_curve_validation.py' file calculates precision and recall values from the predicted and ground truth bounding boxes and plots PR curves for each class.

To validate the predicted results, make sure to have 'y_preds.pkl' and 'y_true.pkl' files in the repository. Then run the script:

python scripts/pr_curve_validation.py

The PR curves will be displayed in the console. A visualisation of the PR curves generated by 'pr_curve_validation.py' is shown below:

here

Feel free to explore and modify the code to suit your needs for post-processing and PR curve analysis in object detection using YOLOv8.

Run Scripts

To conveniently run the necessary scripts, you can use the run_scripts.sh file provided in this repository. This bash script automates the execution of the required scripts in the correct order.

To run the scripts, navigate to the repository directory and execute the following command:

bash scripts/run_scripts.sh

The script will run the following scripts in sequence:

  1. 'yolo_label_converter.py': Converts YOLOv8 labels to regular bounding box coordinates.
  2. 'yolo_inference_and_postprocessing.py': Performs object detection and post-processing using YOLOv8.
  3. 'pr_curve_validation.py': Calculates precision and recall values and plots PR curves. Make sure to have the necessary input files in the repository before running the scripts.

Feel free to explore and modify the code to suit your needs for post-processing and PR curve analysis in object detection using YOLOv8.

Generated Files

The following files will be generated during the execution of the scripts:

  • 'y_preds.pkl': Contains the predicted bounding box data.
  • 'y_true.pkl': Contains the ground truth bounding box data. Please ensure that the 'y_preds.pkl' and 'y_true.pkl' files are present in the repository for PR curve validation.

License

This project is licensed under the AGPL-3.0.

About

This repository contains code for post-processing techniques and PR curve visualization for object detection using YOLOv8. The project aims to improve object detection results through advanced post-processing methods and provides an analysis of precision and recall using PR curves.

License:GNU Affero General Public License v3.0


Languages

Language:Python 98.2%Language:Shell 1.8%