{"id":24583857,"url":"https://github.com/neuronets/cortexode-forked","last_synced_at":"2025-03-17T17:25:28.238Z","repository":{"id":200064153,"uuid":"704178527","full_name":"neuronets/cortexode-forked","owner":"neuronets","description":null,"archived":false,"fork":false,"pushed_at":"2023-10-14T04:14:21.000Z","size":85508,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-24T04:53:46.514Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/neuronets.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-12T17:46:19.000Z","updated_at":"2024-01-30T15:11:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"188090b5-7b7f-48c0-a394-99af1a7cc73c","html_url":"https://github.com/neuronets/cortexode-forked","commit_stats":null,"previous_names":["hvgazula/cortexode-forked","neuronets/cortexode-forked"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuronets%2Fcortexode-forked","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuronets%2Fcortexode-forked/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuronets%2Fcortexode-forked/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuronets%2Fcortexode-forked/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neuronets","download_url":"https://codeload.github.com/neuronets/cortexode-forked/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244076111,"owners_count":20394057,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-24T04:53:54.419Z","updated_at":"2025-03-17T17:25:28.213Z","avatar_url":"https://github.com/neuronets.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CortexODE: Learning Cortical Surface Reconstruction by Neural ODEs\n\n![](figure/diffeo.png)\n\n\nThis is the official PyTorch implementation of the paper:\n\n[CortexODE: Learning Cortical Surface Reconstruction by Neural ODEs](https://arxiv.org/abs/2202.08329)\n\nQiang Ma, Liu Li, Emma C. Robinson, Bernhard Kainz, Daniel Rueckert, Amir Alansary\n\n## Overview\nCortexODE leverages [Neural Ordinary Different Equations](https://arxiv.org/abs/1806.07366) (ODEs) to learn diffeomorphic flows for cortical surface reconstruction. The trajectories of the points on the surface are modeled as ODEs, where the derivatives of their coordinates are parameterized via a learnable Lipschitz-continuous *deformation network*. This provides theoretical guarantees for the prevention of surface self-intersections.\n\n![](figure/deform.png)\n\nCortexODE is integrated to an automatic learning-based pipeline. The pipeline utilizes a 3D U-Net to predict a white matter (WM) segmentation from brain MRI scans, and further generates a signed distance function (SDF) that represents an initial surface. Fast [topology correction](https://doi.org/10.1016/j.cmpb.2007.08.006) is used to guarantee the genus-0 topology. After isosurface extraction, two deformation networks are trained to deform the initial surface to white matter and pial surfaces respectively. \n\n![](figure/pipeline.png)\n\n## Installation\nThis implementation mainly relies on [PyTorch](https://pytorch.org/), [PyTorch3D](https://pytorch3d.org/) and [torchdiffeq](https://github.com/rtqichen/torchdiffeq) libraries. The dependencies can installed by running the following codes:\n```\nconda create --name cortexode\nsource activate cortexode\npip install -r requirements.txt\n```\nIn addition, the [PyTorch3D](https://github.com/facebookresearch/pytorch3d/blob/main/INSTALL.md) library (v0.4.0) should be installed manually.\n\n## Dataset\nCortexODE is validated on the [ADNI](https://adni.loni.usc.edu/), [HCP Young Adult](https://www.humanconnectome.org/study/hcp-young-adult) and [dHCP (3rd Release)](http://www.developingconnectome.org/data-release/third-data-release/) dataset. The data splits for training/validation/testing are given in ```./data/split```. For the ADNI and HCP datasets, the data should be in FreeSurfer format. We have provided an example data in ```./data/adni/test/subject_1```. \n\nFor a new dataset, please revise ```./data/preprocess.py``` to make sure the cortical surfaces match the MRI volume. For the data aligned to MNI-152 space, we recommend to use ```data_name='adni'``` with minor modification.\n\n\n## Evaluation\nWe have provided the pretrained models in ```./ckpts/pretrained``` for all datasets. To predict the cortical surfaces for the example ADNI data using pretrained models, please run\n\n``` bash\npython eval.py --test_type='pred' --data_dir='./data/adni/test/' --model_dir='./ckpts/pretrained/adni/' --result_dir='./ckpts/experiment_1/result/' --data_name='adni' --surf_hemi='lh' --tag='pretrained' --solver='euler' --step_size=0.1 --device='gpu'\n```\n\n```--data_dir``` is the path of the dataset. ```--model_dir``` is the path of saved models. ```--result_dir``` is the path to save the predicted surfaces (obj / stl / FreeSurfer format). Please refer to ```config.py``` for detailed configurations. To evaluate the ASSD, HD and self-intersections, please use\n\n``` bash\npython eval.py --test_type='eval' --data_dir='./data/adni/test/' --model_dir='./ckpts/pretrained/adni/' --data_name='adni' --surf_hemi='lh' --tag='pretrained' --solver='euler' --step_size=0.1 --device='gpu'\n```\nThe [torch-mesh-isect](https://github.com/vchoutas/torch-mesh-isect) package should be installed to detect the mesh self-intersections.\n\n\n## Training\nThe training of CortexODE models consists of segmentation, initial surface generation, and cortical surface reconstruction. The following instruction shows how to train CortexODE models on the ADNI dataset on left brain hemisphere.\n\n### Segmentation\nFor WM segmentation, please run the following code to train a 3D U-Net for 200 epochs:\n\n``` bash\npython train.py --train_type='seg' --data_dir='./data/adni/' --model_dir='./ckpts/experiment_1/model/' --data_name='adni' --n_epoch=200 --tag='exp1' --device='gpu'\n```\nwhere ```--model_dir``` is the path to save the model checkpoints. ```experiment_1``` and ```--tag='exp1'``` are the identity of the experiment. \n\n\n### Initial Surface Generation\nAfter training the WM segmentation, select the model with the best validation Dice score and run the following codes to create initial surfaces for both training and validation sets:\n\n``` bash\npython eval.py --test_type='init' --data_dir='./data/adni/train/' --model_dir='./ckpts/experiment_1/model/' --init_dir='./ckpts/experiment_1/init/train/' --data_name='adni' --surf_hemi='lh' --tag='exp1' --device='gpu'\n```\n``` bash\npython eval.py --test_type='init' --data_dir='./data/adni/valid/' --model_dir='./ckpts/experiment_1/model/'  --init_dir='./ckpts/experiment_1/init/valid/' --data_name='adni' --surf_hemi='lh' --tag='exp1' --device='gpu'\n```\nwhere ```--init_dir``` is the path to save the initial surfaces.\n\n### Cortical Surface Reconstruction\nWe train two deformation networks for WM and pial surface reconstruction. We use the *adjoint sensitivity method* proposed in [Neural ODEs](https://github.com/rtqichen/torchdiffeq) to train our models with constant GPU memory cost. To train CortexODE for WM surface reconstruction using Euler solver with step size h=0.1, you can use:\n\n``` bash\npython train.py --train_type='surf' --data_dir='./data/adni/' --model_dir='./ckpts/experiment_1/model/' --init_dir='./ckpts/experiment_1/init/' --data_name='adni'  --surf_hemi='lh' --surf_type='wm' --n_epochs=400 --n_samples=150000 --tag='exp1' --solver='euler' --step_size=0.1 --device='gpu'\n```\nwhere ```--init_dir``` is the path of the input initial surfaces, and ```--n_samples``` is the number of randomly sampled points to compute the Chamfer loss. For pial surface reconstruction, please run:\n``` bash\npython train.py --train_type='surf' --data_dir='./data/adni/' --model_dir='./ckpts/experiment_1/model/' --data_name='adni'  --surf_hemi='lh' --surf_type='gm' --n_epochs=400 --tag='exp1' --solver='euler' --step_size=0.1 --device='gpu'\n```\nNote that we use ```lr=1e-4``` as the learning rate to reduce the training time. Therefore, the curve of the validation error can highly oscillate. Please select the models with the best performance on the validation.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneuronets%2Fcortexode-forked","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneuronets%2Fcortexode-forked","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneuronets%2Fcortexode-forked/lists"}