Skip to content

Confusion Matrix with weird scale #6626

Closed

Description

@llucasreis

Search before asking

Question

Hello!

I executed the val.py command, and received the following results:

image

And when I checked my Confusion Matrix, it's showing some weird results and a weird scale:

image

I don't get it why TP is 1.0 and FP is 1.0, can someone help me how can I interpret these results? And somehow fix the scale?

I tried to use conf_thres=0.25 and iou_thres=0.45 to see if my val.py results matches somehow the TP, since it's informed here (#1665) as the default values for Confusion Matrix.

Additional

FYI: my class is ALL (Acute Lymphoblastic Leukemia) 😅

Activity

  1. github-actions commented on Feb 12, 2022

    @github-actions
    Contributor

    👋 Hello @llucasreis, 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

    CI CPU testing

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

  2. llucasreis commented on Feb 12, 2022

    @llucasreis
    Author

    Ok apparently my Confusion Matrix is right, I checked all predicted images and my model doesn't predicted FNs, only FPs, and since I have only one class, everything went to background FP 🤔

    So I think I only have the problem with the scale in Confusion Matrix now

  3. changed the title [-]Confusion Matrix with weird ticklabels [/-] [+]Confusion Matrix with weird scale[/+] on Feb 13, 2022
  4. llucasreis commented on Feb 13, 2022

    @llucasreis
    Author

    This code reproduces this behavior:

    import seaborn as sn
    import matplotlib.pyplot as plt
    import numpy as np
    import warnings
    
    matrix = np.array([[112, 34], [0,0]])
    
    normalize = True
    
    array = matrix / ((matrix.sum(0).reshape(1, -1) + 1E-6) if normalize else 1)  # normalize columns
    array[array < 0.005] = np.nan  # don't annotate (would appear as 0.00)
    
    names = ['ALL']
    nc = 1
    
    fig = plt.figure(figsize=(12, 9), tight_layout=True)
    sn.set(font_scale=1.0 if nc < 50 else 0.8)  # for label size
    labels = (0 < len(names) < 99) and len(names) == nc  # apply names to ticklabels
    
    with warnings.catch_warnings():
        warnings.simplefilter('ignore')  # suppress empty matrix RuntimeWarning: All-NaN slice encountered
        sn.heatmap(array, annot=nc < 30, annot_kws={"size": 8}, cmap='Blues', fmt='.2f', square=True,
                    xticklabels=names + ['background FP'] if labels else "auto",
                    yticklabels=names + ['background FN'] if labels else "auto").set_facecolor((1, 1, 1))
    fig.axes[0].set_xlabel('True')
    fig.axes[0].set_ylabel('Predicted')
    fig.savefig('confusion_matrix.png', dpi=250)
    plt.close()
  5. glenn-jocher commented on Feb 14, 2022

    @glenn-jocher
    Member

    @llucasreis thanks for the code. I am able to reproduce. Will investigate.

  6. linked a pull request that will close this issueFix ConfusionMatrix scale `vmin=0.0` #6638on Feb 14, 2022
  7. glenn-jocher commented on Feb 14, 2022

    @glenn-jocher
    Member

    @llucasreis good news 😃! Your original issue may now be fixed ✅ in PR #6638. Nan values were preventing a correct lower threshold for the Seaborn Heatmap colorbar, after update:

    image

    To receive this update:

    • Git – git pull from within your yolov5/ directory or git clone https://github.com/ultralytics/yolov5 again
    • PyTorch Hub – Force-reload model = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True)
    • Notebooks – View updated notebooks Open In Colab Open In Kaggle
    • Docker – sudo docker pull ultralytics/yolov5:latest to update your image Docker Pulls

    Thank you for spotting this issue and informing us of the problem. Please let us know if this update resolves the issue for you, and feel free to inform us of any other issues you discover or feature requests that come to mind. Happy trainings with YOLOv5 🚀!

  8. llucasreis commented on Feb 15, 2022

    @llucasreis
    Author

    Thank you very much! 😄 @glenn-jocher

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions