54
54
parser = argparse .ArgumentParser (description = "Active Learning Setting" )
55
55
56
56
# 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 )
58
58
parser .add_argument ("--data_root" , default = "/scratch_2/data_2021/68111" , type = str )
59
59
parser .add_argument ("--json_path" , default = "/scratch_2/data_2021/68111/dataset_val_test_0_debug.json" , type = str )
60
60
parser .add_argument ("--seed" , default = 102 , type = int )
@@ -155,7 +155,7 @@ def main():
155
155
# Model Definition
156
156
device = torch .device ("cuda:0" )
157
157
network = UNet (
158
- dimensions = 3 ,
158
+ spatial_dims = 3 ,
159
159
in_channels = 1 ,
160
160
out_channels = 3 ,
161
161
channels = (16 , 32 , 64 , 128 , 256 ),
@@ -187,7 +187,7 @@ def main():
187
187
b_max = 1.0 ,
188
188
clip = True ,
189
189
),
190
- CropForegroundd (keys = ["image" , "label" ], source_key = "image" ),
190
+ CropForegroundd (keys = ["image" , "label" ], source_key = "image" , allow_smaller = True ),
191
191
SpatialPadd (keys = ["image" , "label" ], spatial_size = (96 , 96 , 96 )),
192
192
RandCropByPosNegLabeld (
193
193
keys = ["image" , "label" ],
@@ -225,7 +225,7 @@ def main():
225
225
b_max = 1.0 ,
226
226
clip = True ,
227
227
),
228
- CropForegroundd (keys = ["image" , "label" ], source_key = "image" ),
228
+ CropForegroundd (keys = ["image" , "label" ], source_key = "image" , allow_smaller = True ),
229
229
EnsureTyped (keys = ["image" , "label" ]),
230
230
]
231
231
)
@@ -240,7 +240,7 @@ def main():
240
240
mode = ("bilinear" ),
241
241
),
242
242
ScaleIntensityRanged (keys = "image" , a_min = - 21 , a_max = 189 , b_min = 0.0 , b_max = 1.0 , clip = True ),
243
- CropForegroundd (keys = ("image" ), source_key = "image" ),
243
+ CropForegroundd (keys = ("image" ), source_key = "image" , allow_smaller = True ),
244
244
EnsureTyped (keys = ["image" ]),
245
245
]
246
246
)
@@ -315,7 +315,7 @@ def main():
315
315
unl_loader = DataLoader (unl_ds , batch_size = 1 )
316
316
317
317
# Calculation of Epochs based on steps
318
- max_epochs = np . int (args .steps / (np .ceil (len (train_d ) / args .batch_size )))
318
+ max_epochs = int (args .steps / (np .ceil (len (train_d ) / args .batch_size )))
319
319
print ("Epochs Estimated are {} for Active Iter {} with {} Vols" .format (max_epochs , active_iter , len (train_d )))
320
320
321
321
# Model Training begins for one active iteration
@@ -393,7 +393,7 @@ def main():
393
393
prev_best_ckpt = os .path .join (active_model_dir , "model.pt" )
394
394
395
395
device = torch .device ("cuda:0" )
396
- ckpt = torch .load (prev_best_ckpt )
396
+ ckpt = torch .load (prev_best_ckpt , weights_only = True )
397
397
network .load_state_dict (ckpt )
398
398
network .to (device = device )
399
399
@@ -487,16 +487,16 @@ def main():
487
487
488
488
variance_dims = np .shape (variance )
489
489
score_list .append (np .nanmean (variance ))
490
- name_list .append (unl_data ["image_meta_dict" ] ["filename_or_obj" ][0 ])
490
+ name_list .append (unl_data ["image" ]. meta ["filename_or_obj" ][0 ])
491
491
print (
492
492
"Variance for image: {} is: {}" .format (
493
- unl_data ["image_meta_dict" ] ["filename_or_obj" ][0 ], np .nanmean (variance )
493
+ unl_data ["image" ]. meta ["filename_or_obj" ][0 ], np .nanmean (variance )
494
494
)
495
495
)
496
496
497
497
# Plot with matplotlib and save all slices
498
498
plt .figure (1 )
499
- plt .imshow (np .squeeze (variance [:, :, np . int (variance_dims [2 ] / 2 )]))
499
+ plt .imshow (np .squeeze (variance [:, :, int (variance_dims [2 ] / 2 )]))
500
500
plt .colorbar ()
501
501
plt .title ("Dropout Uncertainty" )
502
502
fig_path = os .path .join (fig_base_dir , "active_{}_file_{}.png" .format (active_iter , counter ))
0 commit comments