{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# COTS Augmentation Gallery using the Albumentations Library\n\n* This notebook is a set of quick examples of augmentation techniques using the Albumentations Library\n\n* It also briefly shows (at the end) how to move your bounding boxes with albumentations\n\nFor the full set of augmentations and their documentation, visit: https://albumentations.ai/docs/getting_started/transforms_and_targets/","metadata":{}},{"cell_type":"markdown","source":"## Utility Functions","metadata":{}},{"cell_type":"code","source":"import albumentations as A\n\nimport warnings\nwarnings.filterwarnings(\"ignore\")\n\nimport os\nimport torch\nimport importlib\nimport cv2 \nimport pandas as pd\nimport numpy as np\n\nimport ast\nimport shutil\nimport sys\n\nfrom tqdm.notebook import tqdm\ntqdm.pandas()\n\nfrom PIL import Image\nfrom IPython.display import display","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-01-21T07:16:05.217815Z","iopub.execute_input":"2022-01-21T07:16:05.218730Z","iopub.status.idle":"2022-01-21T07:16:09.283512Z","shell.execute_reply.started":"2022-01-21T07:16:05.218588Z","shell.execute_reply":"2022-01-21T07:16:09.282362Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Modified from https://www.kaggle.com/remekkinas/yolox-inference-on-kaggle-for-cots-lb-0-507\n# Additions: \n#     allows customized box color (BGR)\n\ndef draw_yolox_predictions(img, bboxes, scores, bbclasses, classes_dict, boxcolor = (0,0,255)):\n    outimg = img.copy()\n    for i in range(len(bboxes)):\n        box = bboxes[i]\n        cls_id = int(bbclasses[i])\n        score = scores[i]\n        x0 = int(box[0])\n        y0 = int(box[1])\n        x1 = x0 + int(box[2])\n        y1 = y0 + int(box[3])\n\n        cv2.rectangle(outimg, (x0, y0), (x1, y1), boxcolor, 2)\n        cv2.putText(outimg, '{}:{:.1f}%'.format(classes_dict[cls_id], score * 100), (x0, y0 - 3), cv2.FONT_HERSHEY_PLAIN, 0.8, boxcolor, thickness = 1)\n    return outimg","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-01-21T07:16:11.921163Z","iopub.execute_input":"2022-01-21T07:16:11.921503Z","iopub.status.idle":"2022-01-21T07:16:11.931321Z","shell.execute_reply.started":"2022-01-21T07:16:11.921469Z","shell.execute_reply":"2022-01-21T07:16:11.930303Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Pick Your Example Image Here","metadata":{}},{"cell_type":"code","source":"%cd /kaggle/working\n\nfrom sklearn.model_selection import GroupKFold\n\ndef get_bbox(annots):\n    bboxes = [list(annot.values()) for annot in annots]\n    return bboxes\n\ndef get_path(row):\n    row['image_path'] = f'{ROOT_DIR}/train_images/video_{row.video_id}/{row.video_frame}.jpg'\n    return row\n\nROOT_DIR  = '/kaggle/input/tensorflow-great-barrier-reef/'\n\ndf = pd.read_csv(\"/kaggle/input/tensorflow-great-barrier-reef/train.csv\")\n\n# Don't filter for annotated frames. Include frames with no bboxes as well!\ndf[\"num_bbox\"] = df['annotations'].apply(lambda x: str.count(x, 'x'))\ndf_train = df\n\n# Annotations \ndf_train['annotations'] = df_train['annotations'].progress_apply(lambda x: ast.literal_eval(x))\ndf_train['bboxes'] = df_train.annotations.progress_apply(get_bbox)\n\ndf_train = df_train.progress_apply(get_path, axis=1)\n\nkf = GroupKFold(n_splits = 5) \ndf_train = df_train.reset_index(drop=True)\ndf_train['fold'] = -1\nfor fold, (train_idx, val_idx) in enumerate(kf.split(df_train, y = df_train.video_id.tolist(), groups=df_train.sequence)):\n    df_train.loc[val_idx, 'fold'] = fold\n\ndf_test = df_train[df_train.fold == 4]","metadata":{"_kg_hide-output":false,"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-01-21T07:16:13.139656Z","iopub.execute_input":"2022-01-21T07:16:13.140215Z","iopub.status.idle":"2022-01-21T07:16:31.868951Z","shell.execute_reply.started":"2022-01-21T07:16:13.140176Z","shell.execute_reply":"2022-01-21T07:16:31.868064Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_paths = df_test.image_path.tolist()\ngt = df_test.bboxes.tolist()","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-01-21T07:16:31.870881Z","iopub.execute_input":"2022-01-21T07:16:31.871217Z","iopub.status.idle":"2022-01-21T07:16:31.878021Z","shell.execute_reply.started":"2022-01-21T07:16:31.871172Z","shell.execute_reply":"2022-01-21T07:16:31.877085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"This is my favourite image. Because all the COTS are in the top left hand corner","metadata":{}},{"cell_type":"code","source":"i = 1380\n\nimage_path = image_paths[i]\nImg = Image.open(image_path)\ndisplay(Img)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-01-21T07:16:31.879389Z","iopub.execute_input":"2022-01-21T07:16:31.880123Z","iopub.status.idle":"2022-01-21T07:16:32.418059Z","shell.execute_reply.started":"2022-01-21T07:16:31.880068Z","shell.execute_reply":"2022-01-21T07:16:32.415892Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# A cropped image for simplicity, and with boxes showing you where the COTS are","metadata":{}},{"cell_type":"code","source":"img_np = np.array(Img)[:360,:640]\nout_image = draw_yolox_predictions(img_np, gt[i], [1.0] * len(gt[i]), [0] * len(gt[i]), ['COTS'], (0,255,0))\ndisplay(Image.fromarray(out_image))","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-01-21T07:16:32.420521Z","iopub.execute_input":"2022-01-21T07:16:32.421135Z","iopub.status.idle":"2022-01-21T07:16:32.530884Z","shell.execute_reply.started":"2022-01-21T07:16:32.421094Z","shell.execute_reply":"2022-01-21T07:16:32.529939Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# The Albumentations","metadata":{}},{"cell_type":"code","source":"def show_augmentation(img, augmentation):\n    \"\"\"\n        img: a numpy array of the image\n        augmentation: a function from the Albumentations library\n        see https://albumentations.ai/docs/getting_started/transforms_and_targets/\n        \n        returns: a numpy array of the augmented image\n    \"\"\"\n    transform = A.Compose([augmentation])\n    img_aug = transform(image=img)['image']\n    return(img_aug)","metadata":{"execution":{"iopub.status.busy":"2022-01-21T07:16:32.533020Z","iopub.execute_input":"2022-01-21T07:16:32.533594Z","iopub.status.idle":"2022-01-21T07:16:32.540555Z","shell.execute_reply.started":"2022-01-21T07:16:32.533543Z","shell.execute_reply":"2022-01-21T07:16:32.539544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Blurring Augmentations","metadata":{}},{"cell_type":"markdown","source":"### Blur","metadata":{}},{"cell_type":"code","source":"AUGMENTATION = A.Blur(p = 1.0)\n\nfor q in range(1):\n    img_aug = show_augmentation(img_np, AUGMENTATION)\n    out_image = draw_yolox_predictions(img_aug, gt[i], [1.0] * len(gt[i]), [0] * len(gt[i]), ['COTS'], (0,255,0))\n    display(Image.fromarray(out_image))","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-01-21T06:34:17.470589Z","iopub.execute_input":"2022-01-21T06:34:17.470908Z","iopub.status.idle":"2022-01-21T06:34:17.613801Z","shell.execute_reply.started":"2022-01-21T06:34:17.470868Z","shell.execute_reply":"2022-01-21T06:34:17.612769Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### GaussianBlur","metadata":{}},{"cell_type":"code","source":"AUGMENTATION = A.GaussianBlur(p = 1.0)\n\nfor q in range(1):\n    img_aug = show_augmentation(img_np, AUGMENTATION)\n    out_image = draw_yolox_predictions(img_aug, gt[i], [1.0] * len(gt[i]), [0] * len(gt[i]), ['COTS'], (0,255,0))\n    display(Image.fromarray(out_image))","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-01-21T06:34:23.48995Z","iopub.execute_input":"2022-01-21T06:34:23.490528Z","iopub.status.idle":"2022-01-21T06:34:23.646Z","shell.execute_reply.started":"2022-01-21T06:34:23.490493Z","shell.execute_reply":"2022-01-21T06:34:23.645003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### MedianBlur","metadata":{}},{"cell_type":"code","source":"AUGMENTATION = A.MedianBlur(p = 1.0)\n\nfor q in range(1):\n    img_aug = show_augmentation(img_np, AUGMENTATION)\n    out_image = draw_yolox_predictions(img_aug, gt[i], [1.0] * len(gt[i]), [0] * len(gt[i]), ['COTS'], (0,255,0))\n    display(Image.fromarray(out_image))","metadata":{"execution":{"iopub.status.busy":"2022-01-21T06:34:55.535899Z","iopub.execute_input":"2022-01-21T06:34:55.536182Z","iopub.status.idle":"2022-01-21T06:34:55.739308Z","shell.execute_reply.started":"2022-01-21T06:34:55.536154Z","shell.execute_reply":"2022-01-21T06:34:55.73823Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Downscale","metadata":{}},{"cell_type":"code","source":"AUGMENTATION = A.Downscale(scale_min=0.5, scale_max=0.5, p = 1.0)\n\nfor q in range(1):\n    img_aug = show_augmentation(img_np, AUGMENTATION)\n    out_image = draw_yolox_predictions(img_aug, gt[i], [1.0] * len(gt[i]), [0] * len(gt[i]), ['COTS'], (0,255,0))\n    display(Image.fromarray(out_image))","metadata":{"execution":{"iopub.status.busy":"2022-01-21T06:34:42.90564Z","iopub.execute_input":"2022-01-21T06:34:42.905977Z","iopub.status.idle":"2022-01-21T06:34:43.00175Z","shell.execute_reply.started":"2022-01-21T06:34:42.905942Z","shell.execute_reply":"2022-01-21T06:34:43.000811Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### ImageCompression","metadata":{}},{"cell_type":"code","source":"AUGMENTATION = A.ImageCompression(quality_lower=20, quality_upper=40, p = 1.0)\n\nfor q in range(1):\n    img_aug = show_augmentation(img_np, AUGMENTATION)\n    out_image = draw_yolox_predictions(img_aug, gt[i], [1.0] * len(gt[i]), [0] * len(gt[i]), ['COTS'], (0,255,0))\n    display(Image.fromarray(out_image))","metadata":{"execution":{"iopub.status.busy":"2022-01-21T06:24:39.131368Z","iopub.execute_input":"2022-01-21T06:24:39.132034Z","iopub.status.idle":"2022-01-21T06:24:39.242632Z","shell.execute_reply.started":"2022-01-21T06:24:39.131994Z","shell.execute_reply":"2022-01-21T06:24:39.241663Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Clarity Augmentations","metadata":{}},{"cell_type":"markdown","source":"### Sharpen","metadata":{}},{"cell_type":"code","source":"AUGMENTATION = A.Sharpen(p = 1.0)\n\nfor q in range(1):\n    img_aug = show_augmentation(img_np, AUGMENTATION)\n    out_image = draw_yolox_predictions(img_aug, gt[i], [1.0] * len(gt[i]), [0] * len(gt[i]), ['COTS'], (0,255,0))\n    display(Image.fromarray(out_image))","metadata":{"execution":{"iopub.status.busy":"2022-01-21T06:36:27.446472Z","iopub.execute_input":"2022-01-21T06:36:27.446787Z","iopub.status.idle":"2022-01-21T06:36:27.531992Z","shell.execute_reply.started":"2022-01-21T06:36:27.446757Z","shell.execute_reply":"2022-01-21T06:36:27.530883Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### CLAHE","metadata":{}},{"cell_type":"code","source":"AUGMENTATION = A.CLAHE(p = 1.0)\n\nfor q in range(1):\n    img_aug = show_augmentation(img_np, AUGMENTATION)\n    out_image = draw_yolox_predictions(img_aug, gt[i], [1.0] * len(gt[i]), [0] * len(gt[i]), ['COTS'], (0,255,0))\n    display(Image.fromarray(out_image))","metadata":{"execution":{"iopub.status.busy":"2022-01-21T06:35:52.238922Z","iopub.execute_input":"2022-01-21T06:35:52.239308Z","iopub.status.idle":"2022-01-21T06:35:52.332771Z","shell.execute_reply.started":"2022-01-21T06:35:52.239272Z","shell.execute_reply":"2022-01-21T06:35:52.331741Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### IAAAdditiveGaussianNoise","metadata":{}},{"cell_type":"code","source":"AUGMENTATION = A.IAAAdditiveGaussianNoise(p = 1.0)\n\nfor q in range(1):\n    img_aug = show_augmentation(img_np, AUGMENTATION)\n    out_image = draw_yolox_predictions(img_aug, gt[i], [1.0] * len(gt[i]), [0] * len(gt[i]), ['COTS'], (0,255,0))\n    display(Image.fromarray(out_image))","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-01-21T06:35:57.203587Z","iopub.execute_input":"2022-01-21T06:35:57.204774Z","iopub.status.idle":"2022-01-21T06:35:57.292602Z","shell.execute_reply.started":"2022-01-21T06:35:57.204714Z","shell.execute_reply":"2022-01-21T06:35:57.291544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Emboss","metadata":{}},{"cell_type":"code","source":"AUGMENTATION = A.Emboss(p = 1.0)\n\nfor q in range(1):\n    img_aug = show_augmentation(img_np, AUGMENTATION)\n    out_image = draw_yolox_predictions(img_aug, gt[i], [1.0] * len(gt[i]), [0] * len(gt[i]), ['COTS'], (0,255,0))\n    display(Image.fromarray(out_image))","metadata":{"execution":{"iopub.status.busy":"2022-01-21T06:36:09.572682Z","iopub.execute_input":"2022-01-21T06:36:09.572969Z","iopub.status.idle":"2022-01-21T06:36:09.664525Z","shell.execute_reply.started":"2022-01-21T06:36:09.572941Z","shell.execute_reply":"2022-01-21T06:36:09.663471Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Color Augmentations","metadata":{}},{"cell_type":"markdown","source":"### HSV Augmentation","metadata":{}},{"cell_type":"code","source":"AUGMENTATION = A.HueSaturationValue(p = 1.0)\n\nfor q in range(1):\n    img_aug = show_augmentation(img_np, AUGMENTATION)\n    out_image = draw_yolox_predictions(img_aug, gt[i], [1.0] * len(gt[i]), [0] * len(gt[i]), ['COTS'], (0,255,0))\n    display(Image.fromarray(out_image))","metadata":{"execution":{"iopub.status.busy":"2022-01-21T06:23:40.964051Z","iopub.execute_input":"2022-01-21T06:23:40.965291Z","iopub.status.idle":"2022-01-21T06:23:41.067429Z","shell.execute_reply.started":"2022-01-21T06:23:40.965223Z","shell.execute_reply":"2022-01-21T06:23:41.066429Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### RGBShift","metadata":{}},{"cell_type":"code","source":"AUGMENTATION = A.RGBShift(p = 1.0)\n\nfor q in range(1):\n    img_aug = show_augmentation(img_np, AUGMENTATION)\n    out_image = draw_yolox_predictions(img_aug, gt[i], [1.0] * len(gt[i]), [0] * len(gt[i]), ['COTS'], (0,255,0))\n    display(Image.fromarray(out_image))","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-01-21T06:25:32.275639Z","iopub.execute_input":"2022-01-21T06:25:32.275948Z","iopub.status.idle":"2022-01-21T06:25:32.37611Z","shell.execute_reply.started":"2022-01-21T06:25:32.275918Z","shell.execute_reply":"2022-01-21T06:25:32.374924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### RandomGamma","metadata":{}},{"cell_type":"code","source":"AUGMENTATION = A.RandomGamma(p = 1.0)\n\nfor q in range(1):\n    img_aug = show_augmentation(img_np, AUGMENTATION)\n    out_image = draw_yolox_predictions(img_aug, gt[i], [1.0] * len(gt[i]), [0] * len(gt[i]), ['COTS'], (0,255,0))\n    display(Image.fromarray(out_image))","metadata":{"execution":{"iopub.status.busy":"2022-01-21T06:26:04.314772Z","iopub.execute_input":"2022-01-21T06:26:04.315232Z","iopub.status.idle":"2022-01-21T06:26:04.417965Z","shell.execute_reply.started":"2022-01-21T06:26:04.315198Z","shell.execute_reply":"2022-01-21T06:26:04.415983Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### RandomContrast","metadata":{}},{"cell_type":"code","source":"AUGMENTATION = A.RandomContrast(p = 1.0)\n\nfor q in range(1):\n    img_aug = show_augmentation(img_np, AUGMENTATION)\n    out_image = draw_yolox_predictions(img_aug, gt[i], [1.0] * len(gt[i]), [0] * len(gt[i]), ['COTS'], (0,255,0))\n    display(Image.fromarray(out_image))","metadata":{"execution":{"iopub.status.busy":"2022-01-21T06:26:08.160842Z","iopub.execute_input":"2022-01-21T06:26:08.161691Z","iopub.status.idle":"2022-01-21T06:26:08.261435Z","shell.execute_reply.started":"2022-01-21T06:26:08.161644Z","shell.execute_reply":"2022-01-21T06:26:08.260502Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### RandomBrightness","metadata":{}},{"cell_type":"code","source":"AUGMENTATION = A.RandomBrightness(p = 1.0)\n\nfor q in range(1):\n    img_aug = show_augmentation(img_np, AUGMENTATION)\n    out_image = draw_yolox_predictions(img_aug, gt[i], [1.0] * len(gt[i]), [0] * len(gt[i]), ['COTS'], (0,255,0))\n    display(Image.fromarray(out_image))","metadata":{"execution":{"iopub.status.busy":"2022-01-21T06:26:09.47264Z","iopub.execute_input":"2022-01-21T06:26:09.473392Z","iopub.status.idle":"2022-01-21T06:26:09.57216Z","shell.execute_reply.started":"2022-01-21T06:26:09.47332Z","shell.execute_reply":"2022-01-21T06:26:09.5714Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### ChannelShuffle","metadata":{}},{"cell_type":"code","source":"AUGMENTATION = A.ChannelShuffle(p = 1.0)\n\nfor q in range(1):\n    img_aug = show_augmentation(img_np, AUGMENTATION)\n    out_image = draw_yolox_predictions(img_aug, gt[i], [1.0] * len(gt[i]), [0] * len(gt[i]), ['COTS'], (0,255,0))\n    display(Image.fromarray(out_image))","metadata":{"execution":{"iopub.status.busy":"2022-01-21T06:26:13.346772Z","iopub.execute_input":"2022-01-21T06:26:13.347093Z","iopub.status.idle":"2022-01-21T06:26:13.449176Z","shell.execute_reply.started":"2022-01-21T06:26:13.347058Z","shell.execute_reply":"2022-01-21T06:26:13.448416Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Compound Augmentations","metadata":{}},{"cell_type":"markdown","source":"* Includes support for spatial augmentations (i.e. those that alter object location, therefore the need to move the bboxes)","metadata":{}},{"cell_type":"code","source":"def show_compound_augmentation(img, bboxes, labels, augmentation_list):\n    \"\"\"\n        img: a numpy array of the image\n        bboxes: COCO-format bounding boxes\n        labels: a list of labels\n        augmentation_list: a list of functions from the Albumentations library\n        see https://albumentations.ai/docs/getting_started/transforms_and_targets/\n        \n        returns: a numpy array of the augmented image\n    \"\"\"\n    transform = A.Compose(augmentation_list,\n        bbox_params=A.BboxParams(\n        format='coco',\n        label_fields=['class_labels']\n    ))\n    transformed = transform(image=img, bboxes=bboxes, class_labels = labels)\n    img_aug = transformed['image']\n    boxes = np.array([list(b) for b in transformed['bboxes']])\n    labels = np.array(transformed['class_labels'])\n    return img_aug, boxes, labels","metadata":{"execution":{"iopub.status.busy":"2022-01-21T07:16:32.541974Z","iopub.execute_input":"2022-01-21T07:16:32.542268Z","iopub.status.idle":"2022-01-21T07:16:32.556342Z","shell.execute_reply.started":"2022-01-21T07:16:32.542227Z","shell.execute_reply":"2022-01-21T07:16:32.555407Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* One can include a conga list of their favourite augmentations\n* This example also shows how to move bounding boxes when the augmentation moves the image","metadata":{}},{"cell_type":"code","source":"# Example taken from https://analyticsindiamag.com/hands-on-guide-to-albumentation/\n\nAUGMENTATION_LIST = [\n        A.RandomRotate90(),\n        A.Flip(),\n        A.Transpose(),\n        A.OneOf([\n            A.MotionBlur(p=.2),\n            A.MedianBlur(blur_limit=3, p=0.3),\n            A.Blur(blur_limit=3, p=0.1),\n        ], p=0.2),\n        A.ShiftScaleRotate(shift_limit=0.0625, scale_limit=0.2, rotate_limit=45, p=0.2),\n        A.OneOf([\n            A.CLAHE(clip_limit=2),\n            A.RandomBrightnessContrast(),            \n        ], p=0.3),\n        A.HueSaturationValue(p=0.3),\n    ]\n\nfor q in range(5):\n    img_aug, bboxes, labels = show_compound_augmentation(img_np, gt[i], [0] * len(gt[i]), AUGMENTATION_LIST)\n    out_image = draw_yolox_predictions(img_aug, bboxes, [1.0] * len(bboxes), labels, ['COTS'], (0,255,0))\n    display(Image.fromarray(out_image))","metadata":{"execution":{"iopub.status.busy":"2022-01-21T06:36:42.402292Z","iopub.execute_input":"2022-01-21T06:36:42.402634Z","iopub.status.idle":"2022-01-21T06:36:42.925381Z","shell.execute_reply.started":"2022-01-21T06:36:42.402601Z","shell.execute_reply":"2022-01-21T06:36:42.924147Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Affine Transformation with BBoxes","metadata":{}},{"cell_type":"code","source":"AUGMENTATION_LIST = [A.Affine(scale = (0.8, 1.2), translate_percent = 0.1, rotate = (-45,45), shear = (-5, 5), cval = (114,114,114), p = 1.0)]\n\nfor q in range(5):\n    img_aug, bboxes, labels = show_compound_augmentation(img_np, gt[i], [0] * len(gt[i]), AUGMENTATION_LIST)\n    out_image = draw_yolox_predictions(img_aug, bboxes, [1.0] * len(bboxes), labels, ['COTS'], (0,255,0))\n    display(Image.fromarray(out_image))","metadata":{"execution":{"iopub.status.busy":"2022-01-21T07:23:47.446678Z","iopub.execute_input":"2022-01-21T07:23:47.447030Z","iopub.status.idle":"2022-01-21T07:23:47.871773Z","shell.execute_reply.started":"2022-01-21T07:23:47.446975Z","shell.execute_reply":"2022-01-21T07:23:47.870732Z"},"trusted":true},"execution_count":null,"outputs":[]}]}