.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "checks_gallery/vision/model_evaluation/plot_mean_average_precision_report.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_checks_gallery_vision_model_evaluation_plot_mean_average_precision_report.py: .. _plot_vision_mean_average_precision_report: Mean Average Precision Report ***************************** This notebooks provides an overview for using and understanding the mean average precision report check. **Structure:** * `What is the purpose of the check? <#what-is-the-purpose-of-the-check>`__ * `Generate data & model <#generate-data-and-model>`__ * `Run the check <#run-the-check>`__ * `Define a condition <#define-a-condition>`__ What Is the Purpose of the Check? ================================= The Mean Average Precision Report evaluates the `mAP metric `__ on the given model and data, plots the AP on graph, and returns the mAP values per bounding box size category (small, medium, large). This check only works on the Object Detection task. .. GENERATED FROM PYTHON SOURCE LINES 28-33 Generate Data and Model ================================= We generate a sample dataset of 128 images from the `COCO dataset `__, and using the `YOLOv5 model `__. .. GENERATED FROM PYTHON SOURCE LINES 33-41 .. code-block:: default from deepchecks.vision.checks import MeanAveragePrecisionReport from deepchecks.vision.datasets.detection import coco yolo = coco.load_model(pretrained=True) test_ds = coco.load_dataset(train=False, object_type='VisionData') .. GENERATED FROM PYTHON SOURCE LINES 42-44 Run the check ================================= .. GENERATED FROM PYTHON SOURCE LINES 44-49 .. code-block:: default check = MeanAveragePrecisionReport() result = check.run(test_ds, yolo) result .. rst-class:: sphx-glr-script-out .. code-block:: none Validating Input: | | 0/1 [Time: 00:00] Validating Input: |#####| 1/1 [Time: 00:05] Validating Input: |#####| 1/1 [Time: 00:05] Ingesting Batches: | | 0/2 [Time: 00:00] Ingesting Batches: |##5 | 1/2 [Time: 00:05] Ingesting Batches: |#####| 2/2 [Time: 00:10] Ingesting Batches: |#####| 2/2 [Time: 00:10] Computing Check: | | 0/1 [Time: 00:00] Computing Check: |#####| 1/1 [Time: 00:00] Computing Check: |#####| 1/1 [Time: 00:00] .. raw:: html
Mean Average Precision Report


.. GENERATED FROM PYTHON SOURCE LINES 50-53 If you have a GPU, you can speed up this check by passing it as an argument to .run() as device= To display the results in an IDE like PyCharm, you can use the following code: .. GENERATED FROM PYTHON SOURCE LINES 53-55 .. code-block:: default # result.show_in_window() .. GENERATED FROM PYTHON SOURCE LINES 56-57 The result will be displayed in a new window. .. GENERATED FROM PYTHON SOURCE LINES 60-65 Observe the check’s output -------------------------- The result value is a dataframe that has the Mean Average Precision score for different bounding box area sizes. We report the mAP for different IoU thresholds: 0.5, 0.75 and an average of mAP values for IoU thresholds between 0.5 and 0.9 (with a jump size of 0.05). .. GENERATED FROM PYTHON SOURCE LINES 65-68 .. code-block:: default result.value .. raw:: html
mAP@[.50::.95] (avg.%) mAP@.50 (%) mAP@.75 (%)
Area size
All 0.409436 0.566673 0.425339
Small (area < 32^2) 0.212816 0.342429 0.212868
Medium (32^2 < area < 96^2) 0.383089 0.600228 0.349863
Large (area < 96^2) 0.541146 0.674493 0.585378


.. GENERATED FROM PYTHON SOURCE LINES 69-73 Define a condition ================== We can define a condition that checks whether our model's mean average precision score is not less than a given threshold for all bounding box sizes. .. GENERATED FROM PYTHON SOURCE LINES 73-77 .. code-block:: default check = MeanAveragePrecisionReport().add_condition_average_mean_average_precision_greater_than(0.4) result = check.run(test_ds, yolo) result.show(show_additional_outputs=False) .. rst-class:: sphx-glr-script-out .. code-block:: none Validating Input: | | 0/1 [Time: 00:00] Validating Input: |#####| 1/1 [Time: 00:04] Validating Input: |#####| 1/1 [Time: 00:04] Ingesting Batches: | | 0/2 [Time: 00:00] Ingesting Batches: |##5 | 1/2 [Time: 00:05] Ingesting Batches: |#####| 2/2 [Time: 00:10] Ingesting Batches: |#####| 2/2 [Time: 00:10] Computing Check: | | 0/1 [Time: 00:00] Computing Check: |#####| 1/1 [Time: 00:00] Computing Check: |#####| 1/1 [Time: 00:00] .. raw:: html
Mean Average Precision Report


.. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 31.867 seconds) .. _sphx_glr_download_checks_gallery_vision_model_evaluation_plot_mean_average_precision_report.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_mean_average_precision_report.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_mean_average_precision_report.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_