Upload README.md
Browse files
README.md
ADDED
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
---
|
4 |
+
# Dataset Card for MedIAnomaly
|
5 |
+
|
6 |
+
## Dataset Description
|
7 |
+
|
8 |
+
**MedIAnomaly** is a benchmark designed to evaluate anomaly detection methods in the medical imaging domain. It provides a standardized evaluation protocol across **seven real-world medical image datasets**, including both **image-level anomaly classification (AnoCls)** and **pixel-level anomaly segmentation (AnoSeg)** tasks.
|
9 |
+
|
10 |
+
All datasets follow a **one-class training setting**, where **only normal (non-anomalous) images are available in the training set**, and the **test set includes both normal and abnormal cases**. This reflects real-world scenarios where anomalies are rare and not annotated during training.
|
11 |
+
|
12 |
+
The benchmark includes a total of **seven datasets**, spanning across various imaging modalities (X-ray, MRI, fundus, dermatoscopy, histopathology), and ensures unified data format and preprocessing to support fair and reproducible comparison of anomaly detection methods.
|
13 |
+
|
14 |
+
## Dataset Source
|
15 |
+
- **Homepage**: [https://github.com/caiyu6666/MedIAnomaly](https://github.com/caiyu6666/MedIAnomaly)
|
16 |
+
- **License**: [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0)
|
17 |
+
- **Paper**: Yu Cai et al. _MedIAnomaly: A Comparative Study of Anomaly Detection in Medical Images_, arXiv 2024.
|
18 |
+
|
19 |
+
## Dataset Structure
|
20 |
+
|
21 |
+
| Dataset | Modality | Task | 𝒟<sub>train</sub> | 𝒟<sub>test</sub> (Normal+Abnormal) |
|
22 |
+
|--------------|-----------------------|-------------------|------------------|----------------------------|
|
23 |
+
| RSNA | Chest X-ray | AnoCls | 3851 | 1000 + 1000 |
|
24 |
+
| VinDr-CXR | Chest X-ray | AnoCls | 4000 | 1000 + 1000 |
|
25 |
+
| Brain Tumor | Brain MRI | AnoCls | 1000 | 600 + 600 |
|
26 |
+
| LAG | Retinal fundus image | AnoCls | 1500 | 811 + 811 |
|
27 |
+
| ISIC2018 | Dermatoscopic image | AnoCls | 6705 | 909 + 603 |
|
28 |
+
| Camelyon16 | Histopathology image | AnoCls | 5088 | 1120 + 1113 |
|
29 |
+
| BraTS2021 | Brain MRI | AnoCls & AnoSeg | 4211 | 828 + 1948 |
|
30 |
+
|
31 |
+
### Notes on Dataset-Specific Definitions
|
32 |
+
|
33 |
+
- **RSNA**: Training images are all normal chest X-rays. Test set contains a balanced mix of normal and pneumonia images.
|
34 |
+
- **VinDr-CXR**: Training set consists only of normal chest X-rays. Test set includes both normal and abnormal findings.
|
35 |
+
- **Brain Tumor**: MRI scans. All training samples are healthy brains; test set contains normal and tumor cases.
|
36 |
+
- **LAG**: Retinal fundus images. Training set includes only normal cases; glaucomatous images appear in test set.
|
37 |
+
- **ISIC2018**: One-hot multi-label data. Only images with `NV = 1` and all other labels = 0 are considered **normal**. All others (with any other disease present) are considered **abnormal**.
|
38 |
+
- **Camelyon16**: Histopathological whole-slide patches. Training includes only benign tissue. Abnormal cancerous regions are tested.
|
39 |
+
- **BraTS2021**: Brain MRI for both classification and segmentation. Training includes only normal images. Test set includes tumor cases with segmentation masks.
|
40 |
+
|
41 |
+
## Example Usage
|
42 |
+
|
43 |
+
### RSNA
|
44 |
+
```python
|
45 |
+
from datasets import load_dataset
|
46 |
+
|
47 |
+
dataset = load_dataset("randall-lab/medianomaly", name="rsna", split="train", trust_remote_code=True)
|
48 |
+
# dataset = load_dataset("randall-lab/medianomaly", name="rsna", split="test", trust_remote_code=True)
|
49 |
+
|
50 |
+
# View a sample
|
51 |
+
example = dataset[0]
|
52 |
+
image = example["image"]
|
53 |
+
label = example["label"] # "normal" or "abnormal"
|
54 |
+
|
55 |
+
image.show()
|
56 |
+
print(f"Label: {label}")
|
57 |
+
```
|
58 |
+
|
59 |
+
### Vin-CXR
|
60 |
+
```python
|
61 |
+
from datasets import load_dataset
|
62 |
+
|
63 |
+
dataset = load_dataset("randall-lab/medianomaly", name="vincxr", split="train", trust_remote_code=True)
|
64 |
+
# dataset = load_dataset("randall-lab/medianomaly", name="vincxr", split="test", trust_remote_code=True)
|
65 |
+
|
66 |
+
# View a sample
|
67 |
+
example = dataset[0]
|
68 |
+
image = example["image"]
|
69 |
+
label = example["label"] # "normal" or "abnormal"
|
70 |
+
|
71 |
+
image.show()
|
72 |
+
print(f"Label: {label}")
|
73 |
+
```
|
74 |
+
|
75 |
+
### Brain Tumor
|
76 |
+
```python
|
77 |
+
from datasets import load_dataset
|
78 |
+
|
79 |
+
dataset = load_dataset("randall-lab/medianomaly", name="braintumor", split="train", trust_remote_code=True)
|
80 |
+
# dataset = load_dataset("randall-lab/medianomaly", name="braintumor", split="test", trust_remote_code=True)
|
81 |
+
|
82 |
+
# View a sample
|
83 |
+
example = dataset[0]
|
84 |
+
image = example["image"]
|
85 |
+
label = example["label"] # "normal" or "abnormal"
|
86 |
+
|
87 |
+
image.show()
|
88 |
+
print(f"Label: {label}")
|
89 |
+
```
|
90 |
+
|
91 |
+
### LAG
|
92 |
+
```python
|
93 |
+
from datasets import load_dataset
|
94 |
+
|
95 |
+
dataset = load_dataset("randall-lab/medianomaly", name="lag", split="train", trust_remote_code=True)
|
96 |
+
# dataset = load_dataset("randall-lab/medianomaly", name="lag", split="test", trust_remote_code=True)
|
97 |
+
|
98 |
+
# View a sample
|
99 |
+
example = dataset[0]
|
100 |
+
image = example["image"]
|
101 |
+
label = example["label"] # "normal" or "abnormal"
|
102 |
+
|
103 |
+
image.show()
|
104 |
+
print(f"Label: {label}")
|
105 |
+
```
|
106 |
+
|
107 |
+
### Camelyon16
|
108 |
+
```python
|
109 |
+
from datasets import load_dataset
|
110 |
+
|
111 |
+
dataset = load_dataset("randall-lab/medianomaly", name="camelyon16", split="train", trust_remote_code=True)
|
112 |
+
# dataset = load_dataset("randall-lab/medianomaly", name="camelyon16", split="test", trust_remote_code=True)
|
113 |
+
|
114 |
+
# View a sample
|
115 |
+
example = dataset[0]
|
116 |
+
image = example["image"]
|
117 |
+
label = example["label"] # "normal" or "abnormal"
|
118 |
+
|
119 |
+
image.show()
|
120 |
+
print(f"Label: {label}")
|
121 |
+
```
|
122 |
+
|
123 |
+
### BraTS2021
|
124 |
+
```python
|
125 |
+
from datasets import load_dataset
|
126 |
+
|
127 |
+
# Train
|
128 |
+
dataset = load_dataset("randall-lab/medianomaly", name="brats2021", split="train", trust_remote_code=True)
|
129 |
+
|
130 |
+
example = dataset[0]
|
131 |
+
image = example["image"]
|
132 |
+
label = example["label"] # "normal" or "abnormal"
|
133 |
+
|
134 |
+
image.show()
|
135 |
+
print(f"Label: {label}")
|
136 |
+
|
137 |
+
# Test
|
138 |
+
dataset = load_dataset("randall-lab/medianomaly", name="brats2021", split="test", trust_remote_code=True)
|
139 |
+
|
140 |
+
example = dataset[828] # >= 828 is abnormal images with seg mask
|
141 |
+
image = example["image"]
|
142 |
+
label = example["label"] # "normal" or "abnormal"
|
143 |
+
anno = example["annotation"] # None if label is 0, seg mask if label is 1
|
144 |
+
|
145 |
+
image.show()
|
146 |
+
anno.show()
|
147 |
+
print(f"Label: {label}")
|
148 |
+
```
|
149 |
+
|
150 |
+
### ISIC2018
|
151 |
+
```python
|
152 |
+
from datasets import load_dataset
|
153 |
+
|
154 |
+
dataset = load_dataset("randall-lab/medianomaly", name="isic2018_task3", split="train", trust_remote_code=True)
|
155 |
+
# dataset = load_dataset("randall-lab/medianomaly", name="isic2018_task3", split="test", trust_remote_code=True)
|
156 |
+
|
157 |
+
# View a sample
|
158 |
+
example = dataset[0]
|
159 |
+
image = example["image"]
|
160 |
+
label = example["label"] # "normal" or "abnormal"
|
161 |
+
labels = example["labels"] # one-hot multi label for different disease [MEL, NV, BCC, AKIEC, BKL, DF, VASC]
|
162 |
+
|
163 |
+
# Individual binary class labels (0 or 1)
|
164 |
+
mel_label = example["MEL"]
|
165 |
+
nv_label = example["NV"]
|
166 |
+
bcc_label = example["BCC"]
|
167 |
+
akiec_label = example["AKIEC"]
|
168 |
+
bkl_label = example["BKL"]
|
169 |
+
df_label = example["DF"]
|
170 |
+
vasc_label = example["VASC"]
|
171 |
+
|
172 |
+
image.show()
|
173 |
+
print(f"Label: {label}")
|
174 |
+
```
|
175 |
+
|
176 |
+
If you are using colab, you should update datasets to avoid errors
|
177 |
+
```
|
178 |
+
pip install -U datasets
|
179 |
+
```
|
180 |
+
## Citation
|
181 |
+
```
|
182 |
+
@article{cai2024medianomaly,
|
183 |
+
title={MedIAnomaly: A comparative study of anomaly detection in medical images},
|
184 |
+
author={Cai, Yu and Zhang, Weiwen and Chen, Hao and Cheng, Kwang-Ting},
|
185 |
+
journal={arXiv preprint arXiv:2404.04518},
|
186 |
+
year={2024}
|
187 |
+
}
|
188 |
+
```
|