Main APIο
Methodsο
Detection methods.
- class detectors.methods.MethodsRegistry(value)ο
Bases:
EnumAn enumeration.
- always_one = 'always_one'ο
- always_zero = 'always_zero'ο
- csi = 'csi'ο
- dice = 'dice'ο
- doctor = 'doctor'ο
- energy = 'energy'ο
- entropy = 'entropy'ο
- gmm = 'gmm'ο
- gradnorm = 'gradnorm'ο
- igeood_logits = 'igeood_logits'ο
- kl_matching = 'kl_matching'ο
- knn_cosine = 'knn_cosine'ο
- knn_euclides = 'knn_euclides'ο
- knn_projection = 'knn_projection'ο
- mahalanobis = 'mahalanobis'ο
- max_logits = 'max_logits'ο
- maxcosine = 'maxcosine'ο
- mcdropout = 'mcdropout'ο
- msp = 'msp'ο
- odin = 'odin'ο
- projection = 'projection'ο
- random = 'random'ο
- react = 'react'ο
- react_projection = 'react_projection'ο
- relative_mahalanobis = 'relative_mahalanobis'ο
- ssd = 'ssd'ο
- vim = 'vim'ο
- detectors.methods.create_detector(detector_name: str, **kwargs) Detector[source]ο
Create detector factory.
- Parameters:
detector_name (string) β
Name of the detector. Already implemented:
random, msp, odin, energy, mahalanobis, react, dice, knn_euclides, igeood_logits, projection, react_projection, gradnorm, maxcosine, mcdropout, max_logits, kl_matching, gmm, relative_mahalanobis, doctor, always_one, always_zero, random_score, vim, entropy, ssd, csi, knn_cosine, knn_projection.
**kwargs β Additional arguments for the detector.
- Returns:
the corresponding detector.
- Return type:
- detectors.methods.create_hyperparameters(detector_name: str) Dict[str, Any][source]ο
Create hyperparameters for the detector.
- Parameters:
detector_name (string) β Name of the detector.
- Returns:
Hyperparameters for the detector.
- Return type:
Dict[str, Any]
- detectors.methods.list_detectors() List[str][source]ο
List available detectors.
- Returns:
List of available detectors.
- Return type:
List[str]
- detectors.methods.register_detector(name: str)[source]ο
Decorator to register a new detector.
- Parameters:
name (string) β Name of the detector.
Example:
@register_detector("my_detector") class MyDetector(Detector): ... detector = create_detector("my_detector") @register_detector("my_detector") def my_detector(model, **kwargs): ... detector = create_detector("my_detector")
Pipelinesο
Pipeline module.
- class detectors.pipelines.PipelinesRegistry(value)ο
Bases:
EnumAn enumeration.
- covariate_drift_cifar10 = 'covariate_drift_cifar10'ο
- covariate_drift_cifar100 = 'covariate_drift_cifar100'ο
- covariate_drift_imagenet = 'covariate_drift_imagenet'ο
- ood_benchmark_cifar10 = 'ood_benchmark_cifar10'ο
- ood_benchmark_cifar100 = 'ood_benchmark_cifar100'ο
- ood_benchmark_imagenet = 'ood_benchmark_imagenet'ο
- ood_mnist_benchmark = 'ood_mnist_benchmark'ο
- ood_validation_cifar10 = 'ood_validation_cifar10'ο
- ood_validation_cifar100 = 'ood_validation_cifar100'ο
- ood_validation_imagenet = 'ood_validation_imagenet'ο
- ood_validation_noise_cifar10 = 'ood_validation_noise_cifar10'ο
- ood_validation_noise_cifar100 = 'ood_validation_noise_cifar100'ο
- detectors.pipelines.create_pipeline(name: str, dataset_name: str | None = None, **kwargs) Pipeline[source]ο
Utility factory method to build a Pipeline.
- Parameters:
name (str, optional) β
- The name defining which pipeline will be returned. Currently accepted pipeline names are:
ood_benchmark, ood_validation, ood_validation_noise, covariate_drift, osr
- Complete list:
ood_benchmark_cifar10, ood_benchmark_cifar100, ood_benchmark_imagenet, ood_mnist_benchmark, ood_validation_cifar10, ood_validation_cifar100, ood_validation_imagenet, ood_validation_mnist, ood_validation_noise_cifar10, ood_validation_noise_cifar100, ood_validation_noise_imagenet, covariate_drift_cifar10, covariate_drift_cifar100, covariate_drift_imagenet.
**kwargs β Additional arguments to pass to the pipeline.
- Returns:
A suitable pipeline for the task.
- Return type:
Example:
>>> import detectors >>> pipe = detectors.create_pipeline("ood_benchmark", "cifar10") >>> pipe.run(detector)
- detectors.pipelines.list_pipeline_args(name: str) List[Tuple[str, Any]][source]ο
List all available arguments for a given pipeline.
- Parameters:
name (str) β The name of the pipeline.
- Returns:
A list of available arguments and default values for the pipeline.
- Return type:
list
Dataο
Datasets module.
- class detectors.data.DatasetsRegistry(value)ο
Bases:
EnumAn enumeration.
- blobs = 'blobs'ο
- cifar10 = 'cifar10'ο
- cifar100 = 'cifar100'ο
- cifar100_c = 'cifar100_c'ο
- cifar10_c = 'cifar10_c'ο
- english_chars = 'english_chars'ο
- fashion_mnist = 'fashion_mnist'ο
- gaussian = 'gaussian'ο
- ilsvrc2012 = 'ilsvrc2012'ο
- imagenet = 'imagenet'ο
- imagenet1k = 'imagenet1k'ο
- imagenet1k_c = 'imagenet1k_c'ο
- imagenet_a = 'imagenet_a'ο
- imagenet_c = 'imagenet_c'ο
- imagenet_c_npz = 'imagenet_c_npz'ο
- imagenet_o = 'imagenet_o'ο
- imagenet_r = 'imagenet_r'ο
- isun = 'isun'ο
- lsun_c = 'lsun_c'ο
- lsun_r = 'lsun_r'ο
- mnist = 'mnist'ο
- mnist_c = 'mnist_c'ο
- mos_inaturalist = 'mos_inaturalist'ο
- mos_places365 = 'mos_places365'ο
- mos_sun = 'mos_sun'ο
- openimage_o = 'openimage_o'ο
- oxford_pets = 'oxford_pets'ο
- places365 = 'places365'ο
- rademacher = 'rademacher'ο
- stanford_cars = 'stanford_cars'ο
- stl10 = 'stl10'ο
- svhn = 'svhn'ο
- textures = 'textures'ο
- tiny_imagenet = 'tiny_imagenet'ο
- tiny_imagenet_c = 'tiny_imagenet_c'ο
- tiny_imagenet_r = 'tiny_imagenet_r'ο
- uniform = 'uniform'ο
- wilds_camelyon17 = 'wilds_camelyon17'ο
- wilds_fmow = 'wilds_fmow'ο
- wilds_globalwheat = 'wilds_globalwheat'ο
- wilds_iwildcam = 'wilds_iwildcam'ο
- wilds_poverty = 'wilds_poverty'ο
- wilds_rxrx1 = 'wilds_rxrx1'ο
- detectors.data.create_dataset(dataset_name: str, root: str = '/home/docs/checkouts/readthedocs.org/user_builds/detectors/checkouts/latest/data/', split: str | None = 'train', transform: Callable | None = None, download: bool | None = True, **kwargs)[source]ο
Create dataset factory.
- Parameters:
dataset_name (string) β
Name of the dataset. Already implemented:
cifar10, cifar100, stl10, svhn, mnist, fashion_mnist, kmnist, emnist, mnist_c, english_chars, isun, lsun_c, lsun_r, tiny_imagenet_c, tiny_imagenet_r, tiny_imagenet, textures, gaussian, uniform, places365, stanford_cars, imagenet, imagenet1k, ilsvrc2012, mos_inaturalist, mos_places365, mos_sun, cifar10_lt, cifar100_lt, imagenet1k_lt, cifar10_c, cifar100_c, imagenet_c, imagenet_c_npz, imagenet_a, imagenet_r, imagenet_o, openimage_o, oxford_pets, oxford_flowers, cub200, imagenet1k_c, blobs, rademacher, wilds_iwildcam, wilds_fmow, wilds_camelyon17, wilds_rxrx1, wilds_poverty, wilds_globalwheat.
root (string) β Root directory of dataset.
split (string, optional) β Depends on the selected dataset.
transform (callable, optional) β A function/transform that takes in an PIL image and returns a transformed version. E.g, transforms.RandomCrop
download (bool, optional) β If true, downloads the dataset from the internet and puts it in root directory. If dataset is already downloaded, it is not downloaded again.
**kwargs β Additional arguments for dataset.
- Raises:
ValueError β If dataset name is not specified.
- Returns:
Dataset object.
- Return type:
Dataset
- detectors.data.get_dataset_cls(dataset_name: str) Type[Dataset][source]ο
Return dataset class by name.
- Parameters:
dataset_name (string) β Name of the dataset.
- Raises:
ValueError β If dataset name is not available in datasets_registry.
- Returns:
Dataset class.
- Return type:
Dataset
Modelsο
- detectors.models.create_transform(model: Module, is_training: bool = False)[source]ο
Create a input transformation for a given model.
Based on the default configuration of the model following timmβs library.
- Parameters:
model (torch.nn.Module) β Model to create the transformation for.
is_training (bool, optional) β Whether the transformation is for training or not. Defaults to False.
- Returns:
The transformation.
- Return type:
Callable