Giter Club home page Giter Club logo

tractolearn's Introduction

tractolearn

test, package documentation DOI tractolearn DOI RBX Code format Imports: isort Code style: black

Tractography learning.

Installation

To use tractolearn, it is recommended to create a virtual environment using python 3.10 that will host the necessary dependencies. Torch tested with an NVIDIA RTX 3090 with:

   virtualenv tractolearn_env --python=python3.10
   source tractolearn_env/bin/activate

tractolearn can be installed from its sources by executing, at its root:

   pip install -e .
   pip install --upgrade numpy==1.23

Torch tested with an NVIDIA RTX 3090

   pip install torch==1.8.1+cu111 -f https://download.pytorch.org/whl/cu111/torch_stable.html

In order to execute experiments reporting to Comet, an api_key needs to be set as an environment variable named COMETML. You can write this command in you .bashrc

   export COMETML="api_key"

Training models

To train deep learning models, you need to launch the script ae_train.py. This script takes a config file with all training parameters such as epochs, datasets path, etc. The most up-to-date config file is config.yaml. You can launch the training pipeline with the following command:

   ae_train.py train_config.yaml -vv

Data

To automatically fetch or use the tractolearn data provided, you can use the retrieve_dataset method located in the tractolearn.tractoio.dataset_fetch module, or the dataset_fetch script, e.g.:

fetch_data contrastive_autoencoder_weights {my_path}

The datasets that can be automatically fetched and used are available in tractolearn.tractoio.dataset_fetch.Dataset.

Fetching the RecoBundlesX data is also made available.

How to cite

If you use this toolkit in a scientific publication or if you want to cite our previous works, we would appreciate if you considered the following aspects:

  • If you use tractolearn, please add a link to the appropriate code, data or related resource hosting service (e.g., repository, PyPI) from where you obtained tractolearn. You may want to include the specific version or commit hash information for the sake of reproducibility.
  • Please, cite the appropriate scientific works:
    • If you use tractolearn to filter implausible streamlines or you want to cite our work in tractography filtering, cite FINTA and FIESTA.
    • If you want to cite our work in tractography bundling, cite CINTA and FIESTA.
      • If you use tractolearn to bundle streamlines using a k-nearest neighbor label approach, cite CINTA.
      • If you use tractolearn to bundle streamlines using a thresholding approach, cite FINTA and FIESTA.
    • If you use tractolearn for generative purposes or you want to cite our work in generative models for tractography, cite GESTA and FIESTA.
    • If you use parts of tractolearn for other purposes, please generally cite FINTA and FIESTA.

The corresponding BibTeX files are contained in the above links.

If you use the data made available by the authors, please cite the appropriate Zenodo record.

Please reach out to us if you have related questions.

Patent

J. H. Legarreta, M. Descoteaux, and P.-M. Jodoin. “PROCESSING OF TRACTOGRAPHY RESULTS USING AN AUTOENCODER”. Filed 03 2021. Imeka Solutions Inc. United States Patent #17/337,413. Pending.

License

This software is distributed under a particular license. Please see the LICENSE file for details.

tractolearn's People

Contributors

felixdumais avatar jhlegarreta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

tractolearn's Issues

Mismatching type causes ae_find_thresholds.py to crash while joining path.

fname_root = pjoin(
experiment_dir, LoggerKeys.latent_plot_fname_label + "_trk"
)
fname_root_atlas = pjoin(
experiment_dir, LoggerKeys.latent_plot_fname_label + "_trk_atlas"
)

While running ae_find_thresholds, the script crashes due to LoggerKeys.latent_plot_fname_label being type <enum 'LoggerKeys'> and not string-like.
Changing to either LoggerKeys.latent_plot_fname_label.value or LoggerKeys.latent_plot_fname_label.name would probably fix the issue. I'm not sure whether the intention was to use value or the name.

Error:

