{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"from fastai import *\nfrom fastai.vision import *\nimport seaborn as sns\nfrom PIL import Image\nfrom matplotlib import pyplot as plt","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"path = Path('../input/aptos2019-blindness-detection/')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"path.ls()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df = pd.read_csv(path/'train.csv')\ndf.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_test = pd.read_csv(path/'test.csv')\ndf_test.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(len(df))\nprint(len(df_test))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(df.isna().sum()) \nprint('-' * 20)\nprint(df_test.isna().sum())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df.diagnosis.value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# plot the value counts as histogram\nb = sns.countplot(df['diagnosis'])\nb.axes.set_title('Distribution of diagnosis', fontsize = 30)\nb.set_xlabel('Diagnosis', fontsize = 20)\nb.set_ylabel('Count', fontsize = 20)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"im = Image.open(\"../input/aptos2019-blindness-detection/train_images/08b6e3240858.png\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(im.format, im.size, im.mode)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"im = Image.open(\"../input/aptos2019-blindness-detection/train_images/0ca0aee4d57e.png\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(im.format, im.size, im.mode)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# plot the various sizes of images\ndef get_image_sizes(folder):\n    image_list = (path/folder).ls()\n    heights = []\n    widths = []\n    ids = []\n\n    for image in image_list:\n        im = Image.open(image)\n        height, width = im.size\n        heights.append(height)\n        widths.append(width)\n        ids.append(str(image)[-16:-4])\n        \n    return pd.DataFrame({'id_code': ids,\n                         'height': heights,\n                         'width': widths})","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"size_df = get_image_sizes('train_images')\nsize_df.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"size_df_test = get_image_sizes('test_images')\nsize_df_test.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.hist(size_df['height'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.hist(size_df_test['height'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.hist(size_df['width'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.hist(size_df_test['width'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# plot the images from 0 and 4 to see the difference\ndf_0 = df[df['diagnosis'] == 0]\ndf_0.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_4 = df[df['diagnosis'] == 4]\ndf_4.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"data = (ImageList.from_df(df_0,path,folder='train_images',suffix='.png')\n        .split_by_rand_pct(0.1, seed=42)\n        .label_from_df()\n        .transform(get_transforms(),size=128)\n        .databunch()).normalize(imagenet_stats)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# add figsize argument\ndata.show_batch(rows=3)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"data = (ImageList.from_df(df_4,path,folder='train_images',suffix='.png')\n        .split_by_rand_pct(0.1, seed=42)\n        .label_from_df()\n        .transform(get_transforms(),size=128)\n        .databunch()).normalize(imagenet_stats)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"data.show_batch(rows=3)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Without augmentation"},{"metadata":{"trusted":true},"cell_type":"code","source":"data = (ImageList.from_df(df_4,path,folder='train_images',suffix='.png')\n        .split_by_rand_pct(0.1, seed=42)\n        .label_from_df()\n        .transform([],size=128)\n        .databunch()).normalize(imagenet_stats)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"data.show_batch(rows=3, )","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# in the next notebook work with various augmentations","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}