Skip to content

Commit 430ed5d

Browse files
author
Virginia
committed
Merge remote-tracking branch 'origin/main' into main
2 parents 04a88dd + 5c7a75f commit 430ed5d

24 files changed

+424
-216
lines changed

3d_segmentation/swin_unetr_btcv_segmentation_3d.ipynb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"\n",
3434
"For this tutorial, the dataset needs to be downloaded from: https://www.synapse.org/#!Synapse:syn3193805/wiki/217752. More details are provided in the \"Download dataset\" section below.\n",
3535
"\n",
36-
"In addition, the json file for data splits needs to be downloaded from this [link](https://drive.google.com/file/d/1qcGh41p-rI3H_sQ0JwOAhNiQSXriQqGi/view?usp=sharing). Once downloaded, place the json file in the same folder as the dataset. \n",
36+
"In addition, the json file for data splits needs to be downloaded from this [link](https://developer.download.nvidia.com/assets/Clara/monai/tutorials/swin_unetr_btcv_dataset_0.json). Once downloaded, place the json file in the same folder as the dataset. \n",
3737
"\n",
3838
"For BTCV dataset, under Institutional Review Board (IRB) supervision, 50 abdomen CT scans of were randomly selected from a combination of an ongoing colorectal cancer chemotherapy trial, and a retrospective ventral hernia study. The 50 scans were captured during portal venous contrast phase with variable volume sizes (512 x 512 x 85 - 512 x 512 x 198) and field of views (approx. 280 x 280 x 280 mm3 - 500 x 500 x 650 mm3). The in-plane resolution varies from 0.54 x 0.54 mm2 to 0.98 x 0.98 mm2, while the slice thickness ranges from 2.5 mm to 5.0 mm. \n",
3939
"\n",
@@ -98,8 +98,6 @@
9898
"\n",
9999
"We use weights from self-supervised pre-training of Swin UNETR encoder (3D Swin Tranformer) on a cohort of 5050 CT scans from publicly available datasets. The encoder is pre-trained using reconstructin, rotation prediction and contrastive learning pre-text tasks as shown below. For more details, please refer to [1] (CVPR paper) and see this [repository](https://github.com/Project-MONAI/research-contributions/tree/main/SwinUNETR/Pretrain). \n",
100100
"\n",
101-
"![image](https://lh3.googleusercontent.com/pw/AM-JKLVLgduGZ9naCSasWg09U665NBdd3UD4eLTy15wJiwbmKLS_p5WSZ2MBcRePEJO2tv9X3TkC52MsbnomuPy5JT3vSVeCji1MOEuAzcsxily88TdbHuAt6PzccefwKupbXyOCumK5hzz5Ul38kZnlEQ84=w397-h410-no?authuser=2)\n",
102-
"\n",
103101
"Please download the pre-trained weights from this [link](https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/model_swinvit.pt) and place it in the root directory of this tutorial. \n",
104102
"\n",
105103
"If training from scratch is desired, please skip the step for initializing from pre-trained weights. "
@@ -321,7 +319,7 @@
321319
"\n",
322320
"3. Make a JSON file to define train/val split and other relevant parameters. Place the JSON file at `./data/dataset_0.json`.\n",
323321
"\n",
324-
" You can download an example of the JSON file [here](https://drive.google.com/file/d/1qcGh41p-rI3H_sQ0JwOAhNiQSXriQqGi/view?usp=sharing), or, equivalently, use the following `wget` command. If you would like to use this directly, please move it into the `./data` folder."
322+
" You can download an example of the JSON file [here](https://developer.download.nvidia.com/assets/Clara/monai/tutorials/swin_unetr_btcv_dataset_0.json), or, equivalently, use the following `wget` command. If you would like to use this directly, please move it into the `./data` folder."
325323
]
326324
},
327325
{

active_learning/liver_tumor_al/active_learning.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
parser = argparse.ArgumentParser(description="Active Learning Setting")
5555

5656
# Directory & Json & Seed
57-
parser.add_argument("--base_dir", default="/home/vishwesh/experiments/al_sanity_test_apr27_2023", type=str)
57+
parser.add_argument("--base_dir", default="./experiments/al_sanity_test_apr27_2023", type=str)
5858
parser.add_argument("--data_root", default="/scratch_2/data_2021/68111", type=str)
5959
parser.add_argument("--json_path", default="/scratch_2/data_2021/68111/dataset_val_test_0_debug.json", type=str)
6060
parser.add_argument("--seed", default=102, type=int)

active_learning/liver_tumor_al/runner.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ python active_learning.py --base_dir ${LOG_DIR}/all_data_iter2k --data_root ${DA
2222
python active_learning.py --base_dir ${LOG_DIR}/random_i5_q5_iter2k --data_root ${DATA_ROOT} --json_path ${JSON_PATH} --seed 3840 --active_iters 6 --dropout_ratio 0.2 --mc_number 10 --initial_pool 5 --queries 5 --strategy random --steps 2000 --val_interval 1 --batch_size 1 --val_batch_size 1 --lr 1e-4
2323

2424
# # Initial Pool 5 Queries 5 Variance Strategy
25-
python active_learning.py --base_dir ${LOG_DIR}/variance_i5_q5_iter2k --data_root ${DATA_ROOT} --json_path ${JSON_PATH} --seed 3840 --active_iters 6 --dropout_ratio 0.2 --mc_number 10 --initial_pool 5 --queries 5 --strategy random --steps 2000 --val_interval 1 --batch_size 1 --val_batch_size 1 --lr 1e-4
25+
python active_learning.py --base_dir ${LOG_DIR}/variance_i5_q5_iter2k --data_root ${DATA_ROOT} --json_path ${JSON_PATH} --seed 3840 --active_iters 6 --dropout_ratio 0.2 --mc_number 10 --initial_pool 5 --queries 5 --strategy variance --steps 2000 --val_interval 1 --batch_size 1 --val_batch_size 1 --lr 1e-4

active_learning/tool_tracking_al/active_learning.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
parser = argparse.ArgumentParser(description="Active Learning Settings")
4848

4949
# Directory & Json & Seed
50-
parser.add_argument("--base_dir", default="/home/vishwesh/experiments/robo_tool_experiments/variance_sanity", type=str)
50+
parser.add_argument("--base_dir", default="./experiments/robo_tool_experiments/variance_sanity", type=str)
5151
parser.add_argument("--data_root", default="/scratch_2/robo_tool_dataset_2023", type=str)
5252
parser.add_argument("--json_path", default="/scratch_2/robo_tool_dataset_2023/data_list.json", type=str)
5353
parser.add_argument("--seed", default=120, type=int)
@@ -469,10 +469,10 @@ def main():
469469
variance = np.sum(np.nanvar(vol_input, axis=0), axis=0)
470470

471471
score_list.append(np.nanmean(variance))
472-
name_list.append(unl_data["image_meta_dict"]["filename_or_obj"][0])
472+
name_list.append(unl_data["image"].meta["filename_or_obj"][0])
473473
print(
474474
"Variance for image: {} is: {}".format(
475-
unl_data["image_meta_dict"]["filename_or_obj"][0], np.nanmean(variance)
475+
unl_data["image"].meta["filename_or_obj"][0], np.nanmean(variance)
476476
)
477477
)
478478

active_learning/tool_tracking_al/results_uncertainty_analysis.ipynb

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
},
3636
{
3737
"cell_type": "code",
38-
"execution_count": 2,
38+
"execution_count": 1,
3939
"id": "d5b36e92",
4040
"metadata": {},
4141
"outputs": [],
@@ -56,37 +56,40 @@
5656
},
5757
{
5858
"cell_type": "code",
59-
"execution_count": 3,
59+
"execution_count": 2,
6060
"id": "57ef4a1b",
6161
"metadata": {},
6262
"outputs": [
6363
{
6464
"name": "stdout",
6565
"output_type": "stream",
6666
"text": [
67-
"MONAI version: 1.0.1\n",
68-
"Numpy version: 1.23.4\n",
69-
"Pytorch version: 1.13.0+cu117\n",
67+
"MONAI version: 1.4.0rc10\n",
68+
"Numpy version: 1.24.4\n",
69+
"Pytorch version: 2.5.0a0+872d972e41.nv24.08.01\n",
7070
"MONAI flags: HAS_EXT = False, USE_COMPILED = False, USE_META_DICT = False\n",
71-
"MONAI rev id: 8271a193229fe4437026185e218d5b06f7c8ce69\n",
72-
"MONAI __file__: /home/vishwesh/anaconda3/envs/mtk_py38/lib/python3.8/site-packages/monai/__init__.py\n",
71+
"MONAI rev id: cac21f6936a2e8d6e4e57e4e958f8e32aae1585e\n",
72+
"MONAI __file__: /usr/local/lib/python3.10/dist-packages/monai/__init__.py\n",
7373
"\n",
7474
"Optional dependencies:\n",
75-
"Pytorch Ignite version: 0.4.10\n",
76-
"Nibabel version: 4.0.2\n",
77-
"scikit-image version: 0.19.3\n",
78-
"Pillow version: 9.3.0\n",
79-
"Tensorboard version: 2.11.0\n",
80-
"gdown version: 4.5.3\n",
81-
"TorchVision version: 0.14.0+cu117\n",
82-
"tqdm version: 4.64.1\n",
83-
"lmdb version: 1.3.0\n",
84-
"psutil version: 5.9.0\n",
85-
"pandas version: 1.5.1\n",
86-
"einops version: 0.6.0\n",
87-
"transformers version: 4.21.3\n",
88-
"mlflow version: 2.0.1\n",
89-
"pynrrd version: 0.4.3\n",
75+
"Pytorch Ignite version: 0.4.11\n",
76+
"ITK version: 5.4.0\n",
77+
"Nibabel version: 5.2.1\n",
78+
"scikit-image version: 0.23.2\n",
79+
"scipy version: 1.13.1\n",
80+
"Pillow version: 10.4.0\n",
81+
"Tensorboard version: 2.17.0\n",
82+
"gdown version: 5.2.0\n",
83+
"TorchVision version: 0.20.0a0\n",
84+
"tqdm version: 4.66.4\n",
85+
"lmdb version: 1.5.1\n",
86+
"psutil version: 5.9.8\n",
87+
"pandas version: 2.2.2\n",
88+
"einops version: 0.7.0\n",
89+
"transformers version: 4.40.2\n",
90+
"mlflow version: 2.16.0\n",
91+
"pynrrd version: 1.0.0\n",
92+
"clearml version: 1.16.3\n",
9093
"\n",
9194
"For details about installing the optional dependencies, please visit:\n",
9295
" https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies\n",
@@ -136,7 +139,7 @@
136139
},
137140
{
138141
"cell_type": "code",
139-
"execution_count": 4,
142+
"execution_count": 3,
140143
"id": "1d14c99c",
141144
"metadata": {},
142145
"outputs": [
@@ -188,7 +191,7 @@
188191
").cuda()\n",
189192
"\n",
190193
"# Load Model Weights\n",
191-
"model.load_state_dict(torch.load(model_ckpt))\n",
194+
"model.load_state_dict(torch.load(model_ckpt, weights_only=True))\n",
192195
"\n",
193196
"# Please note that the model is being put to 'train' mode explicitly for Monte-Carlo simulations\n",
194197
"model.train()\n",
@@ -197,16 +200,16 @@
197200
},
198201
{
199202
"cell_type": "code",
200-
"execution_count": 5,
203+
"execution_count": 4,
201204
"id": "22b9db61",
202205
"metadata": {},
203206
"outputs": [
204207
{
205208
"name": "stdout",
206209
"output_type": "stream",
207210
"text": [
208-
"/scratch_2/robo_tool_dataset_2023/robo_tool/dv13_00098.png\n",
209-
"Variance for image: /scratch_2/robo_tool_dataset_2023/robo_tool/dv13_00098.png is: 0.0021140489261597395\n"
211+
"/workspace/Data/robo_tool/dv13_00098.png\n",
212+
"Variance for image: /workspace/Data/robo_tool/dv13_00098.png is: 0.005063239950686693\n"
210213
]
211214
},
212215
{
@@ -286,7 +289,7 @@
286289
},
287290
{
288291
"cell_type": "code",
289-
"execution_count": null,
292+
"execution_count": 5,
290293
"id": "cc913015",
291294
"metadata": {},
292295
"outputs": [],
@@ -344,9 +347,9 @@
344347
],
345348
"metadata": {
346349
"kernelspec": {
347-
"display_name": "mtk_py38",
350+
"display_name": "Python 3",
348351
"language": "python",
349-
"name": "mtk_py38"
352+
"name": "python3"
350353
},
351354
"language_info": {
352355
"codemirror_mode": {
@@ -358,7 +361,7 @@
358361
"name": "python",
359362
"nbconvert_exporter": "python",
360363
"pygments_lexer": "ipython3",
361-
"version": "3.8.15"
364+
"version": "3.10.12"
362365
}
363366
},
364367
"nbformat": 4,

active_learning/tool_tracking_al/runner.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ python active_learning.py --base_dir ${LOG_DIR}/all_data_iter5k --data_root ${DA
2222
python active_learning.py --base_dir ${LOG_DIR}/random_i15_q15_iter5k --data_root ${DATA_ROOT} --json_path ${JSON_PATH} --seed 240 --active_iters 5 --dropout_ratio 0.2 --mc_number 10 --initial_pool 20 --queries 20 --strategy random --steps 5000 --val_interval 1 --batch_size 1 --val_batch_size 1 --lr 1e-4
2323

2424
# Initial Pool 20 Queries 20 Variance Strategy
25-
python active_learning.py --base_dir ${LOG_DIR}/variance_i15_q15_iter5k --data_root ${DATA_ROOT} --json_path ${JSON_PATH} --seed 240 --active_iters 5 --dropout_ratio 0.2 --mc_number 10 --initial_pool 20 --queries 20 --strategy random --steps 5000 --val_interval 1 --batch_size 1 --val_batch_size 1 --lr 1e-4
25+
python active_learning.py --base_dir ${LOG_DIR}/variance_i15_q15_iter5k --data_root ${DATA_ROOT} --json_path ${JSON_PATH} --seed 240 --active_iters 5 --dropout_ratio 0.2 --mc_number 10 --initial_pool 20 --queries 20 --strategy variance --steps 5000 --val_interval 1 --batch_size 1 --val_batch_size 1 --lr 1e-4

generation/2d_ldm/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ torchrun \
5757
--master_addr=localhost --master_port=1234 \
5858
train_autoencoder.py -c ./config/config_train_32g.json -e ./config/environment.json -g ${NUM_GPUS_PER_NODE}
5959
```
60+
Please note that during multi-GPU training, additional GPU memory may be required. Users might need to reduce the `batch_size` accordingly based on their available resources to ensure smooth training.
6061

6162
<p align="center">
6263
<img src="./figs/train_recon.png" alt="autoencoder train curve" width="45%" >
@@ -88,6 +89,8 @@ torchrun \
8889
--master_addr=localhost --master_port=1234 \
8990
train_diffusion.py -c ./config/config_train_32g.json -e ./config/environment.json -g ${NUM_GPUS_PER_NODE}
9091
```
92+
Please note that during multi-GPU training, additional GPU memory may be required. Users might need to reduce the `batch_size` accordingly based on their available resources to ensure smooth training.
93+
9194
<p align="center">
9295
<img src="./figs/train_diffusion.png" alt="latent diffusion train curve" width="45%" >
9396
&nbsp; &nbsp; &nbsp; &nbsp;

generation/2d_vqvae/2d_vqvae_tutorial.ipynb

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,15 @@
2525
"\n",
2626
"The VQVAE can also be used as a generative model if an autoregressor model (e.g., PixelCNN, Decoder Transformer) is trained on the discrete latent representations of the VQVAE bottleneck. This falls outside of the scope of this tutorial.\n",
2727
"\n",
28-
"[1] - Oord et al. \"Neural Discrete Representation Learning\" https://arxiv.org/abs/1711.00937\n",
29-
"\n",
30-
"\n",
31-
"### Setup environment"
28+
"[1] - Oord et al. \"Neural Discrete Representation Learning\" https://arxiv.org/abs/1711.00937"
29+
]
30+
},
31+
{
32+
"cell_type": "markdown",
33+
"id": "d167a850",
34+
"metadata": {},
35+
"source": [
36+
"## Setup environment"
3237
]
3338
},
3439
{
@@ -50,7 +55,7 @@
5055
"id": "6b8ae5e8",
5156
"metadata": {},
5257
"source": [
53-
"### Setup imports"
58+
"## Setup imports"
5459
]
5560
},
5661
{
@@ -118,32 +123,16 @@
118123
"print_config()"
119124
]
120125
},
121-
{
122-
"cell_type": "code",
123-
"execution_count": 2,
124-
"id": "f7f7056e",
125-
"metadata": {},
126-
"outputs": [],
127-
"source": [
128-
"# for reproducibility purposes set a seed\n",
129-
"set_determinism(42)"
130-
]
131-
},
132-
{
133-
"cell_type": "markdown",
134-
"id": "51a9a628",
135-
"metadata": {},
136-
"source": [
137-
"### Setup a data directory and download dataset"
138-
]
139-
},
140126
{
141127
"cell_type": "markdown",
142128
"id": "9b9b6e14",
143129
"metadata": {},
144130
"source": [
145-
"Specify a `MONAI_DATA_DIRECTORY` variable, where the data will be downloaded. If not\n",
146-
"specified a temporary directory will be used."
131+
"## Setup data directory\n",
132+
"\n",
133+
"You can specify a directory with the `MONAI_DATA_DIRECTORY` environment variable. \n",
134+
"This allows you to save results and reuse downloads. \n",
135+
"If not specified a temporary directory will be used."
147136
]
148137
},
149138
{
@@ -166,12 +155,30 @@
166155
"print(root_dir)"
167156
]
168157
},
158+
{
159+
"cell_type": "markdown",
160+
"id": "d49ee071",
161+
"metadata": {},
162+
"source": [
163+
"## Set deterministic"
164+
]
165+
},
166+
{
167+
"cell_type": "code",
168+
"execution_count": null,
169+
"id": "3b010865",
170+
"metadata": {},
171+
"outputs": [],
172+
"source": [
173+
"set_determinism(42)"
174+
]
175+
},
169176
{
170177
"cell_type": "markdown",
171178
"id": "049661aa",
172179
"metadata": {},
173180
"source": [
174-
"### Download the training set"
181+
"## Download the training set"
175182
]
176183
},
177184
{
@@ -248,7 +255,7 @@
248255
"id": "d437adbd",
249256
"metadata": {},
250257
"source": [
251-
"### Visualise examples from the training set"
258+
"## Visualise examples from the training set"
252259
]
253260
},
254261
{
@@ -282,7 +289,7 @@
282289
"id": "8c6ca19a",
283290
"metadata": {},
284291
"source": [
285-
"### Download the validation set"
292+
"## Download the validation set"
286293
]
287294
},
288295
{
@@ -327,7 +334,7 @@
327334
"id": "1cfa9906",
328335
"metadata": {},
329336
"source": [
330-
"### Define network, optimizer and losses"
337+
"## Define network, optimizer and losses"
331338
]
332339
},
333340
{
@@ -377,7 +384,7 @@
377384
"id": "331aa4fc",
378385
"metadata": {},
379386
"source": [
380-
"### Model training\n",
387+
"## Model training\n",
381388
"Here, we are training our model for 100 epochs (training time: ~60 minutes)."
382389
]
383390
},
@@ -474,7 +481,7 @@
474481
"id": "ab3f5e08",
475482
"metadata": {},
476483
"source": [
477-
"### Learning curves"
484+
"## Learning curves"
478485
]
479486
},
480487
{
@@ -518,7 +525,7 @@
518525
"id": "e7c7b3b4",
519526
"metadata": {},
520527
"source": [
521-
"### Plotting evolution of reconstructed images"
528+
"## Plotting evolution of reconstructed images"
522529
]
523530
},
524531
{
@@ -559,7 +566,7 @@
559566
"id": "517f51ea",
560567
"metadata": {},
561568
"source": [
562-
"### Plotting the reconstructions from final trained model"
569+
"## Plotting the reconstructions from final trained model"
563570
]
564571
},
565572
{
@@ -595,7 +602,7 @@
595602
"id": "222c56d3",
596603
"metadata": {},
597604
"source": [
598-
"### Cleanup data directory\n",
605+
"## Cleanup data directory\n",
599606
"\n",
600607
"Remove directory if a temporary was used."
601608
]

0 commit comments

Comments
 (0)