Skip to content

Commit

Permalink
450 update AsDiscrete (#451)
Browse files Browse the repository at this point in the history
* update asdiscrete

Signed-off-by: Yiheng Wang <vennw@nvidia.com>

* update postprocessing figures

Signed-off-by: Yiheng Wang <vennw@nvidia.com>

* fix version error of mutual info

Signed-off-by: Yiheng Wang <vennw@nvidia.com>

* update to use include in torchin

Signed-off-by: Yiheng Wang <vennw@nvidia.com>
  • Loading branch information
yiheng-wang-nv authored Nov 26, 2021
1 parent 2c63c42 commit bc34263
Show file tree
Hide file tree
Showing 60 changed files with 158 additions and 157 deletions.
6 changes: 3 additions & 3 deletions 2d_classification/mednist_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@
" [LoadImage(image_only=True), AddChannel(), ScaleIntensity(), EnsureType()])\n",
"\n",
"y_pred_trans = Compose([EnsureType(), Activations(softmax=True)])\n",
"y_trans = Compose([EnsureType(), AsDiscrete(to_onehot=True, num_classes=num_class)])"
"y_trans = Compose([EnsureType(), AsDiscrete(to_onehot=num_class)])"
]
},
{
Expand Down Expand Up @@ -1328,7 +1328,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -1342,7 +1342,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.8.12"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion 2d_segmentation/torch/unet_evaluation_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def main(tempdir):
# sliding window inference for one image at every iteration
val_loader = DataLoader(val_ds, batch_size=1, num_workers=1, pin_memory=torch.cuda.is_available())
dice_metric = DiceMetric(include_background=True, reduction="mean", get_not_nans=False)
post_trans = Compose([EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold_values=True)])
post_trans = Compose([EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold=0.5)])
saver = SaveImage(output_dir="./output", output_ext=".png", output_postfix="seg")
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = UNet(
Expand Down
2 changes: 1 addition & 1 deletion 2d_segmentation/torch/unet_evaluation_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def main(tempdir):
# sliding window inference need to input 1 image in every iteration
val_loader = DataLoader(val_ds, batch_size=1, num_workers=4, collate_fn=list_data_collate)
dice_metric = DiceMetric(include_background=True, reduction="mean", get_not_nans=False)
post_trans = Compose([EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold_values=True)])
post_trans = Compose([EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold=0.5)])
saver = SaveImage(output_dir="./output", output_ext=".png", output_postfix="seg")
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = UNet(
Expand Down
2 changes: 1 addition & 1 deletion 2d_segmentation/torch/unet_training_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def main(tempdir):
val_ds = ArrayDataset(images[-20:], val_imtrans, segs[-20:], val_segtrans)
val_loader = DataLoader(val_ds, batch_size=1, num_workers=4, pin_memory=torch.cuda.is_available())
dice_metric = DiceMetric(include_background=True, reduction="mean", get_not_nans=False)
post_trans = Compose([EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold_values=True)])
post_trans = Compose([EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold=0.5)])
# create UNet, DiceLoss and Adam optimizer
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = monai.networks.nets.UNet(
Expand Down
2 changes: 1 addition & 1 deletion 2d_segmentation/torch/unet_training_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def main(tempdir):
val_ds = monai.data.Dataset(data=val_files, transform=val_transforms)
val_loader = DataLoader(val_ds, batch_size=1, num_workers=4, collate_fn=list_data_collate)
dice_metric = DiceMetric(include_background=True, reduction="mean", get_not_nans=False)
post_trans = Compose([EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold_values=True)])
post_trans = Compose([EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold=0.5)])
# create UNet, DiceLoss and Adam optimizer
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = monai.networks.nets.UNet(
Expand Down
2 changes: 1 addition & 1 deletion 3d_classification/ignite/densenet_training_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def prepare_batch(batch, device=None, non_blocking=False):
# add evaluation metric to the evaluator engine
val_metrics = {metric_name: ROCAUC()}

post_label = Compose([EnsureType(), AsDiscrete(to_onehot=True, num_classes=2)])
post_label = Compose([EnsureType(), AsDiscrete(to_onehot=2)])
post_pred = Compose([EnsureType(), Activations(softmax=True)])
# Ignite evaluator expects batch=(img, label) and returns output=(y_pred, y) at every iteration,
# user can add output_transform to return other values
Expand Down
2 changes: 1 addition & 1 deletion 3d_classification/torch/densenet_training_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def main():
]
)
post_pred = Compose([EnsureType(), Activations(softmax=True)])
post_label = Compose([EnsureType(), AsDiscrete(to_onehot=True, num_classes=2)])

