edadaltocg commited on
Commit
d5deb12
Β·
1 Parent(s): 4c254bc

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +196 -4
README.md CHANGED
@@ -1,10 +1,202 @@
1
  ---
2
- title: README
3
- emoji: 🐠
4
  colorFrom: pink
5
  colorTo: pink
6
  sdk: static
7
- pinned: false
 
8
  ---
9
 
10
- Edit this `README.md` markdown file to author your organization card.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: detectors
3
+ emoji: 🧐
4
  colorFrom: pink
5
  colorTo: pink
6
  sdk: static
7
+ pinned: true
8
+ license: apache-2.0
9
  ---
10
 
11
+ # 🧐 Detectors
12
+
13
+ Package to accelerate research on generalized out-of-distribution (OOD) detection.
14
+
15
+ Under development. Please report any issues or bugs [here](https://github.com/edadaltocg/detectors/issues).
16
+
17
+ ## Stats
18
+
19
+ [![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/edadaltocg/detectors/graphs/commit-activity)
20
+ [![build](https://github.com/edadaltocg/detectors/actions/workflows/build.yml/badge.svg)](https://github.com/edadaltocg/detectors/actions/workflows/build.yml)
21
+ [![Documentation Status](https://readthedocs.org/projects/detectors/badge/?version=latest)](http://detectors.readthedocs.io/?badge=latest)
22
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.7883080.svg)](https://doi.org/10.5281/zenodo.7883080)
23
+
24
+ ## What is it?
25
+
26
+ This library is aimed at assisting researchers in the field of generalized OOD detection. It is inspired by [HF's Transformers](https://https://github.com/huggingface/transformers) and features implementations of baselines, metrics, and data sets that allow researchers to perform meaningful benchmarking and development of ood detection methods. It features:
27
+
28
+ - `methods`: more than 20 detection methods implemented.
29
+ - `pipelines`: evaluating OOD detectors on popular benchmarks, such as MNIST, CIFAR, and ImageNet benchmarks with random seed support for reproducibility.
30
+ - `datasets`: OOD datasets implemented with md5 checksums and without the need to download them manually.
31
+ - `models`: model architectures totally integrated with [`timm`](https://github.com/huggingface/pytorch-image-models).
32
+ - `eval`: implementation of fast OOD evaluation metrics.
33
+ - Several aggregation methods for multi-layer OOD detection.
34
+ - Pipelines for open set recognition and covariate drift detection.
35
+
36
+ ## Installation
37
+
38
+ Please follow the instructions [here](https://pytorch.org/get-started/locally/) to install PyTorch. Installing PyTorch with CUDA support is strongly recommended.
39
+
40
+ ```bash
41
+ pip install detectors
42
+ ```
43
+
44
+ To install the latest version from the source:
45
+
46
+ ```bash
47
+ git clone https://github.com/edadaltocg/detectors.git
48
+ cd detectors
49
+ pip install --upgrade pip setuptools wheel
50
+ pip install -e .
51
+ ```
52
+
53
+ Also, you have easy access to the Python scripts from the examples:
54
+
55
+ ```bash
56
+ cd examples
57
+ ```
58
+
59
+ ## Examples
60
+
61
+ The following examples show how to use the library and how it can be integrated into your research. For more examples, please check the [documentation](https://detectors.readthedocs.io/en/latest/use_cases/).
62
+
63
+ ### Running a benchmark
64
+
65
+ The following example shows how to run a benchmark.
66
+
67
+ ```python
68
+ import detectors
69
+ import torch
70
+
71
+
72
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
73
+ model = detectors.create_model("resnet18_cifar10", pretrained=True)
74
+ model = model.to(device)
75
+ test_transform = detectors.create_transform(model)
76
+
77
+ pipeline = detectors.create_pipeline("ood_benchmark_cifar10", transform=test_transform)
78
+ method = detectors.create_detector("msp", model=model)
79
+
80
+ pipeline_results = pipeline.run(method)
81
+ print(pipeline.report(pipeline_results["results"]))
82
+ ```
83
+
84
+ We recommend running benchmarks on machines equipped with large RAM and GPUs with 16GB of memory or larger to leverage large batch sizes and faster inference.
85
+
86
+ ### Creating a detector
87
+
88
+ The following example shows how to create a detector. The only requirement is that the method takes an input `x` and returns a score.
89
+
90
+ ```python
91
+ import torch
92
+ import detectors
93
+
94
+
95
+ @detectors.register_detector("awesome_detector")
96
+ def awesome_detector(x: torch.Tensor, model, **kwargs):
97
+ # Do something awesome with the model and the input
98
+ return scores
99
+
100
+ # Instantiating the detector
101
+ method = detectors.create_detector("awesome_detector", model=model)
102
+ ```
103
+
104
+ Alternatively, you can use the `Detector` class to create a detector that requires some initialization or state to be fitted before being called (e.g., Mahalanobis detector):
105
+
106
+ ```python
107
+ import torch
108
+ import detectors
109
+
110
+
111
+ @detectors.register_detector("awesome_detector")
112
+ class AwesomeDetector(detectors.Detector):
113
+ def __init__(self, model, **kwargs):
114
+ self.model = model
115
+
116
+ def __call__(self, x: torch.Tensor, **kwargs):
117
+ # Do something awesome with the model and the input
118
+ return scores
119
+
120
+ # Instantiating the detector
121
+ method = detectors.create_detector("awesome_detector", model=model)
122
+ ```
123
+
124
+ Check the [documentation](https://detectors.readthedocs.io/en/latest/use_cases/) for more information.
125
+
126
+ ### Listing available resources
127
+
128
+ The following example shows how to list all available resources in the library.
129
+
130
+ ```python
131
+ import detectors
132
+
133
+
134
+ # list all available models (same as timm.list_models)
135
+ print(detectors.list_models())
136
+ # list all available models with a specific pattern
137
+ print(detectors.list_models("*cifar*"))
138
+ # list all available datasets
139
+ print(detectors.list_datasets())
140
+ # list all available detectors
141
+ print(detectors.list_detectors())
142
+ # list all available pipelines
143
+ print(detectors.list_pipelines())
144
+ ```
145
+
146
+ ## FAQ over specific documents
147
+
148
+ **Methods**
149
+
150
+ - [Documentation](https://detectors.readthedocs.io/en/latest/use_cases/)
151
+
152
+ **Pipelines**
153
+
154
+ - [Documentation](https://detectors.readthedocs.io/en/latest/use_cases/)
155
+
156
+ **Pypi**
157
+
158
+ - [Website](https://pypi.org/project/detectors)
159
+
160
+ ## Contributing
161
+
162
+ As an open-source project in a rapidly developing field, we are open to contributions, whether in the form of a new feature, improved infra, or better documentation.
163
+
164
+ See the [contributing guidelines](https://github.com/edadaltocg/detectors/blob/master/CONTRIBUTING.md) for instructions on how to make your first contribution to `detectors`.
165
+
166
+ ### Thanks to all our contributors
167
+
168
+ <a href="https://github.com/edadaltocg/detectors/graphs/contributors">
169
+ <img src="https://contributors-img.web.app/image?repo=edadaltocg/detectors" />
170
+ </a>
171
+
172
+ ## Contact
173
+
174
+ Concerning this package, its use, and bugs, use the [issue page](https://github.com/edadaltocg/detectors/issues) of the [ruptures repository](https://github.com/edadaltocg/detectors). For other inquiries, you can contact me [here](https://edadaltocg.github.io/contact/).
175
+
176
+ ## Important links
177
+
178
+ - [Documentation](http://detectors.readthedocs.io/)
179
+ - [Pypi package index](https://pypi.python.org/pypi/detectors)
180
+ - [Github repository](https://github.com/edadaltocg/detectors)
181
+
182
+ ## Limitations
183
+
184
+ - This library is only compatible with PyTorch models.
185
+ - This library has implemented only computer vision pipelines and datasets.
186
+
187
+ ## Citing detectors
188
+
189
+ The detection of Out-of-Distribution (OOD) has created a new way of securing machine intelligence, but despite its many successes, it can be difficult to understand due to the various methods available and their intricate implementations. The fast pace of research and the wide range of OOD methods makes it challenging to navigate the field, which can be a problem for those who have recently joined the field or want to deploy OOD detection. The library we have created aims to lower these barriers by providing a resource for researchers of any background to understand the methods available, how they work, and how to be successful with OOD detection.
190
+
191
+ If you find this repository useful, please consider giving it a star 🌟 and citing it as below:
192
+
193
+ ```bibtex
194
+ @software{detectors2023,
195
+ author = {Eduardo Dadalto},
196
+ title = {Detectors: a Python Library for Generalized Out-Of-Distribution Detection},
197
+ url = {https://github.com/edadaltocg/detectors},
198
+ doi = {https://doi.org/10.5281/zenodo.7883596},
199
+ month = {5},
200
+ year = {2023}
201
+ }
202
+ ```