|
55 | 55 | # <img src="../images/generate_trivial.png" alt="generate trivial" style="height: 350px; margin: 10px; text-align: center;">
|
56 | 56 |
|
57 | 57 | # ```{warning}
|
58 |
| -# You need to execute the `clinica run` and `clinicadl prepare-data` pipelines |
59 |
| -# before running this task. Moreover, the trivial option can synthesize at |
60 |
| -# most $n$ images per label, where $n$ is the total number of images in the |
61 |
| -# input CAPS. |
| 58 | +# You need to execute the `clinica run` pipeline before running this task. |
| 59 | +# Moreover, the trivial option can synthesize at most n images per label, |
| 60 | +# where n is the total number of images in the input CAPS. |
62 | 61 | # ```
|
63 | 62 | # ### Running the task
|
64 | 63 | #
|
|
67 | 66 | # ```
|
68 | 67 | # where:
|
69 | 68 |
|
70 |
| -# - `caps_directory` is the output folder containing the results in a |
| 69 | +# - `caps_directory` is the output folder containing the results of `clinica run` in a |
71 | 70 | # [CAPS](https://aramislab.paris.inria.fr/clinica/docs/public/latest/CAPS/Introduction/) hierarchy,
|
72 | 71 | # - `output_directory` is the folder where the synthetic CAPS is stored,
|
73 | 72 | # - `n_subjects` is the number of subjects per label in the synthetic dataset.
|
|
85 | 84 |
|
86 | 85 | # In order to train a network, meta data must be organized in a file system
|
87 | 86 | # generated by `clinicadl tsvtools`. For more information on the following
|
88 |
| -# commands, please refer to the section ["Define your |
89 |
| -# population"](./label_extraction.ipynb). |
| 87 | +# commands, please refer to the section [Define your |
| 88 | +# population](./label_extraction.ipynb). |
90 | 89 | # %% [markdown]
|
91 |
| -# #### Get the labels AD and CN. |
92 |
| -# This command needs a BIDS folder as an argument in order to create the |
93 |
| -# `missing_mods_directory` and the `merged.tsv` file, but if you already |
| 90 | +# #### Get the labels AD and CN |
| 91 | +# `get-labels` command needs a BIDS folder as an argument in order to create the |
| 92 | +# `missing_mods` directory and the `merged_tsv` file, but if you already |
94 | 93 | # have these, you can give an empty folder as argument and provide the paths
|
95 | 94 | # to the required files separately as keyword arguments.
|
96 | 95 |
|
97 |
| -# Be careful, the output of the command (`labels.tsv`) is saved in the same |
98 |
| -# folder as the BIDS folder. |
99 | 96 | # %%
|
100 | 97 | !mkdir data/fake_bids
|
101 |
| -!clinicadl tsvtools get-labels data/fake_bids --missing_mods data/synthetic/missing_mods --merged_tsv data/synthetic/data.tsv --modality synthetic |
| 98 | +!clinicadl tsvtools get-labels data/fake_bids data --missing_mods data/synthetic/missing_mods --merged_tsv data/synthetic/data.tsv --modality synthetic |
102 | 99 | # %%
|
103 | 100 | # Split train and test data
|
104 | 101 | !clinicadl tsvtools split data/labels.tsv --n_test 0.25 --subset_name test
|
105 | 102 | # %%
|
106 |
| -# Split train and validation data in a 5-fold cross-validation |
| 103 | +# Split train and validation data in a 3-fold cross-validation |
107 | 104 | !clinicadl tsvtools kfold data/split/train.tsv --n_splits 3
|
108 | 105 | # %% [markdown]
|
109 | 106 | # ## Train a model on synthetic data
|
110 | 107 |
|
111 |
| -# Once data was generated and split it is possible to train a model using |
| 108 | +# Once data was generated and split, it is possible to train a model using |
112 | 109 | # `clinicadl train` and evaluate its performance with `clinicadl interpret`. For
|
113 | 110 | # more information on the following command lines please read the sections
|
114 | 111 | # [Classification with a CNN on 2D slice](./training_classification.ipynb) and
|
115 | 112 | # [Regression with 3D images](./training_regression.ipynb).
|
116 | 113 | #
|
117 |
| -# The following command uses a pre-build architecture of ClinicaDL `Conv4_FC3`. |
| 114 | +# The following `clinicadl train` command uses a pre-build architecture of ClinicaDL `Conv4_FC3`. |
118 | 115 | # You can also implement your own models by following the instructions of [this
|
119 | 116 | # section](./training_custom.ipynb).
|
120 | 117 | #
|
121 |
| -# If you failed to generate a trivial dataset, please uncomment the next cell. |
122 |
| -# %% |
123 |
| -# !curl -k https://aramislab.paris.inria.fr/clinicadl/files/handbook_2023/data/synthetic.tar.gz -o synthetic.tar.gz |
124 |
| -# !tar xf synthetic.tar.gz |
125 |
| -# %% |
126 |
| -# Prepare data (extraction of image tensors) |
| 118 | +# First, we need to run `prepare-data` to extract the tensors from the images: |
| 119 | +# %% |
127 | 120 | !clinicadl prepare-data image data/synthetic t1-linear --extract_json extract_T1linear_image
|
| 121 | +# %% [markdown] |
| 122 | +# Then, we will train the network with the synthetic data. If you failed to generate a trivial dataset, |
| 123 | +# please uncomment the next cell. |
| 124 | +# %% |
| 125 | +# # !curl -k https://aramislab.paris.inria.fr/clinicadl/files/handbook_2023/data/synthetic.tar.gz -o synthetic.tar.gz |
| 126 | +# # !mkdir data |
| 127 | +# # !tar xf synthetic.tar.gz -C data |
| 128 | +# # !mkdir data/fake_bids |
| 129 | +# # !clinicadl tsvtools get-labels data/fake_bids data --missing_mods data/synthetic/missing_mods --merged_tsv data/synthetic/data.tsv --modality synthetic |
| 130 | +# # !clinicadl tsvtools split data/labels.tsv --n_test 0.25 --subset_name test |
| 131 | +# # !clinicadl tsvtools kfold data/split/train.tsv --n_splits 3 |
| 132 | +# # no need to run prepare-data |
128 | 133 | # %%
|
129 |
| -# Train a network with synthetic data |
130 |
| -!clinicadl train classification data/synthetic extract_T1linear_image data/split/3_fold data/synthetic_maps --architecture Conv4_FC3 --n_splits 3 --split 0 |
| 134 | +# Train a network with synthetic data (remove --no-gpu option if you do have access to a gpu) |
| 135 | +!clinicadl train classification data/synthetic extract_T1linear_image data/split/3_fold data/synthetic_maps --architecture Conv4_FC3 --n_splits 3 --split 0 --no-gpu |
131 | 136 | # %% [markdown]
|
132 | 137 | # As the number of images is very small (4 per class), we do not rely on the
|
133 | 138 | # accuracy to select the model. Instead we evaluate the model which obtained the
|
|
160 | 165 | # <img src="../images/generate_random.png" alt="generate random" style="height: 350px; margin: 10px; text-align: center;">
|
161 | 166 |
|
162 | 167 | # ```{warning}
|
163 |
| -# You need to execute the `clinica run` and `clinicadl prepare-data` pipelines |
164 |
| -# prior to running this task. Moreover, the random option can synthesize as |
| 168 | +# You need to execute the `clinica run` pipeline prior to running this task. |
| 169 | +# Moreover, the random option can synthesize as |
165 | 170 | # many images as wanted with only one input image.
|
166 | 171 | # ```
|
167 |
| -# %% [markdown] |
168 |
| -# ###Running the task |
| 172 | +# ### Running the task |
| 173 | +# |
169 | 174 | # ```bash
|
170 | 175 | # clinicadl generate random <caps_directory> <generated_caps_directory>
|
171 | 176 | # ```
|
172 | 177 | # where:
|
173 | 178 |
|
174 |
| -# - `caps_directory` is the output folder containing the results in a [CAPS](http://www.clinica.run/doc/CAPS/) hierarchy. |
| 179 | +# - `caps_directory` is the output folder containing the results of `clinica run` in a |
| 180 | +# [CAPS](https://aramislab.paris.inria.fr/clinica/docs/public/latest/CAPS/Introduction/) hierarchy, |
175 | 181 | # - `generated_caps_directory` is the folder where the synthetic CAPS is stored.
|
176 | 182 |
|
177 | 183 |
|
|
196 | 202 | # - **subtype 1**: Top region has its maximum size but Bottom is atrophied,
|
197 | 203 | # - **subtype 2**: Bottom region has its maximum size but Top is atrophied.
|
198 | 204 |
|
199 |
| -# <img src="../images/generate_shepplogan.png" alt="generate shepplogan" style="height: 350px; margin: 10px; text-align: center;"> |
| 205 | +# <img src="../images/generate_shepplogan.png" alt="generate shepplogan" style="height: 250px; margin: 5px; text-align: center;"> |
200 | 206 |
|
201 | 207 | # These three subtypes are spread between two labels which mimic the binary
|
202 | 208 | # classification between Alzheimer's disease patients (AD) with heterogeneous
|
|
0 commit comments