This comment has been minimized.

Copy link
@faizan1234567

faizan1234567 Jan 29, 2022

I am facing this issue. its not applying Asdiscrete transforms

post_label = Compose([EnsureType(), AsDiscrete(to_onehot=2)])

# Define dataset, data loader
check_ds = monai.data.Dataset(data=train_files, transform=train_transforms)
Expand Down
6 changes: 3 additions & 3 deletions 3d_segmentation/brats_segmentation_3d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@
"dice_metric_batch = DiceMetric(include_background=True, reduction=\"mean_batch\")\n",
"\n",
"post_trans = Compose(\n",
" [EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold_values=True)]\n",
" [EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold=0.5)]\n",
")\n",
"\n",
"\n",
Expand Down Expand Up @@ -815,7 +815,7 @@
" to_tensor=True,\n",
" ),\n",
" Activationsd(keys=\"pred\", sigmoid=True),\n",
" AsDiscreted(keys=\"pred\", threshold_values=True),\n",
" AsDiscreted(keys=\"pred\", threshold=0.5),\n",
"])"
]
},
Expand Down Expand Up @@ -899,7 +899,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.8.12"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion 3d_segmentation/challenge_baseline/run_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def train(data_folder=".", model_folder="runs"):

# create evaluator (to be used to measure model quality during training
val_post_transform = monai.transforms.Compose(
[EnsureTyped(keys=("pred", "label")), AsDiscreted(keys=("pred", "label"), argmax=(True, False), to_onehot=True, num_classes=2)]
[EnsureTyped(keys=("pred", "label")), AsDiscreted(keys=("pred", "label"), argmax=(True, False), to_onehot=2)]
)
val_handlers = [
ProgressBar(),
Expand Down
2 changes: 1 addition & 1 deletion 3d_segmentation/ignite/unet_evaluation_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def main(tempdir):
roi_size = (96, 96, 96)
sw_batch_size = 4

post_trans = Compose([EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold_values=True)])
post_trans = Compose([EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold=0.5)])
save_image = SaveImage(output_dir="tempdir", output_ext=".nii.gz", output_postfix="seg")

def _sliding_window_processor(engine, batch):
Expand Down
2 changes: 1 addition & 1 deletion 3d_segmentation/ignite/unet_evaluation_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def main(tempdir):
roi_size = (96, 96, 96)
sw_batch_size = 4

post_trans = Compose([EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold_values=True)])
post_trans = Compose([EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold=0.5)])
save_image = SaveImage(output_dir="tempdir", output_ext=".nii.gz", output_postfix="seg")

def _sliding_window_processor(engine, batch):
Expand Down
4 changes: 2 additions & 2 deletions 3d_segmentation/ignite/unet_training_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ def main(tempdir):
# add evaluation metric to the evaluator engine
val_metrics = {metric_name: MeanDice()}

post_pred = Compose([EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold_values=True)])
post_label = Compose([EnsureType(), AsDiscrete(threshold_values=True)])
post_pred = Compose([EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold=0.5)])
post_label = Compose([EnsureType(), AsDiscrete(threshold=0.5)])

# Ignite evaluator expects batch=(img, seg) and returns output=(y_pred, y) at every iteration,
# user can add output_transform to return other values
Expand Down
4 changes: 2 additions & 2 deletions 3d_segmentation/ignite/unet_training_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ def prepare_batch(batch, device=None, non_blocking=False):
# add evaluation metric to the evaluator engine
val_metrics = {metric_name: MeanDice()}

