Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MS CAPS MAPS FOR MOOD #637

Draft
wants to merge 252 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
252 commits
Select commit Hold shift + click to select a range
b7be82c
Added split and selection metrics option to predict
ravih18 Sep 20, 2022
50c00b0
Moved train options to utils
ravih18 Sep 20, 2022
8239de8
Passed new options to mapsmanager
ravih18 Sep 20, 2022
749abbc
Changed variables name to be more clear
ravih18 Jan 21, 2022
8cf9346
Rechanged variable names since it was not much clearer
ravih18 Jan 21, 2022
00039d9
first commit to add VAE to clinicaDL
ravih18 Aug 13, 2021
b7c9437
Fix padding in decoder
ravih18 Sep 29, 2021
499b584
Added print for debug
ravih18 Sep 29, 2021
37a6a12
Added print for debug
ravih18 Sep 29, 2021
6947cf6
Changed weights of losses
ravih18 Sep 30, 2021
86d8178
added new function to compute kl div
ravih18 Oct 7, 2021
4189634
Moved file after repo refactoring
ravih18 Aug 26, 2021
6899bfa
Added new vae with dense latent space
ravih18 Sep 13, 2021
72d1f34
changed 3D dense model paramters to make it smaller
ravih18 Sep 13, 2021
a54bae6
Changed nconv to reduce memory
ravih18 Sep 13, 2021
bab302a
Changed reconstruction loss weight
ravih18 Sep 14, 2021
a2e4f57
New fuction to print pytorch model summary
ravih18 Nov 4, 2021
a254745
changed log for debugging
ravih18 Nov 9, 2021
0f33e64
Fix decodder output_padding construction
ravih18 Nov 9, 2021
68fd38f
Integration of Benoit's VAE for testing results
ravih18 Nov 24, 2021
4596d93
Added CVAE to the list of models
ravih18 Nov 24, 2021
3881898
Fixed import error
ravih18 Nov 24, 2021
b075c15
Fixed device
ravih18 Nov 24, 2021
e5c42b9
adapted output padding with original size
ravih18 Nov 24, 2021
085140e
print shape for debug
ravih18 Nov 25, 2021
b87ff78
Fixed decoder tensor size
ravih18 Nov 25, 2021
3445001
fixed decoder reshape
ravih18 Nov 25, 2021
4214894
fixed decoder reshape
ravih18 Nov 25, 2021
4708b68
padding test
ravih18 Nov 25, 2021
d061468
padding test
ravih18 Nov 25, 2021
cfccdcc
padding test
ravih18 Nov 25, 2021
e126d12
fixed encoder linear layers size
ravih18 Nov 25, 2021
c620f8a
changed latent space size
ravih18 Nov 25, 2021
d1d9d10
New vae with half size images
ravih18 Nov 25, 2021
3aa618b
Fixed held network
ravih18 Nov 25, 2021
faa37c4
Fix half network
ravih18 Nov 25, 2021
3c73dfd
Minor change to CVAE
ravih18 Nov 30, 2021
003f175
Fixed image reduction
ravih18 Nov 30, 2021
cd1be03
Added print for debug
ravih18 Nov 30, 2021
bc2f895
Added print for debug
ravih18 Nov 30, 2021
0fc2d2a
Added print for debug
ravih18 Nov 30, 2021
e3fec81
Added print for debug
ravih18 Nov 30, 2021
48e48d2
Added print for debug
ravih18 Nov 30, 2021
204eff5
Added print for debug
ravih18 Dec 1, 2021
1894043
Added size_reduction in save_tensor
ravih18 Dec 2, 2021
012e49f
Added size reduction transformation
ravih18 Jan 21, 2022
7b3f451
fix typo 1
ravih18 Jan 21, 2022
0b20239
fix bug 2
ravih18 Jan 21, 2022
42318f0
Correction of branch
ravih18 Jan 21, 2022
6ad1f54
changed print order in CVAE forward
ravih18 Jan 21, 2022
d404738
Removed size reduction in compute output and loss
ravih18 Jan 21, 2022
915259c
remove redundant model
ravih18 Jan 21, 2022
d0a2a9c
Changed variable name
ravih18 Jan 21, 2022
6c2f807
bug fix after name change
ravih18 Jan 21, 2022
c867217
Removed prints
ravih18 Jan 24, 2022
166c16b
take size reduction into account for input_size variable
ravih18 Jan 24, 2022
18651e8
Added new trivial BL models
ravih18 Jan 24, 2022
5159e30
Fix new models
ravih18 Jan 24, 2022
2182c4e
Small change on CVAE
ravih18 Mar 14, 2022
2abec78
temporary patch
ravih18 Mar 14, 2022
dbc85c9
Exp with relu
ravih18 Mar 17, 2022
d4b1dec
exp latent space nomr
ravih18 Mar 17, 2022
4eee390
fixed exp
ravih18 Mar 18, 2022
de386f7
Properly added VAELoss
ravih18 Mar 25, 2022
37a0155
Cleaned code
ravih18 Mar 25, 2022
ab446ae
added possibility to chose size reduction factor
ravih18 Mar 25, 2022
5f397bb
Fix size reduction factor
ravih18 Mar 25, 2022
b02c690
Changed CVAE3D half to be more flexible to input size
ravih18 Mar 28, 2022
2ea3256
debug for vae
ravih18 Mar 28, 2022
1d1c8b2
Fixed feature size calculation
ravih18 Mar 28, 2022
dbe2621
debug cvae
ravih18 Mar 28, 2022
59d970a
Fixed cvae
ravih18 Mar 28, 2022
9dff2fc
Changed float to int
ravih18 Mar 28, 2022
983bb66
Added size reduction of 4
ravih18 Mar 28, 2022
e1236d4
Added size factor of 5 and beta option in cvae
ravih18 Mar 28, 2022
6e91b73
fixed for reduction factor 2
ravih18 Mar 28, 2022
477c3d7
Changed reconstruction error variable
ravih18 Apr 1, 2022
e6878cc
Changed reduction to sum in recons error
ravih18 Apr 1, 2022
31f2421
Use mean redcution
ravih18 Apr 11, 2022
36d6eba
Use sum redcution
ravih18 Apr 11, 2022
b52a28e
Use mean redcution
ravih18 Apr 11, 2022
e08c0e3
Added Save-tensor option to predict
ravih18 Apr 14, 2022
34fe0c1
print tsv_path
ravih18 Apr 14, 2022
d213c59
removed print from mapsmanager
ravih18 Apr 15, 2022
1c4e035
Adding LNCC and using reduction sum as loss
ravih18 Apr 15, 2022
4ab3867
Separated loss components for Logging
ravih18 Apr 21, 2022
6859968
Separated loss components for Logging
ravih18 Apr 22, 2022
0e49d93
divide loss value
ravih18 Apr 22, 2022
5ea33fb
Added SSIM to evaluation
ravih18 Apr 25, 2022
e6d7636
Added SSIM to evaluation
ravih18 Apr 25, 2022
0ff9247
fixed import in ssim3D
ravih18 Apr 25, 2022
d868cf2
added print for debug
ravih18 Apr 25, 2022
13661f3
added print for debug
ravih18 Apr 25, 2022
cfd6d6c
Fixed error shape and size
ravih18 Apr 25, 2022
1445e6c
added print for debug
ravih18 Apr 25, 2022
9f93865
correction of the shape of the array
ravih18 Apr 25, 2022
d897584
transform numpy array into tensor
ravih18 Apr 25, 2022
075b0d8
fixed img type for other function
ravih18 Apr 25, 2022
e0e61bf
Changed the dimension of the tensors
ravih18 Apr 25, 2022
c286723
hot fix
ravih18 Apr 25, 2022
29a55e7
added new losses for VAE
ravih18 May 31, 2022
3f5df2b
Removed reducing factor
ravih18 Jun 8, 2022
1b0d560
Added recons weight
ravih18 Jun 8, 2022
0713bc6
Added new VAE with few new features
ravih18 Jun 16, 2022
baed0d8
hot fix model import
ravih18 Jun 16, 2022
d423c4e
Fixed model padding
ravih18 Jun 16, 2022
2012e71
Add debug in extract
ravih18 Jul 4, 2022
fc60c3b
Add debug in extract
ravih18 Jul 4, 2022
9f695d6
Added debbug
ravih18 Jul 4, 2022
91e363d
fix clinica file reader
ravih18 Jul 4, 2022
3b61c7e
Added normalization choices
ravih18 Jul 26, 2022
ca84db8
Reset for exp
ravih18 Jul 28, 2022
39a75fa
Reset for exp
ravih18 Jul 28, 2022
27d30ee
hotfix
ravih18 Jul 28, 2022
ff4fa7b
reversed modification
ravih18 Aug 1, 2022
083c8a9
Reverse changes
ravih18 Aug 2, 2022
6e5338e
Added the possibility to save the latent space representation
ravih18 Sep 1, 2022
e3ffffc
fix variable name change
ravih18 Sep 19, 2022
0f20660
removed lncc from default reconstruction metrics
ravih18 Sep 19, 2022
5ca4758
Removed save tensor
ravih18 Sep 20, 2022
9de41a6
Uncommented bn4 for test purpose
ravih18 Sep 20, 2022
086ba02
Updated old VAE class
ravih18 Sep 23, 2022
a277485
Corrected base vae output losses loop
ravih18 Sep 23, 2022
8edcd32
fixed variable name error in base vae
ravih18 Sep 23, 2022
268b94c
fixed variable name error in base vae
ravih18 Sep 23, 2022
0397257
Added debug lines
ravih18 Sep 26, 2022
7b0f43a
Added debug lines
ravih18 Sep 26, 2022
14c4d90
Fixed latent space saver
ravih18 Sep 26, 2022
d5e00c2
Fixed code that was saving img instead of latent space
ravih18 Sep 26, 2022
6ec791e
Changed loss values
ravih18 Oct 7, 2022
6011902
Changed loss values
ravih18 Oct 7, 2022
b5896e6
now also saves regularization value
ravih18 Oct 7, 2022
c275e31
fix log regularisation in CB loss
ravih18 Oct 10, 2022
03468a7
Added dataset for neuroimages working with Pythae
ravih18 Dec 8, 2022
826833c
First version of Pythae VAE in clinicadl
ravih18 Dec 8, 2022
2f39f7f
Added to the list of model importable
ravih18 Dec 8, 2022
7c3fcad
added pythae models
ravih18 Jan 25, 2023
ac7e3d5
Added pythae argument to config file
ravih18 Jan 27, 2023
4eefb53
Adding missing files that has been changed
ravih18 Jan 27, 2023
0a8b168
Updating maps and task manager
ravih18 Jan 27, 2023
0dd30f6
Updated code for easy eval with pythae
ravih18 Jan 30, 2023
ef9bd38
add modified files
ravih18 Feb 16, 2023
0313760
Add random search for vae architecture
ravih18 Apr 17, 2023
af8cb80
syntax hotfix
ravih18 Apr 17, 2023
5c4ae94
syntax hotfix
ravih18 Apr 17, 2023
ae25994
Update decoder padding for RS
ravih18 Apr 17, 2023
e22978a
changed default value for feature size
ravih18 Apr 17, 2023
ee06d02
updated toml
ravih18 Apr 21, 2023
4ccafd9
Added AMP as default for VAE
ravih18 May 4, 2023
e14e104
Corrected batch size for vae
ravih18 May 4, 2023
3a979b9
updated batch size argument for trainer config
ravih18 May 4, 2023
7f8ea8b
changelog test
camillebrianceau Jun 13, 2023
31f764b
remove data folder
camillebrianceau Jun 13, 2023
d0fb495
update tests
camillebrianceau Jun 13, 2023
146f2eb
BetaVAEConfig
camillebrianceau Jun 15, 2023
d244f6c
JZ modification
ravih18 Jun 23, 2023
86919cd
correct pep8
ravih18 Oct 3, 2023
61448be
Delete clinicadl/utils/network/pythae/pythae_models.py
ravih18 Oct 3, 2023
ce6aea3
JZ modification (#487)
ravih18 Oct 3, 2023
a46e5b9
correct function args in split manager
ravih18 Oct 5, 2023
6a27150
Merge branch 'rh_pythae' into rh_pythae
ravih18 Oct 5, 2023
8c8ce39
Rh pythae (#488)
ravih18 Oct 5, 2023
6e3bb8d
Merge pull request #1 from aramis-lab/rh_pythae
msolal Oct 9, 2023
f9980d9
multi_conv_VAE: VAE w. multiple conv per layer
msolal Oct 12, 2023
51f886a
rename n_conv_per_block
msolal Oct 13, 2023
c15ab44
multi conv blocks VAE + ResNet
msolal Nov 6, 2023
6491017
multi conv models + upsample
msolal Nov 23, 2023
7b5750b
Update VAEs building
ravih18 Nov 24, 2023
91fb3c2
update ssim and msssim metrics
ravih18 Nov 24, 2023
e536b72
modifications to work with both ClinicaDL and Pythae
ravih18 Nov 24, 2023
978651e
Update Capts Dataset
ravih18 Nov 24, 2023
e8a7ac4
Merge branch 'rh_pythae' of https://github.com/ravih18/ClinicaDL into…
ravih18 Nov 24, 2023
f114c74
debug architectures + random search
msolal Nov 27, 2023
160ed42
Merge branch 'ravih18:rh_pythae' into rh_pythae
msolal Nov 28, 2023
514ad31
multi_conv_VAE: VAE w. multiple conv per layer
msolal Oct 12, 2023
c4d4fdf
rename n_conv_per_block
msolal Oct 13, 2023
69c99b3
multi conv blocks VAE + ResNet
msolal Nov 6, 2023
f584f4b
multi conv models + upsample
msolal Nov 23, 2023
6c515d6
debug architectures + random search
msolal Nov 27, 2023
6f4f080
nomenclature layer / block + multi layer per block
Nov 29, 2023
71bfe9a
Solve conflicts
msolal Nov 29, 2023
9a08b8c
Solve conflicts again
msolal Nov 29, 2023
3e26d48
debug new architectures
msolal Nov 30, 2023
13597a5
separate VAE blocks & VAE layers
Nov 30, 2023
b853739
replace nn.ReLU with F.relu
Nov 30, 2023
cbbee31
upsample only once per block in decoder
msolal Dec 1, 2023
6e239b7
Merge pull request #2 from msolal/ms_pythae
ravih18 Dec 1, 2023
6bde062
Added callback in train pythae
ravih18 Dec 1, 2023
b0dd921
Merge branch 'rh_pythae' of https://github.com/ravih18/ClinicaDL into…
ravih18 Dec 1, 2023
c2fc0b7
Launch call back
ravih18 Dec 1, 2023
8c8f2c7
add block type to random search
msolal Dec 4, 2023
8f423f6
replace relu and leaky relu by silu
msolal Dec 4, 2023
4de9147
random search with custom toml name
msolal Dec 5, 2023
070bc80
optimizer arg in pythae train and random search
msolal Dec 5, 2023
93a9456
last block / layer in VAE model + last layer conv
msolal Dec 5, 2023
48b1d69
Merge pull request #3 from msolal/ms_pythae
ravih18 Dec 5, 2023
0c55099
Added RS for all Pythae models
ravih18 Dec 5, 2023
b4a52fc
minor changes
ravih18 Dec 5, 2023
fda423c
merge branches
ravih18 Dec 5, 2023
1a3c84b
Improved RS for pythae models
ravih18 Dec 7, 2023
49262f5
Added configuration for encoder decoder building
ravih18 Dec 7, 2023
63341fc
Adapted all the models
ravih18 Dec 7, 2023
1f5695f
update gitignore
ravih18 Dec 7, 2023
90efaa3
remove architecture parameters from mandatory args in rs
msolal Dec 8, 2023
33294d3
adjust size of linear layer in discriminator for full-res images
msolal Dec 8, 2023
d2c1ba2
removed rs architecture params from mandatory args
msolal Dec 8, 2023
26de385
size of linear layer in VAEGAN discriminator
msolal Dec 8, 2023
9d3bfbb
split arg from toml for pythae training
msolal Dec 8, 2023
6ed89f7
Merge pull request #4 from msolal/rh_pythae
ravih18 Dec 8, 2023
fb59658
remove split from pythae cli
msolal Dec 8, 2023
7065794
Conv4FC2 for VAE GAN discriminator
msolal Dec 8, 2023
45176e4
Merge pull request #5 from msolal/rh_pythae
ravih18 Dec 8, 2023
8a2633a
Corrected issue when predicting with new VAE builder
ravih18 Dec 11, 2023
ec6799a
Removed print
ravih18 Dec 11, 2023
855d6cb
Added all pythae models for RS
ravih18 Dec 18, 2023
f2fdae2
Added missing parameter
ravih18 Dec 18, 2023
dacfdfe
Corrected models
ravih18 Dec 18, 2023
d408929
removed print
ravih18 Dec 18, 2023
b8370c9
Added split to command line for train pythae
ravih18 Dec 18, 2023
f55969e
call predict once, save model outputs test_pythae
msolal Dec 18, 2023
a6eea7a
Merge pull request #6 from msolal/rh_pythae
ravih18 Dec 19, 2023
958b69d
Remove prints
ravih18 Dec 21, 2023
dc41567
Updated parameters sampling type
ravih18 Dec 21, 2023
d6e32ea
Merge pull request #4 from ravih18/rh_pythae
msolal Jun 3, 2024
5ac5971
Sample latent space option
Jun 3, 2024
5112157
add sample_latent to toml options
Jun 3, 2024
a5c6386
Sampling latent space to obtain multiple reconstructions
Jun 5, 2024
45d6788
don't save sample_latent_results_df if no sample_latent flag
Jun 5, 2024
f8412eb
python 3.10 rather than 3.9 in environment
Jun 13, 2024
1dc7d4d
Remove clinica dependency (#525)
camillebrianceau Feb 13, 2024
7e44bb2
Patch between Path and strings
msolal Jun 17, 2024
d90524b
remove check of custom suffix
msolal Jun 17, 2024
2e3a2dc
save inputs and outputs of reconstruction task as CAPS in MAPS
msolal Jun 17, 2024
b1f1c09
save_caps option saves nifti images instead of tensors
Jun 20, 2024
c780604
Add abnormality map to clinicadl
Jun 21, 2024
74d4141
save_caps saves both .pt and .nii.gz, abnormality maps uses .pt
msolal Jun 21, 2024
f81d65b
test
camillebrianceau Jul 9, 2024
6d7a521
for mood and docker
camillebrianceau Jul 16, 2024
e3c2c58
add workdir
camillebrianceau Jul 19, 2024
485e14a
remove workdir
camillebrianceau Jul 26, 2024
d1b1d36
remove workdir
camillebrianceau Jul 30, 2024
bed77fa
hugues concat dataset
camillebrianceau Aug 5, 2024
617d2b6
hugues concat dataset
camillebrianceau Aug 5, 2024
ac771e0
test
camillebrianceau Aug 8, 2024
8edd5f1
deeplearning moood abdom
camillebrianceau Aug 14, 2024
3aaaff9
last tests and remove print
camillebrianceau Aug 20, 2024
686e4ca
tmp dir
camillebrianceau Aug 20, 2024
6842f2f
tmp dir
camillebrianceau Aug 20, 2024
27acf50
resize
camillebrianceau Aug 21, 2024
1ca6b81
final commit remove print
camillebrianceau Aug 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified .git-blame-ignore-rev
100644 → 100755
Empty file.
Empty file modified .github/workflows/lint.yaml
100644 → 100755
Empty file.
3 changes: 3 additions & 0 deletions .gitignore
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ clinicadl/notebooks/
# Mask and other files
clinicadl/clinicadl/resources/masks/*.nii
clinicadl/clinicadl/resources/masks/*.nii.gz

# Jean zay
core-rg*
Empty file modified .jenkins/Jenkinsfile
100644 → 100755
Empty file.
Empty file modified .pep8speaks.yml
100644 → 100755
Empty file.
Empty file modified .pre-commit-config.yaml
100644 → 100755
Empty file.
Empty file modified .readthedocs.yaml
100644 → 100755
Empty file.
100 changes: 94 additions & 6 deletions CHANGELOG
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,94 @@ Main changes to this code/ project are documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## ClinicaDL 1.4.0

### Fixed

* Fix `--diagnoses` and `--merged_tsv` option bug in `clinicadl get-labels`
* Fix Pathlib bugs
* Fix `get_tsv_paths` function bug.
* Fix a bug for which it was impossible to use predict without specifying the splits and selection metrics.

### Changed

* Changed default batch size to 8 for `clinicadl predict`
* Changed VAEs main class

### New

* Add `--n_proc` option in `clinicadl generate` pipelines for parallelization.
* Add `--split` to `clinicadl predict`
* Add new VAE networks.
* Add pytorch function to summarize
* Add `--size_reduction` and `--size_reduction_factor` options to `clinicadl train`, `clinicadl predict` and `clinicadl interpret`.
* Add SSIM2D, SSIM3D metrics for VAE.
* Add `--save_latent_space` option to `clinicadl train` and `clinicadl predict`.
* Add `clinicadl generate trvial_motion`
* Add Data augmentation with torchio



## ClinicaDL 1.3.1

### Fixed

* Fix TypeError when running ClinicaDL.
* Fix `--extract_json` option bug in `clinicadl prepare-data`.
* Fix `clinicadl tsvtools get-labels` error finding `clinica iotools missing-modalities` output.

### Changed

* Changed `clinicadl tsvtools get-labels` output directory.

### New

* Add `--caps_directory` option in `clinicadl tsvtools get-labels`.
## ClinicaDL 1.3.0

### New

* Add new command `quality-check pet-linear`.
* Add new command `generate hypometabolic`.
* Add new network architecture: `Resnet3D` and `SqueezeExcitationCNN`.
* Add `flair-linear` modality for `prepare-data` command.
* Add pytorch profiler.
* Add `--save_nifti` option for `interpret`command.
* Add `--output_dir` argument for `tsvtools get-labels` command

### Changed

** Core: **

* Transition from os to pathlib.
* Update data CI.
* Improve maps_manager.
* Change `--acq_label` option for `--tracer`.
* Update tutorial.


## ClinicaDL 1.2.0

### Changed

** Core: **

* Add ClinicaDL installation with pipx.
* Improve logging.
* Add method argument to the interpret command to choose between the new Grad-CAM method and the gradient method.
* Change `extract` command to `prepare-data`.
* Change output of `get-labels`, `split` and `kfold` commands to one TSV per split instead of one per label.
* Change `tsvtool` command to `tsvtools`.
* Change `tsvtools getlabels` command to `tsvtools get-labels` and remove the progression column in the TSV output.
* Add new commands: `tsvtools get-progression`, `tsvtools get-metadata`, `tsvtools prepare-experiment` (split + kfold), and `tsvtools adapt`.
* Update data CI.
* Add a new model for quality check

### Fixed

- Fix `quality-check t1-linear`


## ClinicaDL 1.1.1

### Changed
Expand All @@ -18,7 +106,7 @@ greater than 3.8.
sub-command (before `save_tensor` was also subcommand`).
- Update some paper references in the documentation.
- Add a description for the available models.
- Add the flag `--model_layers` to the `clinicadl train list_models` subcommad
- Add the flag `--model_layers` to the `clinicadl train list_models` subcommand
to visualize the model layers.

### Fixed
Expand Down Expand Up @@ -84,7 +172,7 @@ Print help if no argument is given.
### Fixed

Fix label code generation
Remove all occurences of a group in a MAPS when choosing the `overwriting` option.
Remove all occurrences of a group in a MAPS when choosing the `overwriting` option.
Fix `resume` when the training.tsv file is empty.

## ClinicaDL 1.0.3 (release bugfix)
Expand All @@ -108,7 +196,7 @@ Fix `resume` when the training.tsv file is empty.

- Use the GPU option on the command line interface.
- Fix the train task when invoking the CLI.
- Remplace the `predict` arguments passed through the CLI.
- Replace the `predict` arguments passed through the CLI.
- Fix issue when using multiple cohorts.

## ClinicaDL 1.0.1
Expand All @@ -135,12 +223,12 @@ introduction of [Click](https://click.palletsprojects.com/en/8.0.x/) library.
Major changes in several pipelines interfaces have been implemented. For
instance the preprocessing pipeline has been split. Train pipeline has also
been refactored to reduce the number of options. The goal is to make ClinicaDL
more easy to use, to maintain, and adapt the command line to the MAPS.
easier to use, to maintain, and adapt the command line to the MAPS.

ClinicaDL aim for more reproducibility: some configuration files are saved in
the MAPS to reproduce experiments in the same condition (with same
environnement and same parameters). In addition we added some options to fix
the random processes seed and use Pytorch latest enhancement for a
environment and same parameters). In addition, we added some options to fix
the random processes seed and use Pytorch's latest enhancement for a
deterministic behavior.

Other improvement and small fix have also been implemented.
Expand Down
Empty file modified LICENSE.txt
100644 → 100755
Empty file.
Empty file modified MANIFEST.in
100644 → 100755
Empty file.
Empty file modified Makefile
100644 → 100755
Empty file.
Empty file modified clinicadl/__init__.py
100644 → 100755
Empty file.
Empty file.
163 changes: 163 additions & 0 deletions clinicadl/abnormality_map/abnormality_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import json
import numpy as np
import nibabel as nib
from pathlib import Path
from copy import deepcopy
from typing import Tuple, Callable, Union, List

import torch
from torch.utils.data import DataLoader

from clinicadl.utils.caps_dataset.data import load_data_test, return_dataset, get_transforms
from clinicadl.utils.maps_manager import MapsManager
from clinicadl.utils.maps_manager.maps_manager_utils import read_json


def residual_fn(
x: torch.Tensor,
x_hat: torch.Tensor,
) -> Tuple[torch.Tensor, str]:
return x - x_hat, "residual"

# def residual_fn(
# x: nib.Nifti1Image,
# x_hat: nib.Nifti1Image,
# ) -> Tuple[nib.Nifti1Image, str]:
# affine = x.affine
# x_data = x.get_fdata().numpy()
# x_hat_data = x_hat.get_fdata().numpy()
# return nib.Nifti1Image(x_data - x_hat_data, eye(4)), "residual"

abn_map_dict = {
"residual": residual_fn,
}

def compute_abnormality_map(
maps_dir: Path,
preprocessing_json: Path,
data_group: str,
gpu: bool,
n_proc: int,
batch_size: int,
abn_map_fn: Union[str, Callable[[nib.Nifti1Image, nib.Nifti1Image], Tuple[nib.Nifti1Image, str]]] = residual_fn,
split_list: List[int] = None,
tsv_path: Path = None,
selection_metrics: str = None,
multi_cohort: bool = False,
):
"""
Computes the abnormality map for a given split and data group using the model selected with the selection metrics.

Args:
maps_manager (MapsManager): MAPS manager object
split_list (list[int]): list of splits to compute the abnormality map on
data_group (str): data group to compute the abnormality map on
selection_metrics (str): selection metrics to use to select the best model
abn_map_fn (Callable[[nib.Nifti1Image, nib.Nifti1Image], Tuple[nib.Nifti1Image, str]], optional):
method to compute the abnormality map. Defaults to residual_fn.
"""

maps_manager = MapsManager(maps_dir)

if not split_list:
split_list = maps_manager._find_splits()

for split in split_list:

if tsv_path is not None:
group_df = load_data_test(
tsv_path,
"CN",
multi_cohort=multi_cohort,
)

group_df, group_parameters = maps_manager.get_group_info(data_group, split)

if not selection_metrics:
split_selection_metrics = maps_manager._find_selection_metrics(split)[0]
else:
split_selection_metrics = selection_metrics[0]

preprocessing_dict = read_json(preprocessing_json)

input_preprocessing_dict = deepcopy(preprocessing_dict)
input_pattern = preprocessing_dict["file_type"]["pattern"].replace("_mood.pt", "_input.pt")
input_preprocessing_dict["file_type"]["pattern"] = input_pattern
input_preprocessing_dict["preprocessing"] = "custom"

output_preprocessing_dict = deepcopy(preprocessing_dict)
output_pattern = preprocessing_dict["file_type"]["pattern"].replace("_mood.pt", "_output.pt")
output_preprocessing_dict["file_type"]["pattern"] = output_pattern
output_preprocessing_dict["preprocessing"] = "custom"

# TO DO: code to retrieve transforms
# _, all_transforms = get_transforms(
# normalize=maps_manager.normalize,
# data_augmentation=maps_manager.data_augmentation,
# size_reduction=maps_manager.size_reduction,
# size_reduction_factor=maps_manager.size_reduction_factor,
# )

caps_output_dir = Path(maps_dir, f"split-{split}", f"best-{split_selection_metrics}", "CapsOutput")

input_data = return_dataset(
caps_output_dir,
group_df,
input_preprocessing_dict,
all_transformations=None, # TO DO: change this
multi_cohort=group_parameters["multi_cohort"],
)

output_data = return_dataset(
caps_output_dir,
group_df,
output_preprocessing_dict,
all_transformations=None, # TO DO: change this
multi_cohort=group_parameters["multi_cohort"],
)

input_loader = DataLoader(
input_data,
batch_size=batch_size,
shuffle=False,
num_workers=n_proc,
)

output_loader = DataLoader(
output_data,
batch_size=batch_size,
shuffle=False,
num_workers=n_proc,
)

for i, (input_batch, output_batch) in enumerate(zip(input_loader, output_loader)):

for idx in range(len(input_batch['participant_id'])):

assert input_batch['participant_id'][idx] == output_batch['participant_id'][idx]

participant_id = input_batch['participant_id'][idx]
session_id = input_batch['session_id'][idx]

if isinstance(abn_map_fn, str):
abn_map_fn = abn_map_dict[abn_map_fn]

abn_map_pt, abn_map_pattern = abn_map_fn(output_batch['data'][idx], input_batch['data'][idx])
abn_map_nii = nib.Nifti1Image(abn_map_pt.numpy(), np.eye(4))

abn_map_pt_path = input_batch['image_path'][idx].replace("_input.pt", f"_{abn_map_pattern}.pt")
abn_map_nii_path = Path(caps_output_dir, "subjects", participant_id, session_id, "custom", f"{participant_id}_{session_id}_{abn_map_pattern}.nii.gz")

torch.save(abn_map_pt, abn_map_pt_path)
nib.save(abn_map_nii, abn_map_nii_path)

print("Saved abnormality map at", abn_map_pt_path)
print("Saved abnormality map at", abn_map_nii_path)

abn_map_preprocessing_dict = deepcopy(preprocessing_dict)
abn_map_preprocessing_dict["file_type"]["pattern"] = abn_map_pattern

abn_map_preprocessing_json = json.dumps(abn_map_preprocessing_dict, skipkeys=True, indent=4)
f = open(preprocessing_json.replace(".json", f"_{abn_map_pattern}.json"), "w")
f.write(abn_map_preprocessing_json)
f.close()
66 changes: 66 additions & 0 deletions clinicadl/abnormality_map/abnormality_map_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import click
from pathlib import Path

from clinicadl.utils import cli_param

from clinicadl.abnormality_map.abnormality_map import compute_abnormality_map

@click.command(name="abnormality_map", no_args_is_help=True)
@cli_param.argument.input_maps
@cli_param.argument.data_group
@cli_param.argument.preprocessing_json
@cli_param.option.participant_list
@cli_param.option.selection_metrics
@cli_param.option.split
@cli_param.option.use_gpu
@cli_param.option.n_proc
@cli_param.option.batch_size
@click.option(
"--multi_cohort",
type=bool,
default=False,
is_flag=True,
help="""Allow to use multiple CAPS directories.
In this case, CAPS_DIRECTORY and PARTICIPANTS_TSV must be paths to TSV files.""",
)
@click.option(
"--abn_map_type",
type=str,
default="residual",
help="""Type of abnormality map to compute. Default is residual.""",
)
def cli(
input_maps_directory,
data_group,
preprocessing_json,
participants_tsv,
split,
abn_map_type,
gpu,
n_proc,
batch_size,
selection_metrics,
multi_cohort,
):
"""Infer the outputs of a trained model on a test set.
INPUT_MAPS_DIRECTORY is the MAPS folder from where the model used for prediction will be loaded.
DATA_GROUP is the name of the subjects and sessions list used for the interpretation.
"""
from clinicadl.utils.cmdline_utils import check_gpu

if gpu:
check_gpu()

compute_abnormality_map(
maps_dir=input_maps_directory,
abn_map_fn=abn_map_type,
data_group=data_group,
tsv_path=participants_tsv,
gpu=gpu,
n_proc=n_proc,
batch_size=batch_size,
split_list=split,
selection_metrics=selection_metrics,
multi_cohort=multi_cohort,
preprocessing_json=preprocessing_json,
)
2 changes: 2 additions & 0 deletions clinicadl/cmdline.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from clinicadl.train.train_cli import cli as train_cli
from clinicadl.tsvtools.cli import cli as tsvtools_cli
from clinicadl.utils.maps_manager.logwriter import setup_logging
from clinicadl.abnormality_map.abnormality_map_cli import cli as abnormality_map_cli

CONTEXT_SETTINGS = dict(
# Extend content width to avoid shortening of pipeline help.
Expand Down Expand Up @@ -44,6 +45,7 @@ def cli(verbosity):
cli.add_command(interpret_cli)
cli.add_command(qc_cli)
cli.add_command(random_search_cli)
cli.add_command(abnormality_map_cli)

if __name__ == "__main__":
cli()
Empty file modified clinicadl/extract/__init__.py
100644 → 100755
Empty file.
Loading