{"cells": [{"metadata": {"_uuid": "1a9645109acfce8f4f02a8defd89df021e99ff3a", "_cell_guid": "51dd6fcf-f498-40f6-a999-1a3cbbbe00bd", "collapsed": true}, "source": ["import os\n", "from glob import glob\n", "from tqdm import tqdm\n", "import pandas as pd\n", "from skimage.io import imread\n", "import cv2\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "\n", "plt.style.use('ggplot') "], "cell_type": "code", "outputs": [], "execution_count": 1}, {"metadata": {"_uuid": "48c481627d8f7be4b69a0e4d74d1d24bbc96bc48", "_cell_guid": "6b868a54-0411-4b59-9b38-9dbc3e2fbe43"}, "source": ["img_paths = glob(os.path.join('../input/train', '*.jpg'))\n", "gt_dir = '../input/train_masks'\n", "\n", "y = []\n", "for i in tqdm(range(len(img_paths[:1000]))):  \n", "    img_path = img_paths[i]    \n", "    gt = imread(os.path.join(gt_dir, os.path.splitext(os.path.basename(img_path))[0]+'_mask.gif'))\n", "    y.append(gt)\n", "    \n", "y = np.array(y)"], "cell_type": "code", "outputs": [], "execution_count": 2}, {"metadata": {"_uuid": "fee9c32355f2823bf06858b182f2511ab0e70089", "_cell_guid": "53867e15-a7df-426d-b3b7-efc7e87c73c9", "scrolled": true}, "source": ["scales = np.array(range(1, 20)) * 0.05\n", "mean_dices = []\n", "\n", "for scale in scales:\n", "    \n", "    dices = []\n", "    for i in tqdm(range(len(y))):\n", "        \n", "        mask = y[i]\n", "        seg = cv2.resize(mask, dsize=None, fx=scale, fy=scale)\n", "        seg = cv2.resize(seg, (1918, 1280))\n", "        \n", "        mask = mask > 127\n", "        seg = seg > 127\n", "        \n", "        dice = 2.0 * np.sum(seg&mask) / (np.sum(seg) + np.sum(mask))\n", "        dices.append(dice)\n", "    \n", "    dices = np.array(dices)\n", "    mean_dices.append(np.mean(dices))\n", "\n", "mean_dices = np.array(mean_dices)\n", "        "], "cell_type": "code", "outputs": [], "execution_count": 5}, {"metadata": {"_uuid": "5b2d6bb0b5f92e3e2af697cb8527a28c075607bc", "_cell_guid": "d6dbb9f0-6b21-4521-8039-34ce1c3c893e"}, "source": ["plt.figure(figsize=(15, 7))\n", "plt.plot(scales, mean_dices)\n", "plt.xlabel('scale')\n", "plt.ylabel('dice')\n", "for i in range(1, len(scales), 2):\n", "    plt.text(scales[i], mean_dices[i], '%.5f'%mean_dices[i])\n", "plt.show()"], "cell_type": "code", "outputs": [], "execution_count": 10}, {"metadata": {"_uuid": "848c9aaffa74d038ec8ad27e8c1d88a31fc36524", "_cell_guid": "9ab04488-6b5a-41dd-a9cf-fab089e01c94", "collapsed": true}, "source": [], "cell_type": "code", "outputs": [], "execution_count": null}], "metadata": {"kernelspec": {"language": "python", "display_name": "Python 3", "name": "python3"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "name": "python", "version": "3.6.1", "file_extension": ".py", "codemirror_mode": {"version": 3, "name": "ipython"}}}, "nbformat": 4, "nbformat_minor": 1}