Single Dataset Scalar Performance#

This notebooks provides an overview for using and understanding single dataset scalar performance check.

Structure:

What Is the Purpose of the Check?#

This check returns a metric result as a single scalar, which is especially useful for monitoring a model in production.

Some metrics return a single score, but others return a tensor of scores.

For example, Precision returns a tensor in the size of the number of classes. In that case, we will use a reduce function - a function that aggregates the scores into a scalar. In this example we use ‘nanmean’ that returns the mean over the classes, while ignoring NaNs.

Generate data and model#

from deepchecks.vision.checks import SingleDatasetScalarPerformance
from deepchecks.vision.datasets.classification import mnist
mnist_model = mnist.load_model()
train_ds = mnist.load_dataset(train=True, object_type='VisionData')

Run the check#

We will run the check with the model defined above.

The check will use the default classification metric - ignite.Accuracy. The default metric returns a scalar, therefore we will use the reduce function default - None.

Out:

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

Ingesting Batches:
|                                                                                                                                                             | 0/157 [00:00<?, ? Batch/s]

Ingesting Batches:
|#########                                                                                                                                                    | 9/157 [00:00<00:01, 84.41 Batch/s]

Ingesting Batches:
|###################                                                                                                                                          | 19/157 [00:00<00:01, 90.18 Batch/s]

Ingesting Batches:
|############################9                                                                                                                                | 29/157 [00:00<00:01, 90.76 Batch/s]

Ingesting Batches:
|#######################################                                                                                                                      | 39/157 [00:00<00:01, 91.66 Batch/s]

Ingesting Batches:
|#################################################                                                                                                            | 49/157 [00:00<00:01, 92.48 Batch/s]

Ingesting Batches:
|###########################################################                                                                                                  | 59/157 [00:00<00:01, 92.88 Batch/s]

Ingesting Batches:
|#####################################################################                                                                                        | 69/157 [00:00<00:00, 92.62 Batch/s]

Ingesting Batches:
|###############################################################################                                                                              | 79/157 [00:00<00:00, 92.89 Batch/s]

Ingesting Batches:
|#########################################################################################                                                                    | 89/157 [00:00<00:00, 92.28 Batch/s]

Ingesting Batches:
|###################################################################################################                                                          | 99/157 [00:01<00:00, 92.03 Batch/s]

Ingesting Batches:
|#############################################################################################################                                                | 109/157 [00:01<00:00, 91.28 Batch/s]

Ingesting Batches:
|#######################################################################################################################                                      | 119/157 [00:01<00:00, 90.55 Batch/s]

Ingesting Batches:
|#################################################################################################################################                            | 129/157 [00:01<00:00, 91.52 Batch/s]

Ingesting Batches:
|###########################################################################################################################################                  | 139/157 [00:01<00:00, 92.60 Batch/s]

Ingesting Batches:
|#####################################################################################################################################################        | 149/157 [00:01<00:00, 92.50 Batch/s]

Ingesting Batches:
|#############################################################################################################################################################| 157/157 [00:01<00:00, 92.50 Batch/s]


Computing Check:
|     | 0/1 [00:00<?, ? Check/s]


Computing Check:
|#####| 1/1 [00:00<00:00, 4240.95 Check/s]
Single Dataset Scalar Performance


The result value is a dictionary with the following fields: score - the actual result, metric - the name of metric used reduce - the name of the reduce function used.

result.value

Out:

{'score': 0.9837, 'metric': 'accuracy', 'reduce': None}

Now we will run a check with parameters, to use a metric and a reduce function different from the defaults. We will also pass names for them, so that the return value will look neat.

from ignite.metrics import Precision
from torch import nanmean

check = SingleDatasetScalarPerformance(Precision(), nanmean, metric_name='precision', reduce_name='mean')
result = check.run(train_ds, mnist_model)
result.value

Out:

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

Ingesting Batches:
|                                                                                                                                                             | 0/157 [00:00<?, ? Batch/s]

Ingesting Batches:
|#########                                                                                                                                                    | 9/157 [00:00<00:01, 87.50 Batch/s]

Ingesting Batches:
|###################                                                                                                                                          | 19/157 [00:00<00:01, 92.12 Batch/s]

Ingesting Batches:
|############################9                                                                                                                                | 29/157 [00:00<00:01, 89.94 Batch/s]

Ingesting Batches:
|#######################################                                                                                                                      | 39/157 [00:00<00:01, 91.21 Batch/s]

Ingesting Batches:
|#################################################                                                                                                            | 49/157 [00:00<00:01, 89.94 Batch/s]

