Bring your own Transforms

AIAA enables the user to bring their own transform. We will show how to write a custom transform and how to use it with AIAA.

AIAA adopted the same architecture as the dictionary transform from MONAI.

The following example is to get bounding box from each image and add those information back into the data dict.

Copy
Copied!
            

import numpy as np from monai.config import KeysCollection from monai.transforms import generate_spatial_bounding_box from monai.transforms.compose import MapTransform class BoundingBoxD(MapTransform): def __init__( self, keys: KeysCollection, result: str = 'result', bbox: str = 'bbox' ): super().__init__(keys) self.result = result self.bbox = bbox def __call__(self, data): d = dict(data) for key in self.keys: bbox = generate_spatial_bounding_box(d[key]) if d.get(self.result) is None: d[self.result] = dict() # bounding box info is added into data[self.result][self.bbox] d[self.result][self.bbox] = np.array(bbox).astype(int).tolist() return d

Assume you saved this custom transform in a file called custom_transforms.py. For AIAA to pick up, you need to copy that file inside <AIAA workspace>/lib folder.

Then you can use it in config_aiaa.json as the following:

Copy
Copied!
            

{ "name": "custom_transforms.BoundingBoxd", "args": { "keys": "pred", "result": "result", "bbox": "bbox" } }

© Copyright 2020, NVIDIA. Last updated on Feb 2, 2023.