|
90 | 90 | "outputs": [], |
91 | 91 | "source": [ |
92 | 92 | "in_dir = r'../data' # directory where portpy raw data is located\n", |
93 | | - "out_dir = r'../ai_data' # directory where processed data to be stored for training and testing model" |
| 93 | + "out_dir = r'../ai_data_lungs' # directory where processed data to be stored for training and testing model" |
94 | 94 | ] |
95 | 95 | }, |
96 | 96 | { |
|
101 | 101 | "outputs": [], |
102 | 102 | "source": [ |
103 | 103 | "# preprocess portpy data before the training\n", |
104 | | - "data_preprocess(in_dir, out_dir)" |
| 104 | + "# preprocess portpy data\n", |
| 105 | + "data_preprocess(in_dir, out_dir, site='lung', protocol_name='Lung_2Gy_30Fx', technique_name='imrt')\n", |
| 106 | + "# for prostate vmat patients, use below code to preprocess the data. You can change the protocol name and technique name as per your requirement\n", |
| 107 | + "# beam_ids = np.arange(0, 72)\n", |
| 108 | + "# data_preprocess(in_dir, out_dir, site='prostate', protocol_name='Prostate_5Fx', beam_ids = beam_ids, technique_name='vmat')" |
105 | 109 | ] |
106 | 110 | }, |
107 | 111 | { |
|
141 | 145 | "metadata": {}, |
142 | 146 | "outputs": [], |
143 | 147 | "source": [ |
| 148 | + "# Provide only the arguments you want to override\n", |
144 | 149 | "# Provide only the arguments you want to override\n", |
145 | 150 | "train_options = {\n", |
146 | | - " \"dataroot\": \"../ai_data\", # Directory where post-processed training/validation data is located. \n", |
147 | | - " \"checkpoints_dir\": \"../checkpoints\", # Directory to save model checkpoints during training\n", |
148 | | - " \"netG\": \"unet_128\", # Generator architecture to use; e.g., 3D UNet with input size 128x128x128\n", |
149 | | - " \"name\": \"portpy_test_3\", # Name of the training experiment; determines subdirectory for logs and models\n", |
150 | | - " \"model\": \"doseprediction3d\", # Type of model being trained; for 3D dose prediction tasks\n", |
151 | | - " \"direction\": \"AtoB\", # Data flow direction; 'AtoB' means input (A) to predicted dose (B)\n", |
152 | | - " \"lambda_L1\": 1, # Weight for the L1 loss term in the total loss function\n", |
153 | | - " \"dataset_mode\": \"dosepred3d\", # Dataset class to use for loading 3D dose prediction data\n", |
154 | | - " \"norm\": \"batch\", # Type of normalization layer to use ('batch', 'instance', etc.)\n", |
155 | | - " \"batch_size\": 1, # Number of samples per training batch\n", |
156 | | - " \"pool_size\": 0, # Size of image buffer for previously generated images (0 disables the buffer)\n", |
157 | | - " \"display_port\": 8097, # Port to use for Visdom visualization server (if enabled)\n", |
158 | | - " \"lr\": 0.0002, # Initial learning rate for the optimizer\n", |
159 | | - " \"input_nc\": 8, # Number of input channels (e.g., CT + structure masks)\n", |
160 | | - " \"output_nc\": 1, # Number of output channels (e.g., predicted dose volume)\n", |
161 | | - " \"display_freq\": 10, # Frequency (in steps) of displaying images during training\n", |
162 | | - " \"print_freq\": 1, # Frequency (in steps) of printing training losses to console\n", |
163 | | - " \"gpu_ids\": [0] # List of GPU IDs to use; e.g., [0] for single-GPU or [0,1] for multi-GPU\n", |
| 151 | + " \"dataroot\": \"../../ai_data_lungs\", # directory where processed data is located for training and testing model\n", |
| 152 | + " \"checkpoints_dir\": \"../../checkpoints\", # directory where model checkpoints will be saved during training\n", |
| 153 | + " \"netG\": \"mednext\", # type of generator network architecture to be used for training. PortPy uses a baseline 3D U-Net architecture for model training. If desired, users can define their own architectures by modifying the networks_3d.py file located in the model directory of the portpy.ai module.\n", |
| 154 | + " \"dose_loss\": \"mednext_hybrid\", # dose less function. it can be customized\n", |
| 155 | + " \"name\": \"portpy_lung_mednext\", # experiment name\n", |
| 156 | + " \"model\": \"doseprediction3d\", # type of model to be trained\n", |
| 157 | + " \"direction\": \"AtoB\",\n", |
| 158 | + " \"lambda_L1\": 1,\n", |
| 159 | + " \"dataset_mode\": \"dosepred3d\",\n", |
| 160 | + " \"norm\": \"batch\",\n", |
| 161 | + " \"batch_size\": 1,\n", |
| 162 | + " \"pool_size\": 0,\n", |
| 163 | + " \"display_port\": 8097,\n", |
| 164 | + " \"lr\": 0.0001,\n", |
| 165 | + " \"n_epochs\": 100,\n", |
| 166 | + " \"input_nc\": 8,\n", |
| 167 | + " \"output_nc\": 1,\n", |
| 168 | + " \"display_freq\": 10,\n", |
| 169 | + " \"display_id\":-1,\n", |
| 170 | + " \"print_freq\": 1,\n", |
| 171 | + " \"augment\": False, # transform images for data augmentation\n", |
| 172 | + " \"gpu_ids\": [0], # Converted to a list since multiple GPUs may be supported\n", |
| 173 | + " \"val_phase\": \"val\",\n", |
| 174 | + " \"lr_policy\": \"plateau\"\n", |
164 | 175 | "}\n", |
165 | 176 | "\n", |
166 | 177 | "train(train_options) # Run training directly in Jupyter Notebook" |
|
174 | 185 | "outputs": [], |
175 | 186 | "source": [ |
176 | 187 | "# You can uncomment and run below in case if you want to run train script from CLI\n", |
177 | | - "#!python ../portpy/ai/train.py --dataroot ../ai_data --netG unet_128 --name portpy_test_3 --model doseprediction3d --direction AtoB --lambda_L1 1 --dataset_mode dosepred3d --norm batch --batch_size 1 --pool_size 0 --display_port 8097 --lr 0.0002 --input_nc 8 --output_nc 1 --display_freq 10 --print_freq 1 --gpu_ids 0" |
| 188 | + "#!python ../portpy/ai/train.py --dataroot ../ai_data_lungs --netG mednext --name portpy_lung_mednext --model doseprediction3d --direction AtoB --lambda_L1 1 --dataset_mode dosepred3d --dose_loss mednext_hybrid --norm batch --batch_size 1 --pool_size 0 --display_port 8097 --lr 0.0002 --input_nc 8 --output_nc 1 --display_freq 10 --print_freq 1 --gpu_ids 0" |
178 | 189 | ] |
179 | 190 | }, |
180 | 191 | { |
|
193 | 204 | "outputs": [], |
194 | 205 | "source": [ |
195 | 206 | "test_options = {\n", |
196 | | - " \"dataroot\": \"../ai_data\", # Directory where test data is located (post-processed format)\n", |
197 | | - " \"netG\": \"unet_128\", # Generator architecture to use; should match the model used during training\n", |
198 | | - " \"checkpoints_dir\": \"../checkpoints\", # Directory where trained model checkpoints are stored\n", |
199 | | - " \"results_dir\": \"../results\", # Directory to save test outputs (e.g., predicted dose volumes)\n", |
200 | | - " \"name\": \"portpy_test_3\", # Name of the experiment; used to locate the corresponding checkpoint\n", |
201 | | - " \"phase\": \"test\", # Indicates the current phase ('train', 'val', or 'test')\n", |
202 | | - " \"mode\": \"eval\", # Mode of operation; should be 'eval' to run inference\n", |
203 | | - " \"eval\": True, # If True, sets the model to evaluation mode (disables dropout, batch norm updates)\n", |
204 | | - " \"model\": \"doseprediction3d\", # Type of model to load; should match the training configuration\n", |
205 | | - " \"input_nc\": 8, # Number of input channels; must be consistent with the trained model\n", |
206 | | - " \"output_nc\": 1, # Number of output channels; typically 1 for dose prediction\n", |
207 | | - " \"direction\": \"AtoB\", # Data flow direction; must be consistent with training\n", |
208 | | - " \"dataset_mode\": \"dosepred3d\", # Dataset loader to use for loading test data\n", |
209 | | - " \"norm\": \"batch\" # Type of normalization used in the model; must match training setup\n", |
210 | | - "}" |
| 207 | + " \"dataroot\": \"../../ai_data_lungs\",\n", |
| 208 | + " \"netG\": \"mednext\",\n", |
| 209 | + " \"checkpoints_dir\": \"../../checkpoints\",\n", |
| 210 | + " \"results_dir\": \"../../results\",\n", |
| 211 | + " 'dose_loss': 'mednext_hybrid',\n", |
| 212 | + " \"name\": \"portpy_lung_mednext\",\n", |
| 213 | + " \"phase\": \"test\",\n", |
| 214 | + " \"mode\": \"eval\",\n", |
| 215 | + " \"eval\": True, # Boolean flag\n", |
| 216 | + " \"model\": \"doseprediction3d\",\n", |
| 217 | + " \"input_nc\": 8,\n", |
| 218 | + " \"output_nc\": 1,\n", |
| 219 | + " \"direction\": \"AtoB\",\n", |
| 220 | + " \"dataset_mode\": \"dosepred3d\",\n", |
| 221 | + " \"norm\": \"batch\"\n", |
| 222 | + "}\n", |
| 223 | + "test(test_options)" |
211 | 224 | ] |
212 | 225 | }, |
213 | 226 | { |
|
250 | 263 | "source": [ |
251 | 264 | "# For users who does not want to train and test, they can directly preprocess portpy data for dose predicition pipeline and predict using AI model\n", |
252 | 265 | "patient_id = 'Lung_Patient_4'\n", |
253 | | - "model_name = 'portpy_test_3'\n", |
254 | | - "pred_dose = predict_using_model(patient_id=patient_id, in_dir=in_dir, out_dir=out_dir, model_name=model_name, checkpoints_dir='../checkpoints', results_dir='../results')" |
| 266 | + "model_name = 'portpy_lung_mednext'\n", |
| 267 | + "pred_dose = predict_using_model(patient_id=patient_id, in_dir=in_dir, out_dir=out_dir, model_name=model_name, checkpoints_dir='../../checkpoints', results_dir='../../results', netG='mednext',\n", |
| 268 | + " site='lung', protocol_name='Lung_2Gy_30Fx')\n" |
255 | 269 | ] |
256 | 270 | }, |
257 | 271 | { |
|
0 commit comments