Ingesting Batches:
|###########################################################                                                                                                  | 59/157 [00:00<00:01, 87.06 Batch/s]

Ingesting Batches:
|#####################################################################                                                                                        | 69/157 [00:00<00:00, 89.51 Batch/s]

Ingesting Batches:
|###############################################################################                                                                              | 79/157 [00:00<00:00, 90.91 Batch/s]

Ingesting Batches:
|#########################################################################################                                                                    | 89/157 [00:00<00:00, 91.02 Batch/s]

Ingesting Batches:
|###################################################################################################                                                          | 99/157 [00:01<00:00, 89.23 Batch/s]

Ingesting Batches:
|############################################################################################################                                                 | 108/157 [00:01<00:00, 87.48 Batch/s]

Ingesting Batches:
|####################################################################################################################9                                        | 117/157 [00:01<00:00, 86.22 Batch/s]

Ingesting Batches:
|##############################################################################################################################                               | 126/157 [00:01<00:00, 85.09 Batch/s]

Ingesting Batches:
|#######################################################################################################################################                      | 135/157 [00:01<00:00, 84.44 Batch/s]

Ingesting Batches:
|################################################################################################################################################             | 144/157 [00:01<00:00, 84.02 Batch/s]

Ingesting Batches:
|#########################################################################################################################################################    | 153/157 [00:01<00:00, 81.31 Batch/s]

Ingesting Batches:
|#############################################################################################################################################################| 157/157 [00:01<00:00, 81.31 Batch/s]


Computing Check:
|     | 0/1 [00:00<?, ? Check/s]


Computing Check:
|#####| 1/1 [00:00<00:00, 510.50 Check/s]






{'score': 0.9837194021061553, 'metric': 'precision', 'reduce': 'mean'}

Define a Condition#

We can define a condition to validate that our model performance score is above or below a certain threshold. The condition is defined as a function that takes the results of the check as input and returns a ConditionResult object.

check = SingleDatasetScalarPerformance()
check.add_condition_greater_than(0.5)
result = check.run(train_ds, mnist_model)
result.show(show_additional_outputs=False)

Out:

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

Ingesting Batches:
|                                                                                                                                                             | 0/157 [00:00<?, ? Batch/s]

Ingesting Batches:
|#########                                                                                                                                                    | 9/157 [00:00<00:01, 82.97 Batch/s]

Ingesting Batches:
|##################                                                                                                                                           | 18/157 [00:00<00:01, 83.11 Batch/s]

Ingesting Batches:
|###########################                                                                                                                                  | 27/157 [00:00<00:01, 82.46 Batch/s]

Ingesting Batches:
|#####################################                                                                                                                        | 37/157 [00:00<00:01, 86.76 Batch/s]

Ingesting Batches:
|###############################################                                                                                                              | 47/157 [00:00<00:01, 89.55 Batch/s]

Ingesting Batches:
|########################################################9                                                                                                    | 57/157 [00:00<00:01, 91.09 Batch/s]

Ingesting Batches:
|###################################################################                                                                                          | 67/157 [00:00<00:00, 90.79 Batch/s]

Ingesting Batches:
|#############################################################################                                                                                | 77/157 [00:00<00:00, 91.28 Batch/s]

Ingesting Batches:
|#######################################################################################                                                                      | 87/157 [00:00<00:00, 91.44 Batch/s]

Ingesting Batches:
|#################################################################################################                                                            | 97/157 [00:01<00:00, 92.60 Batch/s]

Ingesting Batches:
|###########################################################################################################                                                  | 107/157 [00:01<00:00, 92.99 Batch/s]

Ingesting Batches:
|####################################################################################################################9                                        | 117/157 [00:01<00:00, 90.79 Batch/s]

Ingesting Batches:
|###############################################################################################################################                              | 127/157 [00:01<00:00, 92.32 Batch/s]

Ingesting Batches:
|#########################################################################################################################################                    | 137/157 [00:01<00:00, 91.04 Batch/s]

Ingesting Batches:
|###################################################################################################################################################          | 147/157 [00:01<00:00, 92.83 Batch/s]

Ingesting Batches:
|#############################################################################################################################################################| 157/157 [00:01<00:00, 92.83 Batch/s]


Computing Check:
|     | 0/1 [00:00<?, ? Check/s]


Computing Check:
|#####| 1/1 [00:00<00:00, 4165.15 Check/s]
Single Dataset Scalar Performance


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

Gallery generated by Sphinx-Gallery