{"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 in \n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nimport os\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"!ls ../input","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2aff0ba8ada743224b33705d176103a7ad6ba342"},"cell_type":"code","source":"# Nodular extraction\ndf_nodules = pd.read_csv('../input/stage_1_train_labels.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"759c1c86874f2be83cf5dd7e17fe4a55aec4abc2"},"cell_type":"code","source":"%%time\n\nnodule_locations = {}\n\nfor i in range(len(df_nodules)):\n    filename = df_nodules.iloc[i][0]\n    location = df_nodules.iloc[i][1:5]\n    nodule = df_nodules.iloc[i][-1]\n    \n    if nodule == 1:\n        location = [int(float(loc)) for  loc in location]\n        if filename in nodule_locations.keys():\n            nodule_locations[filename].append(location)\n        else:\n            nodule_locations[filename] = [location]\n    ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ac03db3fca59aa2e53b256d55acaa19b72a87593"},"cell_type":"code","source":"import random\nfolder = '../input/stage_1_train_images'\nfilenames = os.listdir(folder)\nrandom.shuffle(filenames)\n\nn_valid_samples = 2560\ntrain_filenames = filenames[n_valid_samples:]\nvalid_filenames = filenames[:n_valid_samples]\n\nprint(\"Train Samples :\", len(train_filenames))\nprint(\"Validation Samples :\", len(valid_filenames))\nn_train_samples = len(filenames) - n_valid_samples","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a2cbcf1b59933d5d57e61d72b156da6d91de9845"},"cell_type":"code","source":"node_samples = [len(i) for i in nodule_locations.values()]\nsns.countplot(node_samples)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a6d5d4a91b06a4cb403d6716c124fa67ffadeccf"},"cell_type":"code","source":"heatmap = np.zeros((1024, 1024))\nws = []\nhs = []\nfor vals in nodule_locations.values():\n    for val in vals:\n        x, y, w, h = val\n        heatmap[y: y+h, x: x+w] += 1\n        ws.append(w)\n        hs.append(h)\nplt.figure(figsize = (10, 10))\nplt.title('Nodule location heatmap')\nplt.imshow(heatmap, cmap = 'Greys_r')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"26e4c263782978eeaa93cee11190a51c0b369757"},"cell_type":"code","source":"plt.hist(hs, bins = np.linspace(1, 1000, 50))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5bcaae7f8402f7cdf180533d845fd8b09fd2dcdc"},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}