# New Labels#

This notebooks provides an overview for using and understanding the New Labels check.

Structure:

## 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 apper 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.

## Run the Check#

from deepchecks.vision.datasets.detection import coco
from deepchecks.vision.checks import NewLabels

result = NewLabels().run(coco_train, coco_test)
result


Out:

Validating Input:   0%| | 0/1 [00:00<?, ? /s]

Ingesting Batches - Train Dataset:   0%|  | 0/2 [00:00<?, ? Batch/s]
Ingesting Batches - Train Dataset:  50%|# | 1/2 [00:00<00:00,  5.40 Batch/s]
Ingesting Batches - Train Dataset: 100%|##| 2/2 [00:00<00:00,  5.23 Batch/s]

Ingesting Batches - Test Dataset:   0%|  | 0/2 [00:00<?, ? Batch/s]
Ingesting Batches - Test Dataset:  50%|# | 1/2 [00:00<00:00,  5.51 Batch/s]
Ingesting Batches - Test Dataset: 100%|##| 2/2 [00:00<00:00,  5.84 Batch/s]

Computing Check:   0%| | 0/1 [00:00<?, ? Check/s]/home/runner/work/deepchecks/deepchecks/deepchecks/vision/checks/distribution/new_labels.py:51: UserWarning:

Creating a tensor from a list of numpy.ndarrays is extremely slow. Please consider converting the list to a single numpy.ndarray with numpy.array() before converting to a tensor. (Triggered internally at  ../torch/csrc/utils/tensor_new.cpp:201.)

Computing Check: 100%|#| 1/1 [00:00<00:00,  6.88 Check/s]


#### New Labels

Detects labels that apper only in the test set.

### Label "donut"

Appears 14 times in test set.

### Label "tennis racket"

Appears 7 times in test set.

### Label "boat"

Appears 6 times in test set.

### 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.

result.value


Out:

{'donut': 14, 'tennis racket': 7, 'boat': 6, 'cat': 4, 'laptop': 3, 'mouse': 2, 'tv': 2, 'toilet': 2, 'skis': 1, 'bear': 1, 'all_labels': 387}


## 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.

check = NewLabels().add_condition_new_label_ratio_not_greater_than(0.05)
check.run(coco_train, coco_test)


Out:

Validating Input:   0%| | 0/1 [00:00<?, ? /s]

Ingesting Batches - Train Dataset:   0%|  | 0/2 [00:00<?, ? Batch/s]
Ingesting Batches - Train Dataset:  50%|# | 1/2 [00:00<00:00,  5.45 Batch/s]
Ingesting Batches - Train Dataset: 100%|##| 2/2 [00:00<00:00,  5.21 Batch/s]

Ingesting Batches - Test Dataset:   0%|  | 0/2 [00:00<?, ? Batch/s]
Ingesting Batches - Test Dataset:  50%|# | 1/2 [00:00<00:00,  5.58 Batch/s]
Ingesting Batches - Test Dataset: 100%|##| 2/2 [00:00<00:00,  5.87 Batch/s]

Computing Check:   0%| | 0/1 [00:00<?, ? Check/s]
Computing Check: 100%|#| 1/1 [00:00<00:00,  6.97 Check/s]


#### New Labels

Detects labels that apper only in the test set.

##### Conditions Summary
Percentage of new labels in the test set not above 5%. 10.85% of labels found in test set were not in train set. New labels most common in test set: ['donut', 'tennis racket', 'boat']

### Label "donut"

Appears 14 times in test set.

### Label "tennis racket"

Appears 7 times in test set.

### Label "boat"

Appears 6 times in test set.

In this case the condition identified that a major portion of the test set labels do not appear in the training set.

Total running time of the script: ( 0 minutes 2.431 seconds)

Gallery generated by Sphinx-Gallery