Skip to content

Commit caab842

Browse files
authored
Corrects of some typos and adds clarifications (#37)
1 parent ef7db42 commit caab842

File tree

1 file changed

+36
-30
lines changed

1 file changed

+36
-30
lines changed

src/generate.py

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,9 @@
5555
# <img src="../images/generate_trivial.png" alt="generate trivial" style="height: 350px; margin: 10px; text-align: center;">
5656

5757
# ```{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.
6261
# ```
6362
# ### Running the task
6463
#
@@ -67,7 +66,7 @@
6766
# ```
6867
# where:
6968

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
7170
# [CAPS](https://aramislab.paris.inria.fr/clinica/docs/public/latest/CAPS/Introduction/) hierarchy,
7271
# - `output_directory` is the folder where the synthetic CAPS is stored,
7372
# - `n_subjects` is the number of subjects per label in the synthetic dataset.
@@ -85,49 +84,55 @@
8584

8685
# In order to train a network, meta data must be organized in a file system
8786
# 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).
9089
# %% [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
9493
# have these, you can give an empty folder as argument and provide the paths
9594
# to the required files separately as keyword arguments.
9695

97-
# Be careful, the output of the command (`labels.tsv`) is saved in the same
98-
# folder as the BIDS folder.
9996
# %%
10097
!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
10299
# %%
103100
# Split train and test data
104101
!clinicadl tsvtools split data/labels.tsv --n_test 0.25 --subset_name test
105102
# %%
106-
# Split train and validation data in a 5-fold cross-validation
103+
# Split train and validation data in a 3-fold cross-validation
107104
!clinicadl tsvtools kfold data/split/train.tsv --n_splits 3
108105
# %% [markdown]
109106
# ## Train a model on synthetic data
110107

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
112109
# `clinicadl train` and evaluate its performance with `clinicadl interpret`. For
113110
# more information on the following command lines please read the sections
114111
# [Classification with a CNN on 2D slice](./training_classification.ipynb) and
115112
# [Regression with 3D images](./training_regression.ipynb).
116113
#
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`.
118115
# You can also implement your own models by following the instructions of [this
119116
# section](./training_custom.ipynb).
120117
#
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+
# %%
127120
!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
128133
# %%
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
131136
# %% [markdown]
132137
# As the number of images is very small (4 per class), we do not rely on the
133138
# accuracy to select the model. Instead we evaluate the model which obtained the
@@ -160,18 +165,19 @@
160165
# <img src="../images/generate_random.png" alt="generate random" style="height: 350px; margin: 10px; text-align: center;">
161166

162167
# ```{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
165170
# many images as wanted with only one input image.
166171
# ```
167-
# %% [markdown]
168-
# ###Running the task
172+
# ### Running the task
173+
#
169174
# ```bash
170175
# clinicadl generate random <caps_directory> <generated_caps_directory>
171176
# ```
172177
# where:
173178

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,
175181
# - `generated_caps_directory` is the folder where the synthetic CAPS is stored.
176182

177183

@@ -196,7 +202,7 @@
196202
# - **subtype 1**: Top region has its maximum size but Bottom is atrophied,
197203
# - **subtype 2**: Bottom region has its maximum size but Top is atrophied.
198204

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;">
200206

201207
# These three subtypes are spread between two labels which mimic the binary
202208
# classification between Alzheimer's disease patients (AD) with heterogeneous

0 commit comments

Comments
 (0)