Computer Vision News - July 2020
3 Summary 19 MONAI monai_transforms = [ LoadNiftid(keys=['image', 'label']), AddChanneld(keys=['image', 'label']), Spacingd(keys=['image', 'label'], pixdim=( 1.5 , 1.5 , 2. ), mode=('bilinear', 'nearest')), Orientationd(keys=['image', 'label'], axcodes='RAS'), ScaleIntensityRanged(keys=['image'], a_min=- 57 , a_max= 164 , b_min= 0.0 , b_max= 1.0 , clip=True), CropForegroundd(keys=['image', 'label'], source_key='image') ] batch_generator_transforms = ContrastAugmentationTransform(data_key="image") torchio_transforms = RescaleIntensity(out_min_max=( 0. , 1. ), percentiles=( 0.05 , 99.5 )) rising_transforms = Mirror(dims=DiscreteParameter(( 0 , 1 , 2 )), keys=["image", "label"]) def itk_transforms (x): smoothed = list() for channel in x['image']: smoothed.append(median_image_filter(channel, radius= 2 )) x['image'] = np.stack(smoothed) return x transform = Compose(monai_transforms + [ itk_transforms, # add another dim as BatchGenerator and Rising expects shape [B, C, H, W, D] AddChanneld(keys=['image', 'label']), adaptor(batch_generator_transforms, {'image': 'image'}), ToTensord(keys=['image', 'label']), adaptor(rising_transforms, {'image': 'image', 'label': 'label'}), # squeeze shape from [B, C, H, W, D] to [C, H, W, D] for TorchIO transforms SqueezeDimd(keys=['image', 'label'], dim= 0 ), adaptor(torchio_transforms, 'image', {'image': 'data'}) ]) The above code, trained with 50 epochs, outputs similar results: The GAN example is just one of the networks available on Monai. The snippet below can be used to initialize a UNet network parametrized by the several arguments shown, and a Dice loss. Both elements are essential to perform a state-of-the-art 3d segmentation . Among the other applications, Monai also allows to combine its own transformations with 3rd party ones, provided by common libraries such as BatchGenerator, TorchIO, Rising and ITK. Remember to install these using pip beforehand. model = monai.networks.nets.UNet(dimensions= 3 , in_channels= 1 , out_channels= 2 , channels=( 16 , 32 , 64 , 128 , 256 ),strides=( 2 , 2 , 2 , 2 ), num_res_units= 2 , norm=Norm.BATCH).to(device) loss_function = monai.losses.DiceLoss(to_onehot_y=True, softmax=True)
Made with FlippingBook
RkJQdWJsaXNoZXIy NTc3NzU=