post_pred = Compose([EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold_values=True)])
post_label = Compose([EnsureType(), AsDiscrete(threshold_values=True)])
post_pred = Compose([EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold=0.5)])
post_label = Compose([EnsureType(), AsDiscrete(threshold=0.5)])

# Ignite evaluator expects batch=(img, seg) and returns output=(y_pred, y) at every iteration,
# user can add output_transform to return other values
Expand Down
10 changes: 5 additions & 5 deletions 3d_segmentation/spleen_segmentation_3d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,8 @@
"best_metric_epoch = -1\n",
"epoch_loss_values = []\n",
"metric_values = []\n",
"post_pred = Compose([EnsureType(), AsDiscrete(argmax=True, to_onehot=True, num_classes=2)])\n",
"post_label = Compose([EnsureType(), AsDiscrete(to_onehot=True, num_classes=2)])\n",
"post_pred = Compose([EnsureType(), AsDiscrete(argmax=True, to_onehot=2)])\n",
"post_label = Compose([EnsureType(), AsDiscrete(to_onehot=2)])\n",
"\n",
"for epoch in range(max_epochs):\n",
" print(\"-\" * 10)\n",
Expand Down Expand Up @@ -720,8 +720,8 @@
" nearest_interp=False,\n",
" to_tensor=True,\n",
" ),\n",
" AsDiscreted(keys=\"pred\", argmax=True, to_onehot=True, num_classes=2),\n",
" AsDiscreted(keys=\"label\", to_onehot=True, num_classes=2),\n",
" AsDiscreted(keys=\"pred\", argmax=True, to_onehot=2),\n",
" AsDiscreted(keys=\"label\", to_onehot=2),\n",
"])"
]
},
Expand Down Expand Up @@ -799,7 +799,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.8.12"
}
},
"nbformat": 4,
Expand Down
6 changes: 3 additions & 3 deletions 3d_segmentation/spleen_segmentation_3d_lightning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@
" norm=Norm.BATCH,\n",
" )\n",
" self.loss_function = DiceLoss(to_onehot_y=True, softmax=True)\n",
" self.post_pred = Compose([EnsureType(), AsDiscrete(argmax=True, to_onehot=True, num_classes=2)])\n",
" self.post_label = Compose([EnsureType(), AsDiscrete(to_onehot=True, num_classes=2)])\n",
" self.post_pred = Compose([EnsureType(), AsDiscrete(argmax=True, to_onehot=2)])\n",
" self.post_label = Compose([EnsureType(), AsDiscrete(to_onehot=2)])\n",
" self.dice_metric = DiceMetric(include_background=False, reduction=\"mean\", get_not_nans=False)\n",
" self.best_val_dice = 0\n",
" self.best_val_epoch = 0\n",
Expand Down Expand Up @@ -704,7 +704,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.8.12"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion 3d_segmentation/torch/unet_evaluation_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def main(tempdir):
# sliding window inference for one image at every iteration
val_loader = DataLoader(val_ds, batch_size=1, num_workers=1, pin_memory=torch.cuda.is_available())
dice_metric = DiceMetric(include_background=True, reduction="mean", get_not_nans=False)
post_trans = Compose([EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold_values=True)])
post_trans = Compose([EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold=0.5)])
saver = SaveImage(output_dir="./output", output_ext=".nii.gz", output_postfix="seg")
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = UNet(
Expand Down
2 changes: 1 addition & 1 deletion 3d_segmentation/torch/unet_evaluation_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def main(tempdir):
# sliding window inference need to input 1 image in every iteration
val_loader = DataLoader(val_ds, batch_size=1, num_workers=4, collate_fn=list_data_collate)
dice_metric = DiceMetric(include_background=True, reduction="mean", get_not_nans=False)
post_trans = Compose([EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold_values=True)])
post_trans = Compose([EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold=0.5)])
saver = SaveImage(output_dir="./output", output_ext=".nii.gz", output_postfix="seg")
# try to use all the available GPUs
devices = [torch.device("cuda" if torch.cuda.is_available() else "cpu")]
Expand Down
2 changes: 1 addition & 1 deletion 3d_segmentation/torch/unet_inference_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def main(tempdir):
# to ensure a smooth output, then execute `AsDiscreted` transform
to_tensor=True, # convert to PyTorch Tensor after inverting
),
AsDiscreted(keys="pred", threshold_values=True),
AsDiscreted(keys="pred", threshold=0.5),
SaveImaged(keys="pred", meta_keys="pred_meta_dict", output_dir="./out", output_postfix="seg", resample=False),
])

Expand Down
2 changes: 1 addition & 1 deletion 3d_segmentation/torch/unet_training_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def main(tempdir):
val_ds = ImageDataset(images[-20:], segs[-20:], transform=val_imtrans, seg_transform=val_segtrans)
val_loader = DataLoader(val_ds, batch_size=1, num_workers=4, pin_memory=torch.cuda.is_available())
dice_metric = DiceMetric(include_background=True, reduction="mean", get_not_nans=False)
post_trans = Compose([EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold_values=True)])
post_trans = Compose([EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold=0.5)])

# create UNet, DiceLoss and Adam optimizer
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
Expand Down
2 changes: 1 addition & 1 deletion 3d_segmentation/torch/unet_training_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def main(tempdir):
val_ds = monai.data.Dataset(data=val_files, transform=val_transforms)
val_loader = DataLoader(val_ds, batch_size=1, num_workers=4, collate_fn=list_data_collate)
dice_metric = DiceMetric(include_background=True, reduction="mean", get_not_nans=False)
post_trans = Compose([EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold_values=True)])
post_trans = Compose([EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold=0.5)])
# create UNet, DiceLoss and Adam optimizer
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = monai.networks.nets.UNet(
Expand Down
4 changes: 2 additions & 2 deletions 3d_segmentation/unet_segmentation_3d_catalyst.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@
"\n",
"dice_metric = DiceMetric(include_background=True, reduction=\"mean\")\n",
"post_trans = Compose(\n",
" [EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold_values=True)]\n",
" [EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold=0.5)]\n",
")"
]
},
Expand Down Expand Up @@ -678,7 +678,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.8.12"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions 3d_segmentation/unet_segmentation_3d_ignite.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@
"# add evaluation metric to the evaluator engine\n",
"val_metrics = {metric_name: MeanDice()}\n",
"post_pred = Compose(\n",
" [EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold_values=True)]\n",
" [EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold=0.5)]\n",
")\n",
"post_label = Compose([EnsureType(), AsDiscrete(threshold_values=True)])\n",

This comment has been minimized.

Copy link
@scarpma

scarpma Mar 25, 2022

Why it is AsDiscrete(threshold=0.5) and not also AsDiscrete(threshold=0.5, to_onehot=num_classes) like in the file as is in the file 3d_classification/torch/densenet_training_dict.py, for example ?

I am trying to run my own version of this notebook, but this error is appearing:

/opt/miniconda3/envs/pytorch3d/lib/python3.8/site-packages/monai/metrics/meandice.py in _compute_tensor(self, y_pred, y)
     78             raise ValueError("y_pred should have at least three dimensions.")
     79         # compute dice (BxC) for each channel for each batch
---> 80         return compute_meandice(y_pred=y_pred, y=y, include_background=self.include_background)
     81 
     82     def aggregate(self):  # type: ignore

/opt/miniconda3/envs/pytorch3d/lib/python3.8/site-packages/monai/metrics/meandice.py in compute_meandice(y_pred, y, include_background)
    121 
    122     if y.shape != y_pred.shape:
--> 123         raise ValueError("y_pred and y should have same shapes.")
    124 
    125     # reducing only spatial dimensions (not batch nor channels)

ValueError: y_pred and y should have same shapes.
"# Ignite evaluator expects batch=(img, seg) and\n",
Expand Down Expand Up @@ -541,7 +541,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.8.12"
}
},
"nbformat": 4,
Expand Down
8 changes: 4 additions & 4 deletions 3d_segmentation/unetr_btcv_segmentation_3d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,8 @@
"\n",
"max_iterations = 25000\n",
"eval_num = 500\n",
"post_label = AsDiscrete(to_onehot=True, num_classes=14)\n",
"post_pred = AsDiscrete(argmax=True, to_onehot=True, num_classes=14)\n",
"post_label = AsDiscrete(to_onehot=14)\n",
"post_pred = AsDiscrete(argmax=True, to_onehot=14)\n",
"dice_metric = DiceMetric(include_background=True, reduction=\"mean\", get_not_nans=False)\n",
"global_step = 0\n",
"dice_val_best = 0.0\n",
Expand Down Expand Up @@ -833,7 +833,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -847,7 +847,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.10"
"version": "3.8.12"
}
},
"nbformat": 4,
Expand Down
8 changes: 4 additions & 4 deletions 3d_segmentation/unetr_btcv_segmentation_3d_lightning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@
" ).to(device)\n",
"\n",
" self.loss_function = DiceCELoss(to_onehot_y=True, softmax=True)\n",
" self.post_pred = AsDiscrete(argmax=True, to_onehot=True, num_classes=14)\n",
" self.post_label = AsDiscrete(to_onehot=True, num_classes=14)\n",
" self.post_pred = AsDiscrete(argmax=True, to_onehot=14)\n",
" self.post_label = AsDiscrete(to_onehot=14)\n",
" self.dice_metric = DiceMetric(\n",
" include_background=False, reduction=\"mean\", get_not_nans=False\n",
" )\n",
Expand Down Expand Up @@ -771,7 +771,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -785,7 +785,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.10"
"version": "3.8.12"
}
},
"nbformat": 4,
Expand Down
6 changes: 3 additions & 3 deletions acceleration/automatic_mixed_precision.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@
" optimizer = torch.optim.Adam(model.parameters(), 1e-4)\n",
" scaler = torch.cuda.amp.GradScaler() if amp else None\n",
"\n",
" post_pred = Compose([EnsureType(), AsDiscrete(argmax=True, to_onehot=True, num_classes=2)])\n",
" post_label = Compose([EnsureType(), AsDiscrete(to_onehot=True, num_classes=2)])\n",
" post_pred = Compose([EnsureType(), AsDiscrete(argmax=True, to_onehot=2)])\n",
" post_label = Compose([EnsureType(), AsDiscrete(to_onehot=2)])\n",
"\n",
" dice_metric = DiceMetric(include_background=False, reduction=\"mean\", get_not_nans=False)\n",
"\n",
Expand Down Expand Up @@ -870,7 +870,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.8.12"
}
},
"nbformat": 4,
Expand Down
6 changes: 3 additions & 3 deletions acceleration/dataset_type_performance.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@
" loss_function = DiceLoss(to_onehot_y=True, softmax=True)\n",
" optimizer = torch.optim.Adam(model.parameters(), 1e-4)\n",
"\n",
" post_pred = Compose([EnsureType(), AsDiscrete(argmax=True, to_onehot=True, num_classes=2)])\n",
" post_label = Compose([EnsureType(), AsDiscrete(to_onehot=True, num_classes=2)])\n",
" post_pred = Compose([EnsureType(), AsDiscrete(argmax=True, to_onehot=2)])\n",
" post_label = Compose([EnsureType(), AsDiscrete(to_onehot=2)])\n",
"\n",
" dice_metric = DiceMetric(include_background=True, reduction=\"mean\", get_not_nans=False)\n",
"\n",
Expand Down Expand Up @@ -753,7 +753,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.8.12"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion acceleration/distributed_training/brats_training_ddp.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def main_worker(args):
dice_metric = DiceMetric(include_background=True, reduction="mean")
dice_metric_batch = DiceMetric(include_background=True, reduction="mean_batch")

post_trans = Compose([EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold_values=True)])
post_trans = Compose([EnsureType(), Activations(sigmoid=True), AsDiscrete(threshold=0.5)])

# start a typical PyTorch training
best_metric = -1
Expand Down
Loading

0 comments on commit bc34263

Please sign in to comment.