{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport cv2\nimport albumentations\nfrom albumentations import torch as AT\nimport os\nprint(os.listdir(\"../input\"))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"from albumentations import (\n    HorizontalFlip, IAAPerspective, ShiftScaleRotate, CLAHE, RandomRotate90,\n    Transpose, ShiftScaleRotate, Blur, OpticalDistortion, GridDistortion, HueSaturationValue,\n    IAAAdditiveGaussianNoise, GaussNoise, MotionBlur, MedianBlur, RandomBrightnessContrast, IAAPiecewiseAffine,\n    IAASharpen, IAAEmboss, Flip, OneOf, Compose\n)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"base_dr = \"../input/\"\n# Reading the CSVs\ntrain = pd.read_csv(base_dr+'train.csv')\ntest = pd.read_csv(base_dr+'test.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def strong_aug(p=.5):\n    # source - https://github.com/albu/albumentations/blob/master/notebooks/example.ipynb\n    return Compose([\n        RandomRotate90(),\n        Flip(),\n        Transpose(),\n        OneOf([\n            IAAAdditiveGaussianNoise(),\n            GaussNoise(),\n        ], p=0.2),\n        OneOf([\n            MotionBlur(p=.2),\n            MedianBlur(blur_limit=3, p=0.1),\n            Blur(blur_limit=3, p=0.1),\n        ], p=0.2),\n        ShiftScaleRotate(shift_limit=0.0625, scale_limit=0.2, rotate_limit=45, p=0.2),\n        OneOf([\n            OpticalDistortion(p=0.3),\n            GridDistortion(p=.1),\n            IAAPiecewiseAffine(p=0.3),\n        ], p=0.2),\n        OneOf([\n            CLAHE(clip_limit=2),\n            IAASharpen(),\n            IAAEmboss(),\n            RandomBrightnessContrast(),            \n        ], p=0.3),\n        HueSaturationValue(p=0.3),\n    ], p=p)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"x = [] ; y = [] ; names = []\nfor id in (train.id_code.values):\n    full_size_image = cv2.imread('../input/train_images/{}.png'.format(id))\n    imgFile = cv2.resize(full_size_image, (224,224) , interpolation=cv2.INTER_CUBIC)\n    aug = HorizontalFlip(always_apply=True) # horization flip\n    image = aug(image=imgFile)['image']\n    names.append('{}_HP'.format(id))\n    x.append(image)\n    y.append(train[train['id_code'] == id].diagnosis.values[0])\n    aug = ShiftScaleRotate(always_apply=True) # Random Shift Scale & Rotate\n    image = aug(image=imgFile)['image']\n    names.append('{}_SSR'.format(id))\n    x.append(image)\n    y.append(train[train['id_code'] == id].diagnosis.values[0])\n    aug = strong_aug(p=1) # Strong Random augenmation from above function\n    image = aug(image=imgFile)['image']\n    names.append('{}_StrAug'.format(id))\n    x.append(image)\n    y.append(train[train['id_code'] == id].diagnosis.values[0])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"##??ShiftScaleRotate","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Set it up as a dataframe if you like\ndf = pd.DataFrame() ; df[\"labels\"]=y ; df[\"images\"]=x ; df['names'] = names","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#Looking at shapes and first image\ndf.shape , df.images[0].shape , df.labels[0]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Looking at augmented data\ndf.head()","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"from random import sample\nimport cv2\nfull_size_image = cv2.imread('../input/train_images/000c1434d8d7.png')\nimgFile = cv2.resize(full_size_image, (224,224) , interpolation=cv2.INTER_CUBIC)\nplt.imshow(full_size_image)\nimgFile.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(df[df['names'].str.contains(\"000c1434d8d7\")]['names'][0])\nplt.imshow(df[df['names'].str.contains(\"000c1434d8d7\")]['images'][0]);","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(df[df['names'].str.contains(\"000c1434d8d7\")]['names'][1])\nplt.imshow(df[df['names'].str.contains(\"000c1434d8d7\")]['images'][1]);\n\n## this is not working , SSR - need to work more","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(df[df['names'].str.contains(\"000c1434d8d7\")]['names'][2])\nplt.imshow(df[df['names'].str.contains(\"000c1434d8d7\")]['images'][2]);","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Work in progress","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.4","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}