Code updates
Browse files
README.md
CHANGED
@@ -12,92 +12,82 @@ pretty_name: 3D Brain Structure MRI PCA
|
|
12 |
---
|
13 |
|
14 |
## 🧠 Model Summary
|
15 |
-
#
|
16 |
A linear PCA model for brain structure T1 MRIs. The models takes in a 3d MRI NIfTI file and compresses to 1200 latent dimensions before reconstructing the image.
|
17 |
|
18 |
|
19 |
# Training data
|
20 |
-
[
|
21 |
|
22 |
# Example usage
|
23 |
```
|
24 |
-
# get
|
25 |
-
git clone https://huggingface.co/radiata-ai/
|
26 |
-
cd
|
27 |
|
28 |
# set up virtual environemt
|
29 |
-
python3 -m venv
|
30 |
-
source
|
31 |
|
32 |
# install Python libraries
|
33 |
pip install -r requirements.txt
|
34 |
|
35 |
# create the csv file inputs.csv listing the scan paths and other info
|
36 |
-
# this script loads the radiata-ai/brain-structure dataset
|
37 |
python create_csv.py
|
38 |
|
39 |
-
mkdir
|
40 |
-
mkdir
|
41 |
|
42 |
# train the model
|
43 |
-
nohup python
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
55 |
```
|
56 |
|
57 |
# Methods
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
lr: float = 1e-4,
|
65 |
-
|
66 |
-
# References
|
67 |
-
Puglisi
|
68 |
-
Pinaya
|
69 |
|
70 |
# Citation
|
71 |
```
|
72 |
-
@
|
73 |
author = {Jesse Brown and Clayton Young},
|
74 |
-
title = {
|
75 |
year = {2025},
|
76 |
-
url
|
77 |
note = {Version 1.0},
|
78 |
-
publisher
|
79 |
}
|
80 |
```
|
81 |
|
82 |
# License
|
83 |
-
|
84 |
-
|
85 |
-
Copyright
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
99 |
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
100 |
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
101 |
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
102 |
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
103 |
-
SOFTWARE.
|
|
|
12 |
---
|
13 |
|
14 |
## 🧠 Model Summary
|
15 |
+
# brain2vec_PCA
|
16 |
A linear PCA model for brain structure T1 MRIs. The models takes in a 3d MRI NIfTI file and compresses to 1200 latent dimensions before reconstructing the image.
|
17 |
|
18 |
|
19 |
# Training data
|
20 |
+
[radiata-ai/brain-structure](https://huggingface.co/datasets/radiata-ai/brain-structure): 3066 scans from 2085 individuals in the 'train' split. Mean age = 45.1 +- 24.5, including 2847 scans from cognitively normal subjects and 219 scans from individuals with an Alzheimer's disease clinical diagnosis.
|
21 |
|
22 |
# Example usage
|
23 |
```
|
24 |
+
# get brain2vec_PCA model repository
|
25 |
+
git clone https://huggingface.co/radiata-ai/brain2vec_PCA
|
26 |
+
cd brain2vec_PCA
|
27 |
|
28 |
# set up virtual environemt
|
29 |
+
python3 -m venv venv_brain2vec_PCA
|
30 |
+
source venv_brain2vec_PCA/bin/activate
|
31 |
|
32 |
# install Python libraries
|
33 |
pip install -r requirements.txt
|
34 |
|
35 |
# create the csv file inputs.csv listing the scan paths and other info
|
36 |
+
# this script loads the radiata-ai/brain-structure dataset from Hugging Face
|
37 |
python create_csv.py
|
38 |
|
39 |
+
mkdir pca_cache
|
40 |
+
mkdir pca_output
|
41 |
|
42 |
# train the model
|
43 |
+
nohup python train_brain2vec_PCA.py --inputs_csv inputs.csv --output_dir ./pca_output --pca_type standard --n_components 1200 > train_log.txt 2>&1 &
|
44 |
+
|
45 |
+
# model inference
|
46 |
+
python inference_brain2vec_PCA.py \
|
47 |
+
--pca_model /path/to/pca_model.joblib \
|
48 |
+
--input_images /path/to/img1.nii.gz /path/to/img2.nii.gz \
|
49 |
+
--output_dir /path/to/out
|
50 |
+
|
51 |
+
# or if you have a CSV with image paths:
|
52 |
+
python inference_brain2vec_PCA.py \
|
53 |
+
--pca_model /path/to/pca_model.joblib \
|
54 |
+
--csv_input /path/to/images.csv \
|
55 |
+
--output_dir /path/to/out
|
56 |
```
|
57 |
|
58 |
# Methods
|
59 |
+
Input scan image dimensions are 113x137x113, 1.5mm^3 resolution, aligned to MNI152 space (see [radiata-ai/brain-structure](https://huggingface.co/datasets/radiata-ai/brain-structure)).
|
60 |
+
|
61 |
+
The image transform crops to 80 x 96 x 80, 2mm^3 resolution, and scales image intensity to range [0,1].
|
62 |
+
|
63 |
+
PCA is performed using [sklearn.decomposition.PCA](https://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html).
|
64 |
+
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
# Citation
|
67 |
```
|
68 |
+
@misc{Radiata-Brain2Vec-PCA,
|
69 |
author = {Jesse Brown and Clayton Young},
|
70 |
+
title = {brain2vec_PCA: A Linear PCA Model for Brain Structure T1 MRIs},
|
71 |
year = {2025},
|
72 |
+
url = {https://huggingface.co/radiata-ai/brain2vec_PCA},
|
73 |
note = {Version 1.0},
|
74 |
+
publisher = {Hugging Face}
|
75 |
}
|
76 |
```
|
77 |
|
78 |
# License
|
79 |
+
### Apache License 2.0
|
80 |
+
|
81 |
+
Copyright 2025 Jesse Brown
|
82 |
+
|
83 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
84 |
+
you may not use this file except in compliance with the License.
|
85 |
+
You may obtain a copy of the License at:
|
86 |
+
|
87 |
+
[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
|
88 |
+
|
89 |
+
Unless required by applicable law or agreed to in writing, software
|
90 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
91 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
92 |
+
See the License for the specific language governing permissions and
|
93 |
+
limitations under the License.
|
|
|
|
|
|
|
|
|
|
|
|