{"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":"from fastai.vision.all import *","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-10-26T11:32:45.440619Z","iopub.execute_input":"2023-10-26T11:32:45.441024Z","iopub.status.idle":"2023-10-26T11:32:52.534715Z","shell.execute_reply.started":"2023-10-26T11:32:45.440992Z","shell.execute_reply":"2023-10-26T11:32:52.533538Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path = Path('/kaggle/input/UBC-OCEAN')\npath.ls()","metadata":{"execution":{"iopub.status.busy":"2023-10-26T11:32:52.53724Z","iopub.execute_input":"2023-10-26T11:32:52.539Z","iopub.status.idle":"2023-10-26T11:32:52.548719Z","shell.execute_reply.started":"2023-10-26T11:32:52.538947Z","shell.execute_reply":"2023-10-26T11:32:52.54752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv(path/'train.csv')\nencode = {lbl: idx for idx, lbl in enumerate(train_df.label.unique())}\ndecode = {lbl: idx for idx, lbl in encode.items()}","metadata":{"execution":{"iopub.status.busy":"2023-10-26T11:32:52.550458Z","iopub.execute_input":"2023-10-26T11:32:52.550838Z","iopub.status.idle":"2023-10-26T11:32:52.58348Z","shell.execute_reply.started":"2023-10-26T11:32:52.550797Z","shell.execute_reply":"2023-10-26T11:32:52.582196Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_df = pd.read_csv(path/'sample_submission.csv')\nsample_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-10-26T11:32:52.585864Z","iopub.execute_input":"2023-10-26T11:32:52.586211Z","iopub.status.idle":"2023-10-26T11:32:52.606156Z","shell.execute_reply.started":"2023-10-26T11:32:52.586181Z","shell.execute_reply":"2023-10-26T11:32:52.605044Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_copy = sample_df.copy()","metadata":{"execution":{"iopub.status.busy":"2023-10-26T11:32:52.607539Z","iopub.execute_input":"2023-10-26T11:32:52.608295Z","iopub.status.idle":"2023-10-26T11:32:52.613314Z","shell.execute_reply.started":"2023-10-26T11:32:52.608263Z","shell.execute_reply":"2023-10-26T11:32:52.612327Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_file_path(image_id):\n    if os.path.exists(f\"{path}/test_thumbnails/{image_id}_thumbnail.png\"):\n        return f\"{path}/test_thumbnails/{image_id}_thumbnail.png\"\n    else:\n        return f\"{path}/test_images/{image_id}.png\"","metadata":{"execution":{"iopub.status.busy":"2023-10-26T11:32:54.459601Z","iopub.execute_input":"2023-10-26T11:32:54.460631Z","iopub.status.idle":"2023-10-26T11:32:54.466304Z","shell.execute_reply.started":"2023-10-26T11:32:54.460595Z","shell.execute_reply":"2023-10-26T11:32:54.464979Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_copy['image_id'] = sample_df['image_id'].apply(get_file_path)","metadata":{"execution":{"iopub.status.busy":"2023-10-26T11:32:55.225065Z","iopub.execute_input":"2023-10-26T11:32:55.225443Z","iopub.status.idle":"2023-10-26T11:32:55.232772Z","shell.execute_reply.started":"2023-10-26T11:32:55.225416Z","shell.execute_reply":"2023-10-26T11:32:55.23125Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"learn = load_learner('/kaggle/input/fastai-ubc-ovarian-cancer-subtype/export.pkl')","metadata":{"execution":{"iopub.status.busy":"2023-10-26T11:32:56.692122Z","iopub.execute_input":"2023-10-26T11:32:56.692546Z","iopub.status.idle":"2023-10-26T11:32:57.236041Z","shell.execute_reply.started":"2023-10-26T11:32:56.692514Z","shell.execute_reply":"2023-10-26T11:32:57.234842Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_dl = learn.dls.test_dl(sample_copy)","metadata":{"execution":{"iopub.status.busy":"2023-10-26T11:32:58.412607Z","iopub.execute_input":"2023-10-26T11:32:58.413854Z","iopub.status.idle":"2023-10-26T11:32:58.421894Z","shell.execute_reply.started":"2023-10-26T11:32:58.413805Z","shell.execute_reply":"2023-10-26T11:32:58.420541Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds, _ = learn.tta(dl=test_dl)","metadata":{"execution":{"iopub.status.busy":"2023-10-26T11:33:03.92608Z","iopub.execute_input":"2023-10-26T11:33:03.927212Z","iopub.status.idle":"2023-10-26T11:33:06.566271Z","shell.execute_reply.started":"2023-10-26T11:33:03.927175Z","shell.execute_reply":"2023-10-26T11:33:06.564846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_df['label'] = preds.argmax(dim=-1).numpy()\nsample_df['label'] = sample_df['label'].map(decode)","metadata":{"execution":{"iopub.status.busy":"2023-10-26T11:33:06.56937Z","iopub.execute_input":"2023-10-26T11:33:06.569914Z","iopub.status.idle":"2023-10-26T11:33:06.585452Z","shell.execute_reply.started":"2023-10-26T11:33:06.569862Z","shell.execute_reply":"2023-10-26T11:33:06.584258Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_df.to_csv('submission.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2023-10-26T11:33:07.01664Z","iopub.execute_input":"2023-10-26T11:33:07.017797Z","iopub.status.idle":"2023-10-26T11:33:07.02806Z","shell.execute_reply.started":"2023-10-26T11:33:07.017747Z","shell.execute_reply":"2023-10-26T11:33:07.027055Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-10-26T11:33:07.467179Z","iopub.execute_input":"2023-10-26T11:33:07.467623Z","iopub.status.idle":"2023-10-26T11:33:07.479331Z","shell.execute_reply.started":"2023-10-26T11:33:07.467589Z","shell.execute_reply":"2023-10-26T11:33:07.477912Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}