Traceback (most recent call last):
  File "/tractolearn/scripts/ae_find_thresholds.py", line 497, in <module>
    main()
  File "/tractolearn/scripts/ae_find_thresholds.py", line 456, in main
    experiment_dir, LoggerKeys.latent_plot_fname_label + "_trk"
TypeError: unsupported operand type(s) for +: 'LoggerKeys' and 'str'

Provide appropriate regex patterns to the issue body labeler

The issue labeler https://github.com/github/issue-labeler requires JS regex patterns, and our https://github.com/scil-vital/tractolearn/blob/main/.github/labels.yml file uses globbing to identify the paths that are changed in a PR: https://github.com/actions/labeler.

Thus, the issue labeler is consistently failing, e.g.
https://github.com/scil-vital/tractolearn/actions/runs/4204834208/jobs/7296055735#step:2:7

with the message

SyntaxError: Invalid regular expression: /tractolearn/analysis/**/*/: Nothing to repeat

Thus, we could add a new .yaml file that uses JS regex instead of globbing for the issue labeler to fix the issue. However, this means duplicating the labels/patterns, and increasing the risk of going out-of-sync.

Alternatively, we could implement a script or use some npm package to transform the globbing into JS regexes, much like the PR and issue title scripts do.

If we do the script ourselves, this is an example of a pattern that is a valid JS regex:

/^\/tractolearn\/analysis\/[^]*/

for the files e.g.

/tractolearn/analysis/__init__.py
/tractolearn/analysis/file.py
/tractolearn/analysis/tests/__init__.py
/tractolearn/analysis/tests/test_file.py

Filter target tractograms depending on the provided anatomy file

A user reported that when using the downloaded RBx atlas and some custom target (test) dataset, the ae_bundle_streamlines.py script failed with the following output:

Namespace(anatomy_file='/root/tractolearn_data/rbx_atlas_v10.json',
atlas_path='/root/tractolearn_data/atlas/pop_average', batch_loading=None,
common_space_reference='/testdata/subj01/T1.nii.gz',
common_space_tractogram='/testdata/subj02/tracts100k.trk', device='cpu',
model='/root/tractolearn_data/best_model_contrastive_tractoinferno_hcp.pt',
num_neighbors=1, original_reference=None,
original_tractogram=None, output='test', overwrite=True,
thresholds_file='/root/tractolearn_data/thresholds_contrastive_tractoinferno_hcp.json', verbose=False)
INFO:root:Loading atlas files ...
  0%|                   
| 0/52 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "/usr/local/bin/ae_bundle_streamlines", line 8, in <module>
    sys.exit(ae_bundle_streamlines.main())
  File "/tractolearn/scripts/ae_bundle_streamlines.py", line 397, in main
    assert (
AssertionError: [!] Threshold: fornix_group not in threshold file

The issue stems from the fact that when looping over the atlas path files in the script, there is a fornix_group.trk that is being found in the /atlas/pop_average RBx path, and such tractogram does not correspond to any entry in the JSON anatomy config file (or any other config file provided in zenodo actually). The RBx atlas path contains some "*_group.trk" files that are the concatenation of some other files, and we are not interested in considering those in tractolearn, at least within the context of the provided data in zenodo.

Thus, we should

  • Make sure that all config files involved in a process contain all the bundles indicated in the anatomy file. It could be a pre-check utils method that can be re-used across scripts.
  • As we are expecting for exact filename matches with the anatomy config file, we could filter any other file present in a given folder and, inform the user about the presence of other files in the atlas folder that do not correspond to the bundle names in the anatomy config files. Requiring that the folder only contains the bundles of interest and failing otherwise may be another option; however, since the contents of a given path may come from another process unrelated to tractolearn it may not be desirable to force users to remove such files from the path.

Adapt/provide a script to perform plausible/implausible filtering

Some people might want to perform only plausible vs. implausible streamline filtering, and later use a bundling strategy (definition, atlas, etc.) that is different from the one we have made available.

Should also be documented.

This should also be made available in the Nextflow pipeline, so the bundling and the generative parts should be optional.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.