{"cells":[{"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 pandas as pd\nimport numpy as np\nimport tifffile as tiff\nimport os\nimport sys\n\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\nfor 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 20GB 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":{"trusted":true},"cell_type":"code","source":"DIR_INPUT = '../input/hubmap-kidney-segmentation'\nall_shapes = [(31262, 14844), (40429, 31295), (49780, 26840), (43780, 36800),\n              (42360, 38160), (22165, 29433), (47723, 23990), (44066, 31299),\n              (53240, 37040), (29020, 46660), (50680, 39960), (43160, 33240)]\nall_shapes = sorted(all_shapes, key=lambda x: x[0])\npublic_test_names = ('b9a3865fc', 'b2dc8411c', '26dc41664', 'c68fe75ea', 'afa5e8098')\n\nsub_df = pd.read_csv('{}/sample_submission.csv'.format(DIR_INPUT))\n\ntest_set_path = os.path.join(DIR_INPUT, 'test')\nimage_ids = list(set([os.path.splitext(name)[0]\n                     for name in os.listdir(test_set_path)\n                     if name.endswith('.tiff')]))\nif sub_df.shape[0] > 5:\n    online_shapes = []\n    for i, row in sub_df.iterrows():\n        image = tiff.imread('{}/test/{}.tiff'.format(DIR_INPUT, row['id']))\n        image = np.squeeze(image)\n        if image.shape[0] == 3:\n            image = image.transpose([1, 2, 0])\n            image = np.ascontiguousarray(image)\n        h, w, _ = image.shape\n        online_shapes.append((w, h))\n\n    online_shapes = sorted(online_shapes, key=lambda x: x[0])\n    is_shape_equal = [False for _ in range(len(online_shapes))]\n    for i in range(len(online_shapes)):\n        if all_shapes[0] == online_shapes[0] and all_shapes[1] == online_shapes[1]:\n            is_shape_equal[i] = True\n    # whether all online shapes are the same with given shapes\n    if all(is_shape_equal):\n        sub_df.to_csv('submission.csv', index=False)\n    else:\n        sys.exit()\nelse:\n    # This is for committing only.\n    sub_df.to_csv('submission.csv', index=False)\n","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}