Add files using upload-large-folder tool
Browse files- README.md +1 -1
- brain-structure.py +32 -38
README.md
CHANGED
@@ -12,7 +12,7 @@ pretty_name: 3D Brain Structure MRI Scans
|
|
12 |
---
|
13 |
|
14 |
## 🧠 Dataset Summary
|
15 |
-
3794 3D structural MRI brain scans (T1-weighted MPRAGE NIfTI files) from 2607 individuals included in five publicly available datasets: [
|
16 |
|
17 |
Scans have been processed and all protected health information (PHI) is excluded. Only the skull-stripped scan, integer age, biological sex, clinical diagnosis, and scan metadata are included. [Radiata](https://radiata.ai/) compiles and processes publicly available neuroimaging datasets to create this open, unified, and harmonized dataset. For more information see https://radiata.ai/public-studies. Example uses including developing foundation-like models or tailored models for brain age prediction and disease classification.
|
18 |
|
|
|
12 |
---
|
13 |
|
14 |
## 🧠 Dataset Summary
|
15 |
+
3794 3D structural MRI brain scans (T1-weighted MPRAGE NIfTI files) from 2607 individuals included in five publicly available datasets: [DLBS](https://fcon_1000.projects.nitrc.org/indi/retro/dlbs.html), [IXI](https://brain-development.org/ixi-dataset/), [NKI-RS](https://fcon_1000.projects.nitrc.org/indi/enhanced/sharing_neuro.html), [OASIS-1](https://sites.wustl.edu/oasisbrains/home/oasis-1/), and [OASIS-2](https://sites.wustl.edu/oasisbrains/home/oasis-2/). Subjects have a mean age of 45 ± 24. 3773 scans come from cognitively normal individuals and 261 scans from individuals with an Alzheimer's disease clinical diagnosis. Scans dimensions are 113x137x113, 1.5mm^3 resolution, aligned to MNI152 space (see methods).
|
16 |
|
17 |
Scans have been processed and all protected health information (PHI) is excluded. Only the skull-stripped scan, integer age, biological sex, clinical diagnosis, and scan metadata are included. [Radiata](https://radiata.ai/) compiles and processes publicly available neuroimaging datasets to create this open, unified, and harmonized dataset. For more information see https://radiata.ai/public-studies. Example uses including developing foundation-like models or tailored models for brain age prediction and disease classification.
|
18 |
|
brain-structure.py
CHANGED
@@ -1,14 +1,14 @@
|
|
1 |
import os
|
2 |
import json
|
3 |
-
import datasets
|
4 |
import logging
|
|
|
5 |
|
6 |
logger = logging.getLogger(__name__)
|
7 |
|
8 |
_DESCRIPTION = """
|
9 |
This dataset contains T1-weighted .nii.gz structural MRI scans in a BIDS-like arrangement.
|
10 |
-
Each scan has an associated JSON sidecar with metadata, including
|
11 |
-
|
12 |
"""
|
13 |
|
14 |
_CITATION = """
|
@@ -16,7 +16,7 @@ _CITATION = """
|
|
16 |
author = {Jesse Brown and Clayton Young},
|
17 |
title = {Brain-Structure: A Collection of Processed Structural MRI Scans},
|
18 |
year = {2025},
|
19 |
-
url
|
20 |
note = {Version 1.0},
|
21 |
publisher = {Hugging Face}
|
22 |
}
|
@@ -25,21 +25,21 @@ _CITATION = """
|
|
25 |
_HOMEPAGE = "https://huggingface.co/datasets/radiata-ai/brain-structure"
|
26 |
_LICENSE = "ODC-By v1.0"
|
27 |
|
|
|
28 |
class BrainStructureConfig(datasets.BuilderConfig):
|
29 |
"""
|
30 |
Configuration class for the Brain-Structure dataset.
|
31 |
-
You can define multiple configurations if needed (e.g
|
32 |
"""
|
33 |
def __init__(self, **kwargs):
|
34 |
super().__init__(**kwargs)
|
35 |
|
|
|
36 |
class BrainStructure(datasets.GeneratorBasedBuilder):
|
37 |
"""
|
38 |
-
A dataset loader for T1 .nii.gz files plus JSON sidecars
|
39 |
-
|
40 |
-
belongs to the train, validation, or test set.
|
41 |
|
42 |
-
Usage Example:
|
43 |
ds = load_dataset(
|
44 |
"radiata-ai/brain-structure",
|
45 |
name="all",
|
@@ -49,22 +49,20 @@ class BrainStructure(datasets.GeneratorBasedBuilder):
|
|
49 |
"""
|
50 |
|
51 |
VERSION = datasets.Version("1.0.0")
|
|
|
|
|
52 |
BUILDER_CONFIGS = [
|
53 |
BrainStructureConfig(
|
54 |
name="all",
|
55 |
version=VERSION,
|
56 |
-
description=
|
57 |
-
"All structural MRI data in a BIDS-like arrangement, labeled "
|
58 |
-
"with train/validation/test splits."
|
59 |
-
),
|
60 |
),
|
61 |
]
|
62 |
DEFAULT_CONFIG_NAME = "all"
|
63 |
|
64 |
def _info(self):
|
65 |
"""
|
66 |
-
|
67 |
-
and general dataset information.
|
68 |
"""
|
69 |
return datasets.DatasetInfo(
|
70 |
description=_DESCRIPTION,
|
@@ -102,34 +100,35 @@ class BrainStructure(datasets.GeneratorBasedBuilder):
|
|
102 |
|
103 |
def _split_generators(self, dl_manager: datasets.DownloadManager):
|
104 |
"""
|
105 |
-
|
106 |
-
|
|
|
107 |
"""
|
108 |
-
|
|
|
|
|
|
|
|
|
109 |
|
110 |
return [
|
111 |
datasets.SplitGenerator(
|
112 |
name=datasets.Split.TRAIN,
|
113 |
-
gen_kwargs={"data_dir": data_dir, "desired_split": "train"}
|
114 |
),
|
115 |
datasets.SplitGenerator(
|
116 |
name=datasets.Split.VALIDATION,
|
117 |
-
gen_kwargs={"data_dir": data_dir, "desired_split": "validation"}
|
118 |
),
|
119 |
datasets.SplitGenerator(
|
120 |
name=datasets.Split.TEST,
|
121 |
-
gen_kwargs={"data_dir": data_dir, "desired_split": "test"}
|
122 |
),
|
123 |
]
|
124 |
|
125 |
def _generate_examples(self, data_dir, desired_split):
|
126 |
"""
|
127 |
-
Recursively
|
128 |
-
examples
|
129 |
-
|
130 |
-
Each yielded example includes:
|
131 |
-
- 'nii_filepath': pointing to the corresponding .nii.gz file
|
132 |
-
- 'metadata': dictionary of subject and scan information
|
133 |
"""
|
134 |
id_ = 0
|
135 |
for root, dirs, files in os.walk(data_dir):
|
@@ -139,26 +138,21 @@ class BrainStructure(datasets.GeneratorBasedBuilder):
|
|
139 |
with open(sidecar_path, "r") as f:
|
140 |
sidecar = json.load(f)
|
141 |
|
142 |
-
# Only yield if 'split' matches the
|
143 |
if sidecar.get("split") == desired_split:
|
144 |
-
#
|
145 |
-
|
146 |
-
# and the NIfTI file: sub-xxx_ses-xxx_T1w.nii.gz
|
147 |
-
possible_nii_prefix = fname.replace("_scandata.json", "_T1w")
|
148 |
nii_filepath = None
|
149 |
for potential_file in files:
|
150 |
-
if (potential_file.startswith(
|
151 |
and potential_file.endswith(".nii.gz")):
|
152 |
nii_filepath = os.path.join(root, potential_file)
|
153 |
break
|
154 |
|
155 |
if not nii_filepath:
|
156 |
-
logger.warning(
|
157 |
-
f"No corresponding .nii.gz file found for {sidecar_path}"
|
158 |
-
)
|
159 |
continue
|
160 |
|
161 |
-
# Build the example
|
162 |
yield id_, {
|
163 |
"id": str(id_),
|
164 |
"nii_filepath": nii_filepath,
|
@@ -167,7 +161,7 @@ class BrainStructure(datasets.GeneratorBasedBuilder):
|
|
167 |
"participant_id": sidecar.get("participant_id", ""),
|
168 |
"session_id": sidecar.get("session_id", ""),
|
169 |
"study": sidecar.get("study", ""),
|
170 |
-
"age": sidecar.get("age", 0),
|
171 |
"sex": sidecar.get("sex", ""),
|
172 |
"clinical_diagnosis": sidecar.get("clinical_diagnosis", ""),
|
173 |
"scanner_manufacturer": sidecar.get("scanner_manufacturer", ""),
|
|
|
1 |
import os
|
2 |
import json
|
|
|
3 |
import logging
|
4 |
+
import datasets
|
5 |
|
6 |
logger = logging.getLogger(__name__)
|
7 |
|
8 |
_DESCRIPTION = """
|
9 |
This dataset contains T1-weighted .nii.gz structural MRI scans in a BIDS-like arrangement.
|
10 |
+
Each scan has an associated JSON sidecar with metadata, including a 'split' field indicating
|
11 |
+
whether it's train, validation, or test.
|
12 |
"""
|
13 |
|
14 |
_CITATION = """
|
|
|
16 |
author = {Jesse Brown and Clayton Young},
|
17 |
title = {Brain-Structure: A Collection of Processed Structural MRI Scans},
|
18 |
year = {2025},
|
19 |
+
url = {https://huggingface.co/datasets/radiata-ai/brain-structure},
|
20 |
note = {Version 1.0},
|
21 |
publisher = {Hugging Face}
|
22 |
}
|
|
|
25 |
_HOMEPAGE = "https://huggingface.co/datasets/radiata-ai/brain-structure"
|
26 |
_LICENSE = "ODC-By v1.0"
|
27 |
|
28 |
+
|
29 |
class BrainStructureConfig(datasets.BuilderConfig):
|
30 |
"""
|
31 |
Configuration class for the Brain-Structure dataset.
|
32 |
+
You can define multiple configurations if needed (e.g., different subsets).
|
33 |
"""
|
34 |
def __init__(self, **kwargs):
|
35 |
super().__init__(**kwargs)
|
36 |
|
37 |
+
|
38 |
class BrainStructure(datasets.GeneratorBasedBuilder):
|
39 |
"""
|
40 |
+
A dataset loader for T1 .nii.gz files plus JSON sidecars indicating splits
|
41 |
+
(train, validation, test). Usage example:
|
|
|
42 |
|
|
|
43 |
ds = load_dataset(
|
44 |
"radiata-ai/brain-structure",
|
45 |
name="all",
|
|
|
49 |
"""
|
50 |
|
51 |
VERSION = datasets.Version("1.0.0")
|
52 |
+
|
53 |
+
# If you do NOT need multiple configs, you can define just one here:
|
54 |
BUILDER_CONFIGS = [
|
55 |
BrainStructureConfig(
|
56 |
name="all",
|
57 |
version=VERSION,
|
58 |
+
description="All structural MRI data in a BIDS-like arrangement, labeled with train/val/test splits."
|
|
|
|
|
|
|
59 |
),
|
60 |
]
|
61 |
DEFAULT_CONFIG_NAME = "all"
|
62 |
|
63 |
def _info(self):
|
64 |
"""
|
65 |
+
Returns DatasetInfo, including feature types and other meta information.
|
|
|
66 |
"""
|
67 |
return datasets.DatasetInfo(
|
68 |
description=_DESCRIPTION,
|
|
|
100 |
|
101 |
def _split_generators(self, dl_manager: datasets.DownloadManager):
|
102 |
"""
|
103 |
+
Creates SplitGenerators for train, validation, and test.
|
104 |
+
No remote download is performed here. Instead, we reference
|
105 |
+
the local directory containing this script.
|
106 |
"""
|
107 |
+
# Typically, we use dl_manager.download_and_extract(...) for remote data,
|
108 |
+
# but here we assume the data is already in the same repo as this script.
|
109 |
+
|
110 |
+
# Path to the folder containing this script (and presumably the data).
|
111 |
+
data_dir = os.path.abspath(os.path.dirname(__file__))
|
112 |
|
113 |
return [
|
114 |
datasets.SplitGenerator(
|
115 |
name=datasets.Split.TRAIN,
|
116 |
+
gen_kwargs={"data_dir": data_dir, "desired_split": "train"}
|
117 |
),
|
118 |
datasets.SplitGenerator(
|
119 |
name=datasets.Split.VALIDATION,
|
120 |
+
gen_kwargs={"data_dir": data_dir, "desired_split": "validation"}
|
121 |
),
|
122 |
datasets.SplitGenerator(
|
123 |
name=datasets.Split.TEST,
|
124 |
+
gen_kwargs={"data_dir": data_dir, "desired_split": "test"}
|
125 |
),
|
126 |
]
|
127 |
|
128 |
def _generate_examples(self, data_dir, desired_split):
|
129 |
"""
|
130 |
+
Recursively walks data_dir, locates JSON sidecar files, and yields
|
131 |
+
examples that match the specified 'desired_split'.
|
|
|
|
|
|
|
|
|
132 |
"""
|
133 |
id_ = 0
|
134 |
for root, dirs, files in os.walk(data_dir):
|
|
|
138 |
with open(sidecar_path, "r") as f:
|
139 |
sidecar = json.load(f)
|
140 |
|
141 |
+
# Only yield if 'split' matches the requested split
|
142 |
if sidecar.get("split") == desired_split:
|
143 |
+
# Locate corresponding NIfTI .nii.gz
|
144 |
+
nii_prefix = fname.replace("_scandata.json", "_T1w")
|
|
|
|
|
145 |
nii_filepath = None
|
146 |
for potential_file in files:
|
147 |
+
if (potential_file.startswith(nii_prefix)
|
148 |
and potential_file.endswith(".nii.gz")):
|
149 |
nii_filepath = os.path.join(root, potential_file)
|
150 |
break
|
151 |
|
152 |
if not nii_filepath:
|
153 |
+
logger.warning(f"No .nii.gz found for {sidecar_path}")
|
|
|
|
|
154 |
continue
|
155 |
|
|
|
156 |
yield id_, {
|
157 |
"id": str(id_),
|
158 |
"nii_filepath": nii_filepath,
|
|
|
161 |
"participant_id": sidecar.get("participant_id", ""),
|
162 |
"session_id": sidecar.get("session_id", ""),
|
163 |
"study": sidecar.get("study", ""),
|
164 |
+
"age": sidecar.get("age", 0),
|
165 |
"sex": sidecar.get("sex", ""),
|
166 |
"clinical_diagnosis": sidecar.get("clinical_diagnosis", ""),
|
167 |
"scanner_manufacturer": sidecar.get("scanner_manufacturer", ""),
|