{"cells":[{"metadata":{},"cell_type":"markdown","source":"This notebook does simple EDA for the dataset to see the distribution of original sizes. It is common to downscale all images for initial training to save processor power. However, as we can see with this notebook there is some distinct groups of original sizes - some very large - and hence a considerable amount of data may be lost."},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\n#for dirname, _, filenames in os.walk('/kaggle/input'):\n #   for filename in filenames:\n  #      print(os.path.join(dirname, filename))\n\n# You can write up to 5GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"import cv2\nimport os\n\nimage_meta_path = \"/kaggle/input/siim-isic-melanoma-classification/train.csv\"\nimage_path = \"/kaggle/input/siim-isic-melanoma-classification/jpeg/train/\"\nimage_meta = pd.read_csv(image_meta_path)\nimage_meta[\"height\"] = 0\nimage_meta[\"width\"] = 0","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"from torch.utils.data import DataLoader, Dataset #Create an efficient dataloader set to feed images to the model\n\nclass TrainData(Dataset):\n\n    def __init__(self, dataframe, image_dir, transforms = None):\n        super().__init__()\n        self.df = dataframe\n        self.image_ids = dataframe['image_name'].unique()\n        self.image_dir = image_dir\n\n\n    def __getitem__(self, idx: int):\n        image_id = self.image_ids[idx]\n        image = cv2.imread(f'{self.image_dir}/{image_id}.jpg', cv2.IMREAD_COLOR)\n        #image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB).astype(np.float32)\n        height = image.shape[0]\n        width = image.shape[1]\n        \n        return image_id, height, width\n    \n    def __len__(self) -> int:\n        return self.image_ids.shape[0]\n\ntrain_dataset = TrainData(image_meta, image_path)\n\ndef sizefinder(image):\n    image_id = image[0]\n    height = image[1]\n    width = image[2]\n    image_meta.loc[image_meta['image_name'] == image_id, ['height']] = height\n    image_meta.loc[image_meta['image_name'] == image_id, ['width']] = width\n    \n    \nsizefinder = [sizefinder(image) for image in train_dataset]\nimage_meta.to_csv(\"ImageSizes.csv\", index= False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"image_meta","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import matplotlib.pyplot as plt\n\npd.DataFrame.hist(image_meta, column = \"image_name\", by = \"height\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import seaborn as sns\nimage_meta = pd.read_csv(\"/kaggle/input/imagesizes/image_meta.csv\")\nheight = sns.kdeplot(image_meta[\"height\"])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"width = sns.kdeplot(image_meta[\"width\"])","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":4}