{ "cells": [ { "cell_type": "markdown", "id": "1043b220", "metadata": {}, "source": [ "# Detect Outliers with Cleanlab and PyTorch Image Models (timm)\n", "\n", "This quick tutorial shows how to detect outliers (out-of-distribution examples) in image data, using the [cifar10](https://www.cs.toronto.edu/~kriz/cifar.html) dataset as an example. You can easily replace the image dataset + neural network used here with any other Pytorch dataset + neural network (e.g. to instead detect outliers in text data with minimal code changes). \n", "\n", "**Overview of what we'll do in this tutorial:**\n", "\n", "Detect outliers using `feature_embeddings`\n", "\n", "- Pre-process [cifar10](https://www.cs.toronto.edu/~kriz/cifar.html) into Pytorch datasets where `train_data` only contains images of animals and `test_data` contains images from all classes.\n", "\n", "- Use a pretrained neural network model from [timm](https://github.com/rwightman/pytorch-image-models) to extract feature embeddings of each image.\n", "\n", "- Use cleanlab to find naturally occurring outlier examples in the `train_data` (i.e. atypical images).\n", "\n", "- Find outlier examples in the `test_data` that do not stem from training data distribution (including out-of-distribution non-animal images).\n", "\n", "- Explore threshold selection for determining which images are outliers vs not.\n", "\n", "Detect outliers using `pred_probs` from a trained classifier\n", "\n", "- Adapt our [timm](https://github.com/rwightman/pytorch-image-models) network into a classifier by training an additional output layer using the (in-distribution) training data.\n", "\n", "- Use cleanlab to find out-of-distribution examples in the dataset based on the probabilistic predictions of this classifier, as an alternative to relying on feature embeddings." ] }, { "cell_type": "markdown", "id": "70016f64", "metadata": {}, "source": [ "