{"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":"markdown","source":"# [SIIM-FISABIO-RSNA COVID-19 Detection](https://www.kaggle.com/c/siim-covid19-detection)\n> Identify and localize COVID-19 abnormalities on chest radiographs\n\n![](https://storage.googleapis.com/kaggle-competitions/kaggle/26680/logos/header.png)","metadata":{}},{"cell_type":"markdown","source":"# Overview:\n* Basic idea was to use **classification** model for **Study-Level** & **detection** model for **Image-Level**,\n\n# Notebooks:\n\n#### Study-Level:\n* **train**: [SIIM-COVID-19: EffNetB6 Study-Level [train] TPU🩺](https://www.kaggle.com/awsaf49/siim-covid-19-effnetb6-study-level-train-tpu/)\n* **infer**: [SIIM-COVID-19: EffNetB6 Study-Level [infer]🩺](https://www.kaggle.com/awsaf49/siim-covid-19-effnetb6-study-level-infer) [LB: **0.338**]\n* **data**: [SIIM-COVID-19: 512x512 tfrec Data](https://www.kaggle.com/awsaf49/siim-covid-19-512x512-tfrec-data)\n\n#### Image-Level:\n* **train**: [SIIM-COVID-19: YOLOv5 Image-Level [train]](https://www.kaggle.com/awsaf49/siim-covid-19-yolov5-image-level-train)\n* **infer**: [SIIM-COVID-19: YOLOv5 Image-Level [infer]](https://www.kaggle.com/awsaf49/siim-covid-19-yolov5-image-level-infer) **placeholder**, seems someting is wrong with `image-level` data, gives very small score `0.051`.\n\n# Dataset:\n\n#### JPEG\n* [1024x1024](https://www.kaggle.com/awsaf49/siimcovid19-1024-jpg-image-dataset)\n* [512x512](https://www.kaggle.com/awsaf49/siimcovid19-512-jpg-image-dataset)\n* [256x256](https://www.kaggle.com/awsaf49/siimcovid19-256-jpg-image-dataset)\n\n#### TFRECORD\n* [1024x1024](https://www.kaggle.com/awsaf49/siimcovid19-1024x1024-tfrec-dataset)\n* [512x512](https://www.kaggle.com/awsaf49/siimcovid19-512x512-tfrec-dataset)\n* [256x256](https://www.kaggle.com/awsaf49/siimcovid19-256x256-tfrec-dataset)","metadata":{}},{"cell_type":"code","source":"!pip install -q --upgrade seaborn","metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"papermill":{"duration":9.633907,"end_time":"2021-01-01T09:44:53.448657","exception":false,"start_time":"2021-01-01T09:44:43.81475","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-06-07T05:10:24.915886Z","iopub.execute_input":"2021-06-07T05:10:24.916295Z","iopub.status.idle":"2021-06-07T05:10:31.956616Z","shell.execute_reply.started":"2021-06-07T05:10:24.916193Z","shell.execute_reply":"2021-06-07T05:10:31.955702Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np, pandas as pd\nfrom glob import glob\nimport shutil, os\nimport matplotlib.pyplot as plt\nfrom sklearn.model_selection import GroupKFold\nfrom tqdm.notebook import tqdm\nimport seaborn as sns","metadata":{"papermill":{"duration":0.926929,"end_time":"2021-01-01T09:44:54.403588","exception":false,"start_time":"2021-01-01T09:44:53.476659","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-06-07T05:10:33.216458Z","iopub.execute_input":"2021-06-07T05:10:33.216787Z","iopub.status.idle":"2021-06-07T05:10:34.139209Z","shell.execute_reply.started":"2021-06-07T05:10:33.216758Z","shell.execute_reply":"2021-06-07T05:10:34.138482Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dim = 512 #512, 256, 'original'\nepochs = 25\nbatch_size = 16\nfold = 0","metadata":{"execution":{"iopub.status.busy":"2021-06-07T05:10:35.26116Z","iopub.execute_input":"2021-06-07T05:10:35.261501Z","iopub.status.idle":"2021-06-07T05:10:35.267473Z","shell.execute_reply.started":"2021-06-07T05:10:35.261468Z","shell.execute_reply":"2021-06-07T05:10:35.266475Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv(f'../input/siim-covid19-yolov5-2class-labels/meta.csv')\ntrain_df['image_path'] = '../input/siimcovid19-512-jpg-image-dataset/train/'+train_df.image_id+'.jpg'\ntrain_df.head()","metadata":{"papermill":{"duration":0.262045,"end_time":"2021-01-01T09:44:54.691965","exception":false,"start_time":"2021-01-01T09:44:54.42992","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-06-07T05:10:36.22935Z","iopub.execute_input":"2021-06-07T05:10:36.229677Z","iopub.status.idle":"2021-06-07T05:10:36.369708Z","shell.execute_reply.started":"2021-06-07T05:10:36.229651Z","shell.execute_reply":"2021-06-07T05:10:36.369001Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Split","metadata":{"papermill":{"duration":0.052492,"end_time":"2021-01-01T09:47:56.110766","exception":false,"start_time":"2021-01-01T09:47:56.058274","status":"completed"},"tags":[]}},{"cell_type":"code","source":"gkf  = GroupKFold(n_splits = 5)\ntrain_df['fold'] = -1\nfor fold, (train_idx, val_idx) in enumerate(gkf.split(train_df, groups = train_df.StudyInstanceUID.tolist())):\n    train_df.loc[val_idx, 'fold'] = fold\ntrain_df.head()","metadata":{"papermill":{"duration":0.134603,"end_time":"2021-01-01T09:47:56.297774","exception":false,"start_time":"2021-01-01T09:47:56.163171","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-06-07T05:10:50.307483Z","iopub.execute_input":"2021-06-07T05:10:50.307813Z","iopub.status.idle":"2021-06-07T05:10:50.362872Z","shell.execute_reply.started":"2021-06-07T05:10:50.307784Z","shell.execute_reply":"2021-06-07T05:10:50.36182Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_files = []\nval_files   = []\nval_files += list(train_df[train_df.fold==fold].image_path.unique())\ntrain_files += list(train_df[train_df.fold!=fold].image_path.unique())\nlen(train_files), len(val_files)","metadata":{"papermill":{"duration":0.086817,"end_time":"2021-01-01T09:47:56.443789","exception":false,"start_time":"2021-01-01T09:47:56.356972","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-06-07T05:10:51.177554Z","iopub.execute_input":"2021-06-07T05:10:51.177874Z","iopub.status.idle":"2021-06-07T05:10:51.192519Z","shell.execute_reply.started":"2021-06-07T05:10:51.177843Z","shell.execute_reply":"2021-06-07T05:10:51.19137Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Copying Files","metadata":{"papermill":{"duration":0.083752,"end_time":"2021-01-01T09:47:56.584924","exception":false,"start_time":"2021-01-01T09:47:56.501172","status":"completed"},"tags":[]}},{"cell_type":"code","source":"os.makedirs('/kaggle/working/siim-covid-19/labels/train', exist_ok = True)\nos.makedirs('/kaggle/working/siim-covid-19/labels/val', exist_ok = True)\nos.makedirs('/kaggle/working/siim-covid-19/images/train', exist_ok = True)\nos.makedirs('/kaggle/working/siim-covid-19/images/val', exist_ok = True)\nlabel_dir = '/kaggle//input/siim-covid19-yolov5-2class-labels/labels/'\nfor file in tqdm(train_files):\n    shutil.copy(file, '/kaggle/working/siim-covid-19/images/train')\n    filename = file.split('/')[-1].split('.')[0]\n    shutil.copy(os.path.join(label_dir, filename+'.txt'), '/kaggle/working/siim-covid-19/labels/train')\n    \nfor file in tqdm(val_files):\n    shutil.copy(file, '/kaggle/working/siim-covid-19/images/val')\n    filename = file.split('/')[-1].split('.')[0]\n    shutil.copy(os.path.join(label_dir, filename+'.txt'), '/kaggle/working/siim-covid-19/labels/val')","metadata":{"papermill":{"duration":124.654777,"end_time":"2021-01-01T09:50:01.331041","exception":false,"start_time":"2021-01-01T09:47:56.676264","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-06-07T05:10:52.421143Z","iopub.execute_input":"2021-06-07T05:10:52.421493Z","iopub.status.idle":"2021-06-07T05:12:14.682009Z","shell.execute_reply.started":"2021-06-07T05:10:52.421463Z","shell.execute_reply":"2021-06-07T05:12:14.681242Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Get Class Name","metadata":{"papermill":{"duration":0.068822,"end_time":"2021-01-01T09:50:01.458337","exception":false,"start_time":"2021-01-01T09:50:01.389515","status":"completed"},"tags":[]}},{"cell_type":"code","source":"class_ids  = {0:'opacity'}\nclass_names = ['opacity']","metadata":{"papermill":{"duration":0.082234,"end_time":"2021-01-01T09:50:01.601574","exception":false,"start_time":"2021-01-01T09:50:01.51934","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-06-07T05:12:14.683913Z","iopub.execute_input":"2021-06-07T05:12:14.684275Z","iopub.status.idle":"2021-06-07T05:12:14.688343Z","shell.execute_reply.started":"2021-06-07T05:12:14.684235Z","shell.execute_reply":"2021-06-07T05:12:14.687426Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# [YOLOv5](https://github.com/ultralytics/yolov5)\n![](https://user-images.githubusercontent.com/26833433/98699617-a1595a00-2377-11eb-8145-fc674eb9b1a7.jpg)\n![](https://user-images.githubusercontent.com/26833433/90187293-6773ba00-dd6e-11ea-8f90-cd94afc0427f.png)","metadata":{"papermill":{"duration":0.056257,"end_time":"2021-01-01T09:50:01.716608","exception":false,"start_time":"2021-01-01T09:50:01.660351","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"# YOLOv5 Stuff","metadata":{"papermill":{"duration":0.055699,"end_time":"2021-01-01T09:50:01.82747","exception":false,"start_time":"2021-01-01T09:50:01.771771","status":"completed"},"tags":[]}},{"cell_type":"code","source":"from os import listdir\nfrom os.path import isfile, join\nimport yaml\n\ncwd = '/kaggle/working/'\n\nwith open(join( cwd , 'train.txt'), 'w') as f:\n    for path in glob('/kaggle/working/siim-covid-19/images/train/*'):\n        f.write(path+'\\n')\n            \nwith open(join( cwd , 'val.txt'), 'w') as f:\n    for path in glob('/kaggle/working/siim-covid-19/images/val/*'):\n        f.write(path+'\\n')\n\ndata = dict(\n    train =  join( cwd , 'train.txt') ,\n    val   =  join( cwd , 'val.txt' ),\n    nc    = 1,\n    names = class_names\n    )\n\nwith open(join( cwd , 'siim-covid-19.yaml'), 'w') as outfile:\n    yaml.dump(data, outfile, default_flow_style=False)\n\nf = open(join( cwd , 'siim-covid-19.yaml'), 'r')\nprint('\\nyaml:')\nprint(f.read())","metadata":{"papermill":{"duration":0.113001,"end_time":"2021-01-01T09:50:01.996448","exception":false,"start_time":"2021-01-01T09:50:01.883447","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-06-07T05:13:15.94434Z","iopub.execute_input":"2021-06-07T05:13:15.944705Z","iopub.status.idle":"2021-06-07T05:13:15.995767Z","shell.execute_reply.started":"2021-06-07T05:13:15.944675Z","shell.execute_reply":"2021-06-07T05:13:15.994898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# https://www.kaggle.com/ultralytics/yolov5\n# !git clone https://github.com/ultralytics/yolov5  # clone repo\n# %cd yolov5\nshutil.copytree('/kaggle/input/yolov5-official-v50-dataset/', '/kaggle/working/yolov5')\nos.chdir('/kaggle/working/yolov5')\n%pip install -qr requirements.txt # install dependencies\n\nimport torch\nfrom IPython.display import Image, clear_output  # to display images\n\nclear_output()\nprint('Setup complete. Using torch %s %s' % (torch.__version__, torch.cuda.get_device_properties(0) if torch.cuda.is_available() else 'CPU'))","metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","papermill":{"duration":6.702428,"end_time":"2021-01-01T09:50:08.784153","exception":false,"start_time":"2021-01-01T09:50:02.081725","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-06-07T05:13:31.325429Z","iopub.execute_input":"2021-06-07T05:13:31.325784Z","iopub.status.idle":"2021-06-07T05:13:45.657754Z","shell.execute_reply.started":"2021-06-07T05:13:31.325752Z","shell.execute_reply":"2021-06-07T05:13:45.656827Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!python detect.py --weights yolov5s.pt --img 640 --conf 0.25 --source data/images/\nImage(filename='runs/detect/exp/zidane.jpg', width=600)","metadata":{"papermill":{"duration":10.410768,"end_time":"2021-01-01T09:50:19.303402","exception":false,"start_time":"2021-01-01T09:50:08.892634","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-06-07T05:13:49.397476Z","iopub.execute_input":"2021-06-07T05:13:49.39781Z","iopub.status.idle":"2021-06-07T05:13:58.98238Z","shell.execute_reply.started":"2021-06-07T05:13:49.39778Z","shell.execute_reply":"2021-06-07T05:13:58.979082Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Pretrained Checkpoints:\n\n| Model | AP<sup>val</sup> | AP<sup>test</sup> | AP<sub>50</sub> | Speed<sub>GPU</sub> | FPS<sub>GPU</sub> || params | FLOPS |\n|---------- |------ |------ |------ | -------- | ------| ------ |------  |  :------: |\n| [YOLOv5s](https://github.com/ultralytics/yolov5/releases/tag/v3.0)    | 37.0     | 37.0     | 56.2     | **2.4ms** | **416** || 7.5M   | 13.2B\n| [YOLOv5m](https://github.com/ultralytics/yolov5/releases/tag/v3.0)    | 44.3     | 44.3     | 63.2     | 3.4ms     | 294     || 21.8M  | 39.4B\n| [YOLOv5l](https://github.com/ultralytics/yolov5/releases/tag/v3.0)    | 47.7     | 47.7     | 66.5     | 4.4ms     | 227     || 47.8M  | 88.1B\n| [YOLOv5x](https://github.com/ultralytics/yolov5/releases/tag/v3.0)    | **49.2** | **49.2** | **67.7** | 6.9ms     | 145     || 89.0M  | 166.4B\n| | | | | | || |\n| [YOLOv5x](https://github.com/ultralytics/yolov5/releases/tag/v3.0) + TTA|**50.8**| **50.8** | **68.9** | 25.5ms    | 39      || 89.0M  | 354.3B\n| | | | | | || |\n| [YOLOv3-SPP](https://github.com/ultralytics/yolov5/releases/tag/v3.0) | 45.6     | 45.5     | 65.2     | 4.5ms     | 222     || 63.0M  | 118.0B","metadata":{"papermill":{"duration":0.064911,"end_time":"2021-01-01T09:50:19.435746","exception":false,"start_time":"2021-01-01T09:50:19.370835","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"# Selecting Models\nIn this notebok I'm using `v5x`. To select your prefered model just replace `--cfg models/yolov5s.yaml --weights yolov5s.pt` with the following command:\n* `v5s` : `--cfg models/yolov5s.yaml --weights yolov5s.pt`\n* `v5m` : `--cfg models/yolov5m.yaml --weights yolov5m.pt`\n* `v5l` : `--cfg models/yolov5l.yaml --weights yolov5l.pt`\n* `v5x` : `--cfg models/yolov5x.yaml --weights yolov5x.pt`","metadata":{"papermill":{"duration":0.064016,"end_time":"2021-01-01T09:50:19.564859","exception":false,"start_time":"2021-01-01T09:50:19.500843","status":"completed"},"tags":[]}},{"cell_type":"markdown","source":"# Train","metadata":{"papermill":{"duration":0.064553,"end_time":"2021-01-01T09:50:19.6938","exception":false,"start_time":"2021-01-01T09:50:19.629247","status":"completed"},"tags":[]}},{"cell_type":"code","source":"# !WANDB_MODE=\"dryrun\" python train.py --img 640 --batch 16 --epochs 3 --data coco128.yaml --weights yolov5s.pt --nosave --cache \n!WANDB_MODE=\"dryrun\" python train.py --img $dim --batch $batch_size\\\n--epochs $epochs --data /kaggle/working/siim-covid-19.yaml\\\n--weights yolov5x.pt --cache","metadata":{"papermill":{"duration":19916.498298,"end_time":"2021-01-01T15:22:16.289734","exception":false,"start_time":"2021-01-01T09:50:19.791436","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-06-07T05:14:20.737821Z","iopub.execute_input":"2021-06-07T05:14:20.738175Z","iopub.status.idle":"2021-06-07T05:29:04.350125Z","shell.execute_reply.started":"2021-06-07T05:14:20.73814Z","shell.execute_reply":"2021-06-07T05:29:04.349233Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Class Distribution","metadata":{"papermill":{"duration":4.919442,"end_time":"2021-01-01T15:22:26.398681","exception":false,"start_time":"2021-01-01T15:22:21.479239","status":"completed"},"tags":[]}},{"cell_type":"code","source":"plt.figure(figsize = (20,20))\nplt.axis('off')\nplt.imshow(plt.imread('runs/train/exp/labels_correlogram.jpg'));","metadata":{"papermill":{"duration":6.511035,"end_time":"2021-01-01T15:22:37.753063","exception":false,"start_time":"2021-01-01T15:22:31.242028","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-06-07T05:29:09.556533Z","iopub.execute_input":"2021-06-07T05:29:09.556883Z","iopub.status.idle":"2021-06-07T05:29:10.366962Z","shell.execute_reply.started":"2021-06-07T05:29:09.556852Z","shell.execute_reply":"2021-06-07T05:29:10.366171Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (20,20))\nplt.axis('off')\nplt.imshow(plt.imread('runs/train/exp/labels.jpg'));","metadata":{"papermill":{"duration":5.977042,"end_time":"2021-01-01T15:22:48.614609","exception":false,"start_time":"2021-01-01T15:22:42.637567","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-06-07T05:32:23.325661Z","iopub.execute_input":"2021-06-07T05:32:23.32598Z","iopub.status.idle":"2021-06-07T05:32:23.980149Z","shell.execute_reply.started":"2021-06-07T05:32:23.325951Z","shell.execute_reply":"2021-06-07T05:32:23.979102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Batch Image","metadata":{"papermill":{"duration":5.378338,"end_time":"2021-01-01T15:22:59.482837","exception":false,"start_time":"2021-01-01T15:22:54.104499","status":"completed"},"tags":[]}},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nplt.figure(figsize = (15, 15))\nplt.imshow(plt.imread('runs/train/exp/train_batch0.jpg'))\n\nplt.figure(figsize = (15, 15))\nplt.imshow(plt.imread('runs/train/exp/train_batch1.jpg'))\n\nplt.figure(figsize = (15, 15))\nplt.imshow(plt.imread('runs/train/exp/train_batch2.jpg'))","metadata":{"papermill":{"duration":7.317416,"end_time":"2021-01-01T15:23:11.777544","exception":false,"start_time":"2021-01-01T15:23:04.460128","status":"completed"},"tags":[],"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-07T05:32:36.984601Z","iopub.execute_input":"2021-06-07T05:32:36.985039Z","iopub.status.idle":"2021-06-07T05:32:39.021999Z","shell.execute_reply.started":"2021-06-07T05:32:36.985Z","shell.execute_reply":"2021-06-07T05:32:39.021175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# GT Vs Pred","metadata":{}},{"cell_type":"code","source":"fig, ax = plt.subplots(3, 2, figsize = (3*5,4*5), constrained_layout = True)\nfor row in range(3):\n    ax[row][0].imshow(plt.imread(f'runs/train/exp/test_batch{row}_labels.jpg'))\n    ax[row][0].set_xticks([])\n    ax[row][0].set_yticks([])\n    ax[row][0].set_title(f'test_batch{row}.jpg', fontsize = 12)\n    \n    ax[row][1].imshow(plt.imread(f'runs/train/exp/test_batch{row}_pred.jpg'))\n    ax[row][1].set_xticks([])\n    ax[row][1].set_yticks([])\n    ax[row][1].set_title(f'test_batch{row}.jpg', fontsize = 12)","metadata":{"papermill":{"duration":6.453975,"end_time":"2021-01-01T15:23:23.514717","exception":false,"start_time":"2021-01-01T15:23:17.060742","status":"completed"},"tags":[],"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-07T05:33:16.469357Z","iopub.execute_input":"2021-06-07T05:33:16.469716Z","iopub.status.idle":"2021-06-07T05:33:17.196032Z","shell.execute_reply.started":"2021-06-07T05:33:16.46967Z","shell.execute_reply":"2021-06-07T05:33:17.193853Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# (Loss, Map) Vs Epoch","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(30,15))\nplt.axis('off')\nplt.imshow(plt.imread('runs/train/exp/results.png'));","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-07T05:33:39.976488Z","iopub.execute_input":"2021-06-07T05:33:39.976806Z","iopub.status.idle":"2021-06-07T05:33:40.088465Z","shell.execute_reply.started":"2021-06-07T05:33:39.976777Z","shell.execute_reply":"2021-06-07T05:33:40.086798Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Confusion Matrix","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(30,15))\nplt.axis('off')\nplt.imshow(plt.imread('runs/train/exp/confusion_matrix.png'));","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-06-07T05:33:54.484401Z","iopub.execute_input":"2021-06-07T05:33:54.48475Z","iopub.status.idle":"2021-06-07T05:33:54.604421Z","shell.execute_reply.started":"2021-06-07T05:33:54.484721Z","shell.execute_reply":"2021-06-07T05:33:54.602712Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Precision, Recall, Precision-Recall, F1 Curve","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(2*10, 2*8))\nfor idx, tag in enumerate(['P', 'R', 'PR', 'F1']):\n    plt.subplot(2, 2, idx+1)\n    plt.imshow(plt.imread(f'runs/train/exp/{tag}_curve.png'));\n    plt.axis('OFF')\n    plt.title(tag, fontsize=15)\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-06-07T05:34:44.283066Z","iopub.execute_input":"2021-06-07T05:34:44.283521Z","iopub.status.idle":"2021-06-07T05:34:44.486945Z","shell.execute_reply.started":"2021-06-07T05:34:44.28348Z","shell.execute_reply":"2021-06-07T05:34:44.483614Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Removing Files","metadata":{}},{"cell_type":"code","source":"shutil.rmtree('/kaggle/working/siim-covid-19')\nshutil.rmtree('runs/detect')\nfor file in (glob('**/*.png', recursive = True)+glob('**/*.jpg', recursive = True)):\n    os.remove(file)","metadata":{"papermill":{"duration":5.709202,"end_time":"2021-01-01T15:24:22.413173","exception":false,"start_time":"2021-01-01T15:24:16.703971","status":"completed"},"tags":[],"_kg_hide-input":true,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2021-05-29T18:03:01.702102Z","iopub.status.idle":"2021-05-29T18:03:01.702809Z"},"trusted":true},"execution_count":null,"outputs":[]}]}