detectors package
Subpackages
- detectors.aggregations package
- Submodules
- detectors.aggregations.anomaly module
- detectors.aggregations.basics module
- detectors.aggregations.cosine module
- detectors.aggregations.innerprod module
- detectors.aggregations.mahalanobis module
- detectors.aggregations.quantile module
- detectors.aggregations.supervised module
- Module contents
- detectors.data package
- Submodules
- detectors.data.cifar_wrapper module
- detectors.data.cifarc module
- detectors.data.cifarlt module
- detectors.data.constants module
- detectors.data.english_chars module
- detectors.data.imagenet module
- detectors.data.imagenetlt module
- detectors.data.isun module
- detectors.data.lsun_r_c module
- detectors.data.mnist_wrapped module
- detectors.data.mnistc module
- detectors.data.mos module
- detectors.data.noise module
- detectors.data.openimage_o module
- detectors.data.places365 module
- detectors.data.textures module
- detectors.data.tiny_imagenet module
- detectors.data.tiny_imagenet_r_c module
- detectors.data.wilds_ds module
- Module contents
DatasetsRegistryDatasetsRegistry.blobsDatasetsRegistry.cifar10DatasetsRegistry.cifar100DatasetsRegistry.cifar100_cDatasetsRegistry.cifar10_cDatasetsRegistry.english_charsDatasetsRegistry.fashion_mnistDatasetsRegistry.gaussianDatasetsRegistry.ilsvrc2012DatasetsRegistry.imagenetDatasetsRegistry.imagenet1kDatasetsRegistry.imagenet1k_cDatasetsRegistry.imagenet_aDatasetsRegistry.imagenet_cDatasetsRegistry.imagenet_c_npzDatasetsRegistry.imagenet_oDatasetsRegistry.imagenet_rDatasetsRegistry.isunDatasetsRegistry.lsun_cDatasetsRegistry.lsun_rDatasetsRegistry.mnistDatasetsRegistry.mnist_cDatasetsRegistry.mos_inaturalistDatasetsRegistry.mos_places365DatasetsRegistry.mos_sunDatasetsRegistry.openimage_oDatasetsRegistry.oxford_petsDatasetsRegistry.places365DatasetsRegistry.rademacherDatasetsRegistry.stanford_carsDatasetsRegistry.stl10DatasetsRegistry.svhnDatasetsRegistry.texturesDatasetsRegistry.tiny_imagenetDatasetsRegistry.tiny_imagenet_cDatasetsRegistry.tiny_imagenet_rDatasetsRegistry.uniformDatasetsRegistry.wilds_camelyon17DatasetsRegistry.wilds_fmowDatasetsRegistry.wilds_globalwheatDatasetsRegistry.wilds_iwildcamDatasetsRegistry.wilds_povertyDatasetsRegistry.wilds_rxrx1
create_dataset()get_dataset_cls()list_datasets()register_dataset()
- detectors.methods package
- Submodules
- detectors.methods.ae module
- detectors.methods.bats module
- detectors.methods.csi module
- detectors.methods.dice module
- detectors.methods.doctor module
- detectors.methods.energy module
- detectors.methods.entropy module
- detectors.methods.gmm module
- detectors.methods.gmm_torch module
- detectors.methods.godin module
- detectors.methods.gradnorm module
- detectors.methods.gram module
- detectors.methods.igeood_logits module
- detectors.methods.kl_matching module
- detectors.methods.knn_euclides module
- detectors.methods.logit_norm module
- detectors.methods.mahalanobis module
- detectors.methods.max_logits module
- detectors.methods.maxcosine module
- detectors.methods.mcdropout module
- detectors.methods.msp module
- detectors.methods.naive module
- detectors.methods.odin module
- detectors.methods.oe module
- detectors.methods.openmax module
- detectors.methods.projection module
- detectors.methods.rankfeat module
- detectors.methods.react module
- detectors.methods.react_projection module
- detectors.methods.relative_mahalanobis module
- detectors.methods.ssd module
- detectors.methods.templates module
- detectors.methods.utils module
adaptive_avg_pool2d()adaptive_max_pool2d()add_output_op()avg_or_getitem()create_reduction()flatten()get_composed_attr()get_last_layer()get_last_layer_name()get_penultimate_layer()get_penultimate_layer_name()getitem()input_pre_processing()max_or_getitem()none_reduction()sklearn_cov_matrix_estimarion()torch_reduction_matrix()
- detectors.methods.vim module
- Module contents
MethodsRegistryMethodsRegistry.always_oneMethodsRegistry.always_zeroMethodsRegistry.csiMethodsRegistry.diceMethodsRegistry.doctorMethodsRegistry.energyMethodsRegistry.entropyMethodsRegistry.gmmMethodsRegistry.gradnormMethodsRegistry.igeood_logitsMethodsRegistry.kl_matchingMethodsRegistry.knn_cosineMethodsRegistry.knn_euclidesMethodsRegistry.knn_projectionMethodsRegistry.mahalanobisMethodsRegistry.max_logitsMethodsRegistry.maxcosineMethodsRegistry.mcdropoutMethodsRegistry.mspMethodsRegistry.odinMethodsRegistry.projectionMethodsRegistry.randomMethodsRegistry.reactMethodsRegistry.react_projectionMethodsRegistry.relative_mahalanobisMethodsRegistry.ssdMethodsRegistry.vim
create_detector()create_hyperparameters()list_detectors()register_detector()
- detectors.models package
- Submodules
- detectors.models.densenet module
- detectors.models.resnet module
resnet18_cifar10()resnet18_cifar100()resnet18_svhn()resnet34_cifar10()resnet34_cifar100()resnet34_simclr_cifar10()resnet34_simclr_cifar100()resnet34_supcon_cifar10()resnet34_supcon_cifar100()resnet34_svhn()resnet50_cifar10()resnet50_cifar100()resnet50_simclr_cifar10()resnet50_simclr_cifar100()resnet50_supcon_cifar10()resnet50_supcon_cifar100()resnet50_svhn()
- detectors.models.utils module
- detectors.models.vgg module
- detectors.models.vit module
- Module contents
- detectors.pipelines package
- Submodules
- detectors.pipelines.base module
- detectors.pipelines.covariate_drift module
- detectors.pipelines.ood module
OODBenchmarkPipelineOODCifar100BenchmarkPipelineOODCifar100NoiseValidationPipelineOODCifar100ValidationPipelineOODCifar10BenchmarkPipelineOODCifar10NoiseValidationPipelineOODCifar10ValidationPipelineOODImageNetBenchmarkPipelineOODImageNetValidationPipelineOODMNISTBenchmarkPipelineOODValidationPipeline
- detectors.pipelines.osr module
- detectors.pipelines.ttoodda module
- Module contents
PipelinesRegistryPipelinesRegistry.covariate_drift_cifar10PipelinesRegistry.covariate_drift_cifar100PipelinesRegistry.covariate_drift_imagenetPipelinesRegistry.ood_benchmark_cifar10PipelinesRegistry.ood_benchmark_cifar100PipelinesRegistry.ood_benchmark_imagenetPipelinesRegistry.ood_mnist_benchmarkPipelinesRegistry.ood_validation_cifar10PipelinesRegistry.ood_validation_cifar100PipelinesRegistry.ood_validation_imagenetPipelinesRegistry.ood_validation_noise_cifar10PipelinesRegistry.ood_validation_noise_cifar100
create_pipeline()list_pipeline_args()list_pipelines()register_pipeline()
Submodules
detectors.config module
Configuration for the project.
It is used to set the default paths for the data, checkpoints, results, etc.
Constants:
DATA_DIR: The directory where the data is stored.
IMAGENET_ROOT: The directory where the ImageNet data is stored.
CHECKPOINTS_DIR: The directory where the checkpoints are stored.
RESULTS_DIR: The directory where the results are stored.
detectors.criterions module
- class detectors.criterions.CSILoss(temperature=0.07, contrast_mode='all', base_temperature=0.07, lbd=1)[source]
Bases:
SupConLossContrasting shifted instances (con-SI) loss.
References
[1] https://arxiv.org/abs/2007.08176
- forward(features, shift_labels, labels=None, mask=None)[source]
Compute loss for model. If both labels and mask are None, it degenerates to SimCLR unsupervised loss.
- Parameters:
features – hidden vector of shape [bsz, n_views, …].
labels – ground truth of shape [bsz].
mask – contrastive mask of shape [bsz, bsz], mask_{i,j}=1 if sample j has the same class as sample i. Can be asymmetric.
- Returns:
A loss scalar.
- training: bool
- class detectors.criterions.SupConLoss(temperature=0.07, contrast_mode='all', base_temperature=0.07)[source]
Bases:
ModuleSupervised Contrastive Learning. It also supports the unsupervised contrastive loss in SimCLR: A Simple Framework for Contrastive Learning of Visual Representations
References
[1] https://github.com/HobbitLong/SupContrast [2] https://arxiv.org/pdf/2004.11362.pdf [3] https://arxiv.org/abs/2002.05709
- forward(features, labels=None, mask=None)[source]
Compute loss for model. If both labels and mask are None, it degenerates to SimCLR unsupervised loss.
- Parameters:
features – hidden vector of shape [bsz, n_views, …].
labels – ground truth of shape [bsz].
mask – contrastive mask of shape [bsz, bsz], mask_{i,j}=1 if sample j has the same class as sample i. Can be asymmetric.
- Returns:
A loss scalar.
- training: bool
detectors.eval module
Module containing evaluation metrics.
- detectors.eval.compute_detection_error(fpr: float, tpr: float, pos_ratio: float)[source]
Compute the detection error.
- Parameters:
fpr (float) – False positive rate at a fixed TPR.
tpr (float) – True positive rate.
pos_ratio (float) – Ratio of positive labels.
- Returns:
Detection error.
- Return type:
float
- detectors.eval.fpr_at_fixed_tpr(fprs: ndarray, tprs: ndarray, thresholds: ndarray, tpr_level: float = 0.95)[source]
Return the FPR at a fixed TPR level.
- Parameters:
fprs (np.ndarray) – False positive rates.
tprs (np.ndarray) – True positive rates.
thresholds (np.ndarray) – Thresholds.
tpr_level (float, optional) – TPR level. Defaults to 0.95.
- Returns:
FPR, TPR, threshold.
- Return type:
Tuple[float, float, float]
- detectors.eval.get_ood_results(in_scores: Tensor, ood_scores: Tensor) Dict[str, float][source]
Compute OOD detection metrics.
- Parameters:
in_scores (Tensor) – In-distribution scores.
ood_scores (Tensor) – Out-of-distribution scores.
- Returns:
- OOD detection metrics.
keys: fpr_at_0.95_tpr, tnr_at_0.95_tpr, detection_error, auroc, aupr_in, aupr_out, thr.
- Return type:
Dict[str, float]
- detectors.eval.minimum_detection_error(fprs: ndarray, tprs: ndarray, pos_ratio: float)[source]
Compute the minimum detection error.
- Parameters:
fprs (np.ndarray) – False positive rates.
tprs (np.ndarray) – True positive rates.
thresholds (np.ndarray) – Thresholds.
pos_ratio (float) – Ratio of positive labels.
- Returns:
FPR, TPR, threshold.
- Return type:
Tuple[float, float, float]
detectors.trainer module
Trainer for classification models.
- detectors.trainer.trainer_supervised_classification(model: ~torch.nn.modules.module.Module, optimizer: ~torch.optim.optimizer.Optimizer, scheduler: ~torch.optim.lr_scheduler._LRScheduler, criterion: ~typing.Callable, train_loader: ~torch.utils.data.dataloader.DataLoader, val_loader: ~torch.utils.data.dataloader.DataLoader, save_root: str, training_function=<function training_iteration>, validation_function=<function validation_iteration>, epochs=10, validation_frequency=1, seed: int = 42)[source]
detectors.utils module
- detectors.utils.sync_tensor_across_gpus(t: Tensor) Tensor[source]
Gather tensor from all gpus and return a tensor with dim 0 equal to the number of gpus.
- Parameters:
t (torch.Tensor) – _description_
- Returns:
_description_
- Return type:
torch.Tensor
References
https://discuss.pytorch.org/t/ddp-evaluation-gather-output-loss-and-stuff-how-to/130593/2
Module contents
Detectors package.