Skip to content

Spherical U-Net for icosahedron discretized spherical surface data

Notifications You must be signed in to change notification settings

HenryVarro666/Spherical_U-Net

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spherical U-Net on Cortical Surfaces


conda create -n sunet2 python=3.8

pip install -U scikit-learn

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
python predict.py -hemi left -l 7 -i /mnt/d/Spherical_U-Net/examples/left_hemisphere/40962/test1.lh.40k.vtk -o 0715.vtk

This is the code for paper "Spherical U-Net on Cortical Surfaces: Methods and Applications".

How to use it

Prerequisites

  • Linux
  • NVIDIA GPU
  • CUDA CuDNN

Cc's Python Dependencies

  • python (3.8)
  • torch (2.2.1)
  • torchvision (0.17.1)
  • pyvista (0.43.4)
  • numpy (1.21.5)
  • scikit-learn (1.3.2)
  • vtk (9.0.3)

Python Dependencies

  • python (3.6)
  • pytorch (0.4.1+)
  • torchvision (0.2.1+)
  • tensorboardx (1.6+)
  • pyvista (0.22.4+)

You can use conda to easily create an environment for the experiment using following command:

conda create -n sunet python=3.6 
conda activate sunet
conda install pytorch torchvision cudatoolkit=10.0 -c pytorch
conda install -c conda-forge pyvista

Some basic tools can be found in the Spherical U‐Net package and installed from PyPI:

pip install sphericalunet

Data preparation

The input file is a cortical inner surface of one hemisphere in vtk format reconstructed from neuroimaging pipelines [1][2], which has been resampled as either 40,962 or 163,842 vertices. Two features, i.e., mean curvature and average convexity, are required for the parcellation, denoted as “curv” and “sulc” field attributes in the vtk file, respectively. For resampling and feature computing, FreeSurfer [2] can be used. To be consistent with the trained model, gyral crests should have negative curvature values, while sulcal bottoms should have positive curvature values.

Train

After data prepration, modify the train.py file to match the training data in your own path. Then, run:

python train.py

Test

You can easily obtain the output parcellation maps on your surfaces via the following commands. To predict a single surface’ parcellation map:

python predict.py -hemi left -l 7 -i input.vtk -o output.vtk

To predict the parcellation maps of multiple surfaces in the same folder:

python predict.py -hemi left -l 7 -in_folder in_folder -out_folder out_folder

You can also view the help information of the whole usage of this command by running

python predict.py -h
Usage: predict.py [-h] [--hemisphere {left,right}] [--level {7,8}]
                  [--input INPUT] [--in_folder INPUT_FOLDER] [--output OUTPUT] [--out_folder OUT_FOLDER]

Predict the parcellation maps with 36 regions from the input surfaces

optional arguments:
  -h, --help            show this help message and exit
  --hemisphere {left,right}, -hemi {left,right}
                        Specify the hemisphere for parcellation, left or
                        right. (default: left)
  --level {7,8}, -l {7,8}
                        Specify the level of the surfaces. Generally, level
                        7 spherical surface is with 40962 vertices, 8 is with
                        163842 vertices. (default: 7)
  --input INPUT, -i INPUT
                        filename of input surface (default: None)
  --in_folder INPUT_FOLDER, -in_folder INPUT_FOLDER
                        folder path for input files. Will parcelalte all the
                        files end in .vtk in this folder. Accept input or                        
                        in_folder. (default: None)
  --output OUTPUT, -o OUTPUT
                        Filename of ouput surface. (default: [input].parc.vtk)
  --out_folder OUT_FOLDER, -out_folder OUT_FOLDER
                        folder path for ouput surface. Accept output or
                        out_folder. (default: [in_folder])

Troubleshoot notes:

  1. The code requires input or in_folder option, not both, for single surface’ parcellation or all surfaces in the folder.
  2. The input data should be end in .vtk.

Examples

You can test the code using the example surfaces we provided in the examples folder. Simply run:

python predict.py -hemi left -l 7 -i examples/left_hemisphere/40962/test1.lh.40k.vtk

You will get the corresponding output surface at the same folder with name test1.lh.40k.parc.vtk. Or, run the command for all the 3 surface in the same folder:

python predict.py -hemi left -l 7 -in_folder examples/left_hemisphere/40962

Visualization

You can use Paraview software to visualize the parcellated surface in VTK format. An example of the input curvature map and output parcellation map are shown below. More usages about Paraview please refer to Paraview. paraview.

Data structure

The brain cortical surface lie in a non-Euclidean space represented by triangular meshes. CorticalSurface IcosahedronDiscretizedSphere

1-ring filter on sphere

The convolution on the spherical surface is performed baed on the 1-ring filter convoulution.

We provide 3 types of filter on the spherical surfaces. filters.

Spherical U-Net architecture

sphericaluent.

Cite

If you use this code for your research, please cite as:

Fenqiang Zhao, et.al. Spherical U-Net on Cortical Surfaces: Methods and Applications. Information Processing in Medical Imaging (IPMI), 2019.

Fenqiang Zhao, et.al. Spherical Deformable U-Net: Application to Cortical Surface Parcellation and Development Prediction. IEEE Transactions on Medical Imaging, 2021.

trackgit-views

Functions

  • check_sdf.py calculate SDF value on the sphere and then add to surf vtk

  • mv_hemi_npy.py archive npz files to six folders, lh & rh

Error

1

/home/cxc0366/fsl/lib/python3.11/site-packages/torch/nn/modules/loss.py:101: UserWarning: Using a target size (torch.Size([40962])) that is different to the input size (torch.Size([40962, 1])). This will likely lead to incorrect results due to broadcasting. Please ensure they have the same size. return F.l1_loss(input, target, reduction=self.reduction)

2

torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 87.51 GiB (GPU 0; 47.50 GiB total capacity; 29.21 MiB already allocated; 46.95 GiB free; 46.00 MiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF


npz error

Problem found in file: ./Test4/lh/fold1/130922.lh.InnerSurf.RegByFS.Resp40962_linemask_skeleton.npz Problem found in file: ./Test4/lh/fold5/130114.lh.InnerSurf.RegByFS.Resp40962_linemask_skeleton.npz

About

Spherical U-Net for icosahedron discretized spherical surface data

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 99.8%
  • Shell 0.2%