ultralytics / yolov5

YOLOv5 πŸš€ in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
51.26k stars 16.44k forks source link

How can I reproduce Precision-recall curve (PR_curve.png) #10107

Closed Vinicius-ufsc closed 2 years ago

Vinicius-ufsc commented 2 years ago

Search before asking

Question

I'm trying to reproduce the curves (PR) and the confusion matrix at max F1 score using the predictions from the model.

Those curves I'm referring are produced when I run:

python val.py --data Dataset.yaml --task test --weights best.pt --imgsz 320

To reproduce the curves I'm using the results.xyxyn of each image in test dataset (Dataset.yaml).

--getting a list of all predictions--

To get the predictions I'm using conf = 0.001 and IoU = 0.6, as it seems to be the default values ​​in val.py

model.conf = 0.001
model.iou = 0.6

cord_thres = []
for image_dir in image_dirs: # a list of image directories.
    image = cv.imread(image_dir)
    results = model(image, size = 320)
    cord_thres.append(*results.xyxyn)

-- default values of val.py--

@smart_inference_mode()
def run(
        date,
        weights=None, # model.pt path(s)
        batch_size=32, # batch size
        imgsz=640, # inference size (pixels)
        conf_thres=0.001, # confidence threshold
        iou_thres=0.6, # NMS IoU threshold

How can I reproduce those curves using the predictions?

I have tried with self made code to calculate P, R and PR curve, but can't get the same results

here what I have so far: https://github.com/Vinicius-ufsc/mean_average_precision

For the confusion matrix I have used the code from utils, still, I get different results.

Thank you.

github-actions[bot] commented 2 years ago

πŸ‘‹ Hello @Vinicius-ufsc, thank you for your interest in YOLOv5 πŸš€! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a πŸ› Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://ultralytics.com or email support@ultralytics.com.

Requirements

Python>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

YOLOv5 CI

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training, validation, inference, export and benchmarks on MacOS, Windows, and Ubuntu every 24 hours and on every commit.