.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "vision/auto_checks/train_test_validation/plot_new_labels.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_vision_auto_checks_train_test_validation_plot_new_labels.py: .. _vision__new_labels: New Labels ========== This notebooks provides an overview for using and understanding the New Labels check. **Structure:** * `How the check works <#How-the-check-works>`__ * `Run the check <#run-the-check>`__ * `Define a condition <#define-a-condition>`__ How the check works ------------------- In this check we count the frequency of each class id in the test set then check which of them do not appear in the training set. Note that by default this check run on a sample of the data set and so it is possible that class ids that are rare in the train set will also be considered as new labels in the test set. .. GENERATED FROM PYTHON SOURCE LINES 25-33 Run the Check ------------- .. note:: In this example, we use the pytorch version of the coco dataset and model. In order to run this example using tensorflow, please change the import statements to:: from deepchecks.vision.datasets.detection import coco_tensorflow as coco .. GENERATED FROM PYTHON SOURCE LINES 33-43 .. code-block:: default from deepchecks.vision.datasets.detection import coco_torch as coco from deepchecks.vision.checks import NewLabels coco_train = coco.load_dataset(train=True, object_type='VisionData', shuffle=False) coco_test = coco.load_dataset(train=False, object_type='VisionData', shuffle=False) result = NewLabels().run(coco_train, coco_test) result .. rst-class:: sphx-glr-script-out .. code-block:: none Downloading https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5s.pt to yolov5s.pt... 0%| | 0.00/14.1M [00:00 New Labels

.. GENERATED FROM PYTHON SOURCE LINES 44-45 To display the results in an IDE like PyCharm, you can use the following code: .. GENERATED FROM PYTHON SOURCE LINES 45-47 .. code-block:: default # result.show_in_window() .. GENERATED FROM PYTHON SOURCE LINES 48-49 The result will be displayed in a new window. .. GENERATED FROM PYTHON SOURCE LINES 51-55 Observe the check’s output ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The check searches for new labels in the test set. The value output is a dictionary containing of appearances of each newly found class_id in addition to the total number of labels in the test set for comparison purposes. .. GENERATED FROM PYTHON SOURCE LINES 55-58 .. code-block:: default result.value .. rst-class:: sphx-glr-script-out .. code-block:: none {'new_labels': {'donut': 14, 'tennis racket': 7, 'boat': 6, 'cat': 4, 'laptop': 3, 'mouse': 2, 'toilet': 2, 'bear': 1}, 'all_labels_count': 387} .. GENERATED FROM PYTHON SOURCE LINES 59-66 Define a condition ------------------- The check has a default condition which can be defined. The condition verifies that the ratio of new labels out of the total number of labels in the test set is smaller than a given threshold. If the check is run with the default sampling mechanism we recommend on setting the condition threshold to a small percentage instead of setting it to 0. .. GENERATED FROM PYTHON SOURCE LINES 66-70 .. code-block:: default check = NewLabels().add_condition_new_label_ratio_less_or_equal(0.05) check.run(coco_train, coco_test) .. rst-class:: sphx-glr-script-out .. code-block:: none Processing Train Batches: | | 0/1 [Time: 00:00] Processing Train Batches: |█████| 1/1 [Time: 00:00] Processing Train Batches: |█████| 1/1 [Time: 00:00] Processing Test Batches: | | 0/1 [Time: 00:00] Processing Test Batches: |█████| 1/1 [Time: 00:00] Processing Test Batches: |█████| 1/1 [Time: 00:00] Computing Check: | | 0/1 [Time: 00:00] Computing Check: |█████| 1/1 [Time: 00:00] Computing Check: |█████| 1/1 [Time: 00:00] .. raw:: html
New Labels


.. GENERATED FROM PYTHON SOURCE LINES 71-72 In this case the condition identified that a major portion of the test set labels do not appear in the training set. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 4.744 seconds) .. _sphx_glr_download_vision_auto_checks_train_test_validation_plot_new_labels.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_new_labels.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_new_labels.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_