jesseab commited on
Commit
b7c12bb
·
1 Parent(s): 0178b19

Code updates

Browse files
Files changed (1) hide show
  1. README.md +48 -58
README.md CHANGED
@@ -12,92 +12,82 @@ pretty_name: 3D Brain Structure MRI PCA
12
  ---
13
 
14
  ## 🧠 Model Summary
15
- # brain2vec
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 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 model repository
25
- git clone https://huggingface.co/radiata-ai/brain2vec
26
- cd brain2vec
27
 
28
  # set up virtual environemt
29
- python3 -m venv venv_brain2vec
30
- source venv_brain2vec/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
37
  python create_csv.py
38
 
39
- mkdir ae_cache
40
- mkdir ae_output
41
 
42
  # train the model
43
- nohup python brain2vec.py train \
44
- --dataset_csv /home/ubuntu/brain2vec/inputs.csv \
45
- --cache_dir ./ae_cache \
46
- --output_dir ./ae_output \
47
- --n_epochs 10 \
48
- > train_log.txt 2>&1 &
49
-
50
- # run model inference to create *_embeddings.npz files
51
- python brain2vec.py infererence \
52
- --dataset_csv home/ubuntu/brain2vec/inputs.csv \
53
- --aekl_ckpt /home/ubuntu/brain2vec/autoencoder_final.pth \
54
- --output_dir /home/ubuntu/brain2vec
 
55
  ```
56
 
57
  # Methods
58
- transform:
59
- (80, 96, 80)
60
- pixdim=2
61
- 10 epochs
62
- max_batch_size: int = 2,
63
- batch_size: int = 16,
64
- lr: float = 1e-4,
65
-
66
- # References
67
- Puglisi
68
- Pinaya
69
 
70
  # Citation
71
  ```
72
- @dataset{Radiata-Brain-Structure,
73
  author = {Jesse Brown and Clayton Young},
74
- title = {Brain-Structure: Processed Structural MRI Brain Scans Across the Lifespan},
75
  year = {2025},
76
- url = {https://huggingface.co/datasets/radiata-ai/brain-structure},
77
  note = {Version 1.0},
78
- publisher = {Hugging Face}
79
  }
80
  ```
81
 
82
  # License
83
- MIT License
84
-
85
- Copyright (c) 2025
86
-
87
- Permission is hereby granted, free of charge, to any person obtaining a copy
88
- of this software and associated documentation files (the "Software"), to deal
89
- in the Software without restriction, including without limitation the rights
90
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
91
- copies of the Software, and to permit persons to whom the Software is
92
- furnished to do so, subject to the following conditions:
93
-
94
- The above copyright notice and this permission notice shall be included in all
95
- copies or substantial portions of the Software.
96
-
97
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
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.