{"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_minor":4,"nbformat":4,"cells":[{"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\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","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# sample = pd.read_csv('../input/hpa-single-cell-image-classification/sample_submission.csv')\n# sample\n# sample.to_csv('submission.csv', index=False)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"total = pd.read_csv('../input/hpa-single-cell-image-classification/sample_submission.csv')\ntotal\nsample = pd.read_csv('../input/123456/submission.csv')\nsample","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ID = np.array(total['ID'])\nImageWidth = np.array(total['ImageWidth'])\nImageHeight = np.array(total['ImageHeight'])\nPredictionString = np.array(total['PredictionString'])","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"idx = np.array(sample['ID'])\npredstr = np.array(sample['PredictionString'])","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(ID.shape[0]):\n    if ID[i] in idx:\n        for j in range(idx.shape[0]):\n            if ID[i] == idx[j]:\n                PredictionString[i] = predstr[j]\n                break","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df = pd.DataFrame({'ID':ID,'ImageWidth':ImageWidth,'ImageHeight':ImageHeight,'PredictionString':PredictionString})\nsubmission_df.to_csv(\"submission.csv\",index=False)\nsubmission_df","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"PredictionString[0]","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# b = 0\n# ID = []\n# ImageWidth = [] # get from sample submission\n# ImageHeight = [] # get from sample submission\n# PredictionString = []\n# # ID.append('aaa')\n# # ID = []\n# predStr = \"\"\n# while(b < 2210):\n#     image_loc_batches, id_loc_batches, encoded_mask_loc_batches, b = test_image_batches(bottom = b, n_batch_limit=500, dsize=(256,256))\n#     print(image_loc_batches.shape)\n# #     print(id_loc_batches)\n#     print(id_loc_batches.shape)\n# #     print(encoded_mask_loc_batches)\n    \n#     image_loc_batches = torch.FloatTensor(image_loc_batches).permute(0, 3, 1, 2)\n#     pred = model(image_loc_batches)\n# #     print(pred.shape)\n    \n#     probability = torch.nn.functional.softmax(pred, dim=1)\n#     max_value,index = torch.max(probability,1)\n#     print(probability.shape)\n#     print(max_value)\n#     print(index)\n    \n#     max_value = max_value.detach().numpy()\n#     index = index.detach().numpy()\n    \n#     for i in range(id_loc_batches.shape[0]):\n#         if i == 0:\n#             ID = np.append(ID, id_loc_batches[i])\n#             predStr = str(index[i]) + ' ' + str(max_value[i]) + ' ' + encoded_mask_loc_batches[i]\n#         elif id_loc_batches[i] != id_loc_batches[i-1]:\n#             PredictionString = np.append(PredictionString, predStr)\n#             ID = np.append(ID, id_loc_batches[i])\n#             predStr = str(index[i]) + ' ' + str(max_value[i]) + ' ' + encoded_mask_loc_batches[i]        \n#         elif id_loc_batches[i] == id_loc_batches[i-1]:\n#             predStr += ' ' + str(index[i]) + ' ' + str(max_value[i]) + ' ' + encoded_mask_loc_batches[i]       \n#     PredictionString = np.append(PredictionString, predStr)\n    \n#     print(ID)\n#     print(ID.shape)\n# #     print(PredictionString)\n#     print(PredictionStirng.shape)","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}