Datasets:
Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
---
|
|
|
|
| 2 |
license: cc-by-4.0
|
| 3 |
task_categories:
|
| 4 |
- image-classification
|
|
@@ -125,3 +126,119 @@ dataset_info:
|
|
| 125 |
download_size: 1266898242525
|
| 126 |
dataset_size: 1226435862593.624
|
| 127 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
|
| 3 |
license: cc-by-4.0
|
| 4 |
task_categories:
|
| 5 |
- image-classification
|
|
|
|
| 126 |
download_size: 1266898242525
|
| 127 |
dataset_size: 1226435862593.624
|
| 128 |
---
|
| 129 |
+
|
| 130 |
+
# TAIX-Ray Dataset
|
| 131 |
+
|
| 132 |
+
TAIX-Ray is a comprehensive dataset of about 200k bedside chest radiographs from about 50k intensive care patients at the University Hospital in Aachen, Germany, collected between 2010 and 2024.
|
| 133 |
+
Trained radiologists provided structured reports at the time of acquisition, assessing key findings such as cardiomegaly, pulmonary congestion, pleural effusion, pulmonary opacities, and atelectasis on an ordinal scale.
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
<br>
|
| 137 |
+
|
| 138 |
+
## Code & Details:
|
| 139 |
+
The code for data loading, preprocessing, and baseline experiments is available at: https://github.com/mueller-franzes/TAIX-Ray
|
| 140 |
+
|
| 141 |
+
## How to Use
|
| 142 |
+
|
| 143 |
+
### Prerequisites
|
| 144 |
+
Ensure you have the following dependencies installed:
|
| 145 |
+
|
| 146 |
+
```bash
|
| 147 |
+
pip install datasets matplotlib huggingface_hub pandas tqdm
|
| 148 |
+
```
|
| 149 |
+
|
| 150 |
+
### Configurations
|
| 151 |
+
This dataset is available in two configurations.
|
| 152 |
+
|
| 153 |
+
| **Name** | **Size** | **Image Size** |
|
| 154 |
+
|------------|----------|----------------|
|
| 155 |
+
| default | 62GB | 512px |
|
| 156 |
+
| original | 1.2TB | variable |
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
### Option A: Use within the Hugging Face Framework
|
| 160 |
+
If you want to use the dataset directly within the Hugging Face `datasets` library, you can load and visualize it as follows:
|
| 161 |
+
|
| 162 |
+
```python
|
| 163 |
+
from datasets import load_dataset
|
| 164 |
+
from matplotlib import pyplot as plt
|
| 165 |
+
|
| 166 |
+
# Load the TAIX-Ray dataset
|
| 167 |
+
dataset = load_dataset("TLAIM/TAIX-Ray", name="default")
|
| 168 |
+
|
| 169 |
+
# Access the training split (Fold 0)
|
| 170 |
+
ds_train = dataset['train']
|
| 171 |
+
|
| 172 |
+
# Retrieve a single sample from the training set
|
| 173 |
+
item = ds_train[0]
|
| 174 |
+
|
| 175 |
+
# Extract and display the image
|
| 176 |
+
image = item['Image']
|
| 177 |
+
plt.imshow(image, cmap='gray')
|
| 178 |
+
plt.savefig('image.png') # Save the image to a file
|
| 179 |
+
plt.show() # Display the image
|
| 180 |
+
|
| 181 |
+
# Print metadata (excluding the image itself)
|
| 182 |
+
for key in item.keys():
|
| 183 |
+
if key != 'Image':
|
| 184 |
+
print(f"{key}: {item[key]}")
|
| 185 |
+
```
|
| 186 |
+
|
| 187 |
+
### Option B: Downloading the Dataset
|
| 188 |
+
|
| 189 |
+
If you prefer to download the dataset to a specific folder, use the following script. This will create the following folder structure:
|
| 190 |
+
```
|
| 191 |
+
.
|
| 192 |
+
├── data/
|
| 193 |
+
│ ├── 549a816ae020fb7da68a31d7d62d73c418a069c77294fc084dd9f7bd717becb9.png
|
| 194 |
+
│ ├── d8546c6108aad271211da996eb7e9eeabaf44d39cf0226a4301c3cbe12d84151.png
|
| 195 |
+
│ └── ...
|
| 196 |
+
└── metadata/
|
| 197 |
+
├── annoation.csv
|
| 198 |
+
└── split.csv
|
| 199 |
+
```
|
| 200 |
+
|
| 201 |
+
```python
|
| 202 |
+
from datasets import load_dataset
|
| 203 |
+
from huggingface_hub import hf_hub_download
|
| 204 |
+
from pathlib import Path
|
| 205 |
+
import pandas as pd
|
| 206 |
+
from tqdm import tqdm
|
| 207 |
+
|
| 208 |
+
# Define output paths
|
| 209 |
+
output_root = Path("./TAIX-Ray")
|
| 210 |
+
|
| 211 |
+
# Create folders
|
| 212 |
+
data_dir = output_root / "data"
|
| 213 |
+
metadata_dir = output_root / "metadata"
|
| 214 |
+
data_dir.mkdir(parents=True, exist_ok=True)
|
| 215 |
+
metadata_dir.mkdir(parents=True, exist_ok=True)
|
| 216 |
+
|
| 217 |
+
# Load dataset in streaming mode
|
| 218 |
+
dataset = dataset = load_dataset("TLAIM/TAIX-Ray", name="default", streaming=True)
|
| 219 |
+
|
| 220 |
+
# Process dataset
|
| 221 |
+
metadata = []
|
| 222 |
+
for split, split_dataset in dataset.items():
|
| 223 |
+
print("-------- Start Download: ", split, " --------")
|
| 224 |
+
for item in tqdm(split_dataset, desc="Downloading"): # Stream data one-by-one
|
| 225 |
+
uid = item["UID"]
|
| 226 |
+
img = item.pop("Image") # PIL Image object
|
| 227 |
+
|
| 228 |
+
# Save image
|
| 229 |
+
img.save(data_dir / f"{uid}.png", format="PNG")
|
| 230 |
+
|
| 231 |
+
# Store metadata
|
| 232 |
+
metadata.append(item)
|
| 233 |
+
|
| 234 |
+
# Convert metadata to DataFrame
|
| 235 |
+
metadata_df = pd.DataFrame(metadata)
|
| 236 |
+
|
| 237 |
+
# Save annotations to CSV files
|
| 238 |
+
metadata_df.drop(columns=["Split", "Fold"]).to_csv(metadata_dir / "annotation.csv", index=False)
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
print("Dataset streamed and saved successfully!")
|
| 242 |
+
```
|
| 243 |
+
|
| 244 |
+
|