{
  "id": 263734,
  "title": "8th Place Solution [Full Code Attached]",
  "url": "/competitions/siim-covid19-detection/discussion/263734",
  "author_name": "Jihun Lorenzo Park",
  "post_date": "2021-08-10T05:49:58.678000",
  "votes": 26,
  "comment_count": 17,
  "views": 0,
  "content": "<p>*submitted kernel: <a href=\"https://www.kaggle.com/jihunlorenzopark/siim-covid-sub-mmdet?scriptVersionId=70842068\" target=\"_blank\">https://www.kaggle.com/jihunlorenzopark/siim-covid-sub-mmdet?scriptVersionId=70842068</a><br>\n*full training scripts on github: <a href=\"https://github.com/lorenzo-park/siim-covid-kaggle-model-sub\" target=\"_blank\">https://github.com/lorenzo-park/siim-covid-kaggle-model-sub</a></p>\n<hr>\n<p>Thank you for hosting the competition to Kaggle, SIIM, FISABIO, RSNA. I am so happy to get the first gold for two years of Kaggling. I and my teammates keep working hard until the last night and finally the last day's submission ranked at 8th on private leaderboard!</p>\n<h1>Solution</h1>\n<p>Our model consists of three parts as most of the people have used: <br>\nStudy-level prediction, two class prediction and opacity bounding box detection. </p>\n<h3>1. Study-Level 4-class Classification (negative, typical, indeterminate, atypical)</h3>\n<ul>\n<li><p><strong>CV Strategy</strong> Stratified Grouped 5 Fold, using PatientID for grouping</p></li>\n<li><p><strong>Optimizer</strong> AdamW with CosineAnnealingWarmRestarts</p></li>\n<li><p><strong>Model</strong></p>\n<ul>\n<li>Unet++ (Efficientnetv2)</li>\n<li>Unet++ (Efficientnetv2) pretrained on NIH Chest X-rays with 5 epochs</li>\n<li>Swin Transformer pretrained on NIH Chest X-rays with 5 epochs</li>\n<li><a href=\"https://drive.google.com/file/d/1SyDLq5LJBs5bm9sj9heUJ61Ss-nUPY-2/view?usp=sharing\" target=\"_blank\">Architecture overview</a></li></ul></li>\n<li><p><strong>Loss</strong> </p>\n<ul>\n<li>Classification loss (CrossEntropy) + Segmentation auxiliary loss (1/3<em>BCELossWithLogits + 2/3</em>LovaSz loss) for Unet++ <br>\n(2 class for opacity bounding box binary mask and lung binary mask, Lung mask obtained <a href=\"https://drive.google.com/file/d/1jsq_zAERAwVPYEBGXhETxwBE3L3smom1/view?usp=sharing\" target=\"_blank\">by this heuristics</a> and opacity bbox mask))</li>\n<li><strong>Note that samples with ground truth empty masks are not contributing to segmentation loss calculation by multiplying zero to both of outputs and targets</strong> mentioned in <a href=\"https://www.kaggle.com/c/ranzcr-clip-catheter-line-classification/discussion/229706\" target=\"_blank\">this RANZCR 4th solution</a></li>\n<li>Classification loss (CrossEntropy) for Swin Transformer</li></ul></li>\n<li><p><strong>Augmentation</strong></p></li>\n</ul>\n<pre><code>    A.Compose([\n        A.Resize(img_size,img_size),\n        A.HorizontalFlip(p=0.5),\n        RandomBrightness(limit=0.1, p=0.75),\n        A.ShiftScaleRotate(shift_limit=0.2, scale_limit=0.2, rotate_limit=30, border_mode=0, p=0.75),\n        A.Cutout(max_h_size=int(img_size * 0.3), max_w_size=int(img_size * 0.3), num_holes=1, p=0.75),\n        ToTensorV2(p=1.0),\n    ])\n</code></pre>\n<ul>\n<li><strong>Ensemble</strong> Unet++_640x640 + Unet++_512x512 + Unet++_NIH_640x640 + Swin Transformer_384x384</li>\n</ul>\n<h3>2. Image-Level Opacity Detection for “opacity” by <a href=\"https://www.kaggle.com/normalkim0\" target=\"_blank\">@normalkim0</a></h3>\n<ul>\n<li><p>Ensemble of 3 YOLO models and 1 CascadedRCNN model </p>\n<ul>\n<li>yolov5x6 input size 640 (best CV score)</li>\n<li>yolov5x6 input size 1280</li>\n<li>yolov5x input size 512</li>\n<li>cascadedRCNN input size 640 (refer to <a href=\"https://www.kaggle.com/sreevishnudamodaran/siim-effnetv2-l-cascadercnn-mmdetection-infer\" target=\"_blank\">https://www.kaggle.com/sreevishnudamodaran/siim-effnetv2-l-cascadercnn-mmdetection-infer</a> <a href=\"https://www.kaggle.com/sreevishnudamodaran\" target=\"_blank\">@sreevishnudamodaran</a>)</li>\n<li>used also Stratified Grouped 5 Fold for each, using PatientID for grouping</li>\n<li>In case of Yolo, use ‘none’ image for background images. 0~10% backgound images helps to reduce False Positives.</li>\n<li>In case of cascadedRCNN, only use ‘opacity’ images.</li></ul></li>\n<li><p>use YOLOv5 Hyperparameter Evolution</p>\n<ul>\n<li>Hyperparameter evolution is a method of Hyperparameter Optimization using a Genetic Algorithm (GA) for optimization. (<a href=\"https://github.com/ultralytics/yolov5/issues/607\" target=\"_blank\">https://github.com/ultralytics/yolov5/issues/607</a>) </li>\n<li>it improved LB scores +0.003</li></ul></li>\n<li><p>Ensemble method : weighted boxes fusion</p>\n<ul>\n<li>IoU threshold : 0.5</li>\n<li>doubled the weight on the best model (yolov5x6 input size 640)</li>\n<li>the key to improving scores was diversity. we used various input image size and added cascadedRCNN at the end. There was another yolo model using 640 input size with higher score than cascadedRCNN, however the result of ensemble was reversed. (Of course, it would be better to use all the models. However it caused the timeout error.)</li></ul></li>\n</ul>\n<h3>3. Image-Level Binary Classification for \"none\"</h3>\n<ul>\n<li><p>Fine-tuned by replacing the last layer of Study-Level 4-class Classification</p></li>\n<li><p>Sharing the exact same train/valid fold of 4-class training stage to prevent potential leakage</p></li>\n<li><p><strong>Ensemble</strong> Unet++_384x384 + Swin Transformer_384x384</p></li>\n</ul>\n<h1>Reproducibility</h1>\n<ul>\n<li>Results can be reproducible with above github repository</li>\n<li>Note that some models require 48G VRAM and we've used RTX A6000 and RTX3090. Image-level opacity model will be released soon.</li>\n</ul>\n<h1>Others</h1>\n<ul>\n<li>Believed CV than LB</li>\n<li>Used <strong>early stopping</strong> for all training runs except pretraining runs. I think it contributes a lot for our public LB (0.635) to be close to private LB (0.625).</li>\n<li>For multiple images in single study, we choose the one with opacity bbox. (if all images have no bounding box, choose the random one.)</li>\n</ul>\n<h1>Reference</h1>\n<ul>\n<li><p><strong>Tools</strong></p>\n<ul>\n<li>segmentation_models.pytorch <a href=\"https://github.com/qubvel/segmentation_models.pytorch\" target=\"_blank\">https://github.com/qubvel/segmentation_models.pytorch</a> </li>\n<li>pytorch-image-models <a href=\"https://github.com/rwightman/pytorch-image-models\" target=\"_blank\">https://github.com/rwightman/pytorch-image-models</a> </li>\n<li>YOLOv5 <a href=\"https://github.com/ultralytics/yolov5\" target=\"_blank\">https://github.com/ultralytics/yolov5</a> </li>\n<li>Mmdetection <a href=\"https://github.com/open-mmlab/mmdetection\" target=\"_blank\">https://github.com/open-mmlab/mmdetection</a> </li></ul></li>\n<li><p><strong>Idea threads</strong></p>\n<ul>\n<li>Segmentation loss: <a href=\"https://www.kaggle.com/c/siim-covid19-detection/discussion/240233\" target=\"_blank\">https://www.kaggle.com/c/siim-covid19-detection/discussion/240233</a></li>\n<li>Segmentation loss calculation: <a href=\"https://www.kaggle.com/c/ranzcr-clip-catheter-line-classification/discussion/229706\" target=\"_blank\">https://www.kaggle.com/c/ranzcr-clip-catheter-line-classification/discussion/229706</a> </li></ul></li>\n<li><p><strong>Kernels</strong></p>\n<ul>\n<li>Load dcm, resize and save to png: <a href=\"https://www.kaggle.com/c/siim-covid19-detection/discussion/239918\" target=\"_blank\">https://www.kaggle.com/c/siim-covid19-detection/discussion/239918</a></li>\n<li>Timm usage: <a href=\"https://www.kaggle.com/cpmpml/stft-transformer-infer\" target=\"_blank\">https://www.kaggle.com/cpmpml/stft-transformer-infer</a> </li>\n<li>Segmentation_models.pytorch usage: <a href=\"https://www.kaggle.com/haqishen/1st-place-soluiton-code-small-ver\" target=\"_blank\">https://www.kaggle.com/haqishen/1st-place-soluiton-code-small-ver</a> </li>\n<li>CascadeRCNN: <a href=\"https://www.kaggle.com/sreevishnudamodaran/siim-mmdetection-cascadercnn-weight-bias\" target=\"_blank\">https://www.kaggle.com/sreevishnudamodaran/siim-mmdetection-cascadercnn-weight-bias</a> </li>\n<li>Weighted boxes fusion: <a href=\"https://www.kaggle.com/shonenkov/weightedboxesfusion\" target=\"_blank\">https://www.kaggle.com/shonenkov/weightedboxesfusion</a> </li></ul></li>\n<li><p><strong>External datasets</strong><br>\nNIH Chest X-rays: <a href=\"https://www.kaggle.com/nih-chest-xrays/data\" target=\"_blank\">https://www.kaggle.com/nih-chest-xrays/data</a> </p></li>\n</ul>\n<p>Thank you for reading and congratulations to all winners.<br>\nThere could be missing details in the solution. I will keep update the solution as I get the missing details in my mind back.</p>\n<hr>\n<p>*20210811: Add data duplication in Others part. <a href=\"https://www.kaggle.com/c/siim-covid19-detection/discussion/263945\" target=\"_blank\">5th solution</a> makes me remind this detail. <br>\n*20210811: Update used GPUs in Reproducilibity part*<br>\n*20210813: Add Image opacity detection part solution written by <a href=\"https://www.kaggle.com/normalkim0\" target=\"_blank\">@normalkim0</a><br>\n*20210817: Attach submitted kernel link<br>\n*20210818: Add reproducible github repository link</p>",
  "messages": [
    {
      "id": 1463165,
      "postDate": "2021-08-10T05:49:58.680Z",
      "content": "<p>*submitted kernel: <a href=\"https://www.kaggle.com/jihunlorenzopark/siim-covid-sub-mmdet?scriptVersionId=70842068\" target=\"_blank\">https://www.kaggle.com/jihunlorenzopark/siim-covid-sub-mmdet?scriptVersionId=70842068</a><br>\n*full training scripts on github: <a href=\"https://github.com/lorenzo-park/siim-covid-kaggle-model-sub\" target=\"_blank\">https://github.com/lorenzo-park/siim-covid-kaggle-model-sub</a></p>\n<hr>\n<p>Thank you for hosting the competition to Kaggle, SIIM, FISABIO, RSNA. I am so happy to get the first gold for two years of Kaggling. I and my teammates keep working hard until the last night and finally the last day's submission ranked at 8th on private leaderboard!</p>\n<h1>Solution</h1>\n<p>Our model consists of three parts as most of the people have used: <br>\nStudy-level prediction, two class prediction and opacity bounding box detection. </p>\n<h3>1. Study-Level 4-class Classification (negative, typical, indeterminate, atypical)</h3>\n<ul>\n<li><p><strong>CV Strategy</strong> Stratified Grouped 5 Fold, using PatientID for grouping</p></li>\n<li><p><strong>Optimizer</strong> AdamW with CosineAnnealingWarmRestarts</p></li>\n<li><p><strong>Model</strong></p>\n<ul>\n<li>Unet++ (Efficientnetv2)</li>\n<li>Unet++ (Efficientnetv2) pretrained on NIH Chest X-rays with 5 epochs</li>\n<li>Swin Transformer pretrained on NIH Chest X-rays with 5 epochs</li>\n<li><a href=\"https://drive.google.com/file/d/1SyDLq5LJBs5bm9sj9heUJ61Ss-nUPY-2/view?usp=sharing\" target=\"_blank\">Architecture overview</a></li></ul></li>\n<li><p><strong>Loss</strong> </p>\n<ul>\n<li>Classification loss (CrossEntropy) + Segmentation auxiliary loss (1/3<em>BCELossWithLogits + 2/3</em>LovaSz loss) for Unet++ <br>\n(2 class for opacity bounding box binary mask and lung binary mask, Lung mask obtained <a href=\"https://drive.google.com/file/d/1jsq_zAERAwVPYEBGXhETxwBE3L3smom1/view?usp=sharing\" target=\"_blank\">by this heuristics</a> and opacity bbox mask))</li>\n<li><strong>Note that samples with ground truth empty masks are not contributing to segmentation loss calculation by multiplying zero to both of outputs and targets</strong> mentioned in <a href=\"https://www.kaggle.com/c/ranzcr-clip-catheter-line-classification/discussion/229706\" target=\"_blank\">this RANZCR 4th solution</a></li>\n<li>Classification loss (CrossEntropy) for Swin Transformer</li></ul></li>\n<li><p><strong>Augmentation</strong></p></li>\n</ul>\n<pre><code>    A.Compose([\n        A.Resize(img_size,img_size),\n        A.HorizontalFlip(p=0.5),\n        RandomBrightness(limit=0.1, p=0.75),\n        A.ShiftScaleRotate(shift_limit=0.2, scale_limit=0.2, rotate_limit=30, border_mode=0, p=0.75),\n        A.Cutout(max_h_size=int(img_size * 0.3), max_w_size=int(img_size * 0.3), num_holes=1, p=0.75),\n        ToTensorV2(p=1.0),\n    ])\n</code></pre>\n<ul>\n<li><strong>Ensemble</strong> Unet++_640x640 + Unet++_512x512 + Unet++_NIH_640x640 + Swin Transformer_384x384</li>\n</ul>\n<h3>2. Image-Level Opacity Detection for “opacity” by <a href=\"https://www.kaggle.com/normalkim0\" target=\"_blank\">@normalkim0</a></h3>\n<ul>\n<li><p>Ensemble of 3 YOLO models and 1 CascadedRCNN model </p>\n<ul>\n<li>yolov5x6 input size 640 (best CV score)</li>\n<li>yolov5x6 input size 1280</li>\n<li>yolov5x input size 512</li>\n<li>cascadedRCNN input size 640 (refer to <a href=\"https://www.kaggle.com/sreevishnudamodaran/siim-effnetv2-l-cascadercnn-mmdetection-infer\" target=\"_blank\">https://www.kaggle.com/sreevishnudamodaran/siim-effnetv2-l-cascadercnn-mmdetection-infer</a> <a href=\"https://www.kaggle.com/sreevishnudamodaran\" target=\"_blank\">@sreevishnudamodaran</a>)</li>\n<li>used also Stratified Grouped 5 Fold for each, using PatientID for grouping</li>\n<li>In case of Yolo, use ‘none’ image for background images. 0~10% backgound images helps to reduce False Positives.</li>\n<li>In case of cascadedRCNN, only use ‘opacity’ images.</li></ul></li>\n<li><p>use YOLOv5 Hyperparameter Evolution</p>\n<ul>\n<li>Hyperparameter evolution is a method of Hyperparameter Optimization using a Genetic Algorithm (GA) for optimization. (<a href=\"https://github.com/ultralytics/yolov5/issues/607\" target=\"_blank\">https://github.com/ultralytics/yolov5/issues/607</a>) </li>\n<li>it improved LB scores +0.003</li></ul></li>\n<li><p>Ensemble method : weighted boxes fusion</p>\n<ul>\n<li>IoU threshold : 0.5</li>\n<li>doubled the weight on the best model (yolov5x6 input size 640)</li>\n<li>the key to improving scores was diversity. we used various input image size and added cascadedRCNN at the end. There was another yolo model using 640 input size with higher score than cascadedRCNN, however the result of ensemble was reversed. (Of course, it would be better to use all the models. However it caused the timeout error.)</li></ul></li>\n</ul>\n<h3>3. Image-Level Binary Classification for \"none\"</h3>\n<ul>\n<li><p>Fine-tuned by replacing the last layer of Study-Level 4-class Classification</p></li>\n<li><p>Sharing the exact same train/valid fold of 4-class training stage to prevent potential leakage</p></li>\n<li><p><strong>Ensemble</strong> Unet++_384x384 + Swin Transformer_384x384</p></li>\n</ul>\n<h1>Reproducibility</h1>\n<ul>\n<li>Results can be reproducible with above github repository</li>\n<li>Note that some models require 48G VRAM and we've used RTX A6000 and RTX3090. Image-level opacity model will be released soon.</li>\n</ul>\n<h1>Others</h1>\n<ul>\n<li>Believed CV than LB</li>\n<li>Used <strong>early stopping</strong> for all training runs except pretraining runs. I think it contributes a lot for our public LB (0.635) to be close to private LB (0.625).</li>\n<li>For multiple images in single study, we choose the one with opacity bbox. (if all images have no bounding box, choose the random one.)</li>\n</ul>\n<h1>Reference</h1>\n<ul>\n<li><p><strong>Tools</strong></p>\n<ul>\n<li>segmentation_models.pytorch <a href=\"https://github.com/qubvel/segmentation_models.pytorch\" target=\"_blank\">https://github.com/qubvel/segmentation_models.pytorch</a> </li>\n<li>pytorch-image-models <a href=\"https://github.com/rwightman/pytorch-image-models\" target=\"_blank\">https://github.com/rwightman/pytorch-image-models</a> </li>\n<li>YOLOv5 <a href=\"https://github.com/ultralytics/yolov5\" target=\"_blank\">https://github.com/ultralytics/yolov5</a> </li>\n<li>Mmdetection <a href=\"https://github.com/open-mmlab/mmdetection\" target=\"_blank\">https://github.com/open-mmlab/mmdetection</a> </li></ul></li>\n<li><p><strong>Idea threads</strong></p>\n<ul>\n<li>Segmentation loss: <a href=\"https://www.kaggle.com/c/siim-covid19-detection/discussion/240233\" target=\"_blank\">https://www.kaggle.com/c/siim-covid19-detection/discussion/240233</a></li>\n<li>Segmentation loss calculation: <a href=\"https://www.kaggle.com/c/ranzcr-clip-catheter-line-classification/discussion/229706\" target=\"_blank\">https://www.kaggle.com/c/ranzcr-clip-catheter-line-classification/discussion/229706</a> </li></ul></li>\n<li><p><strong>Kernels</strong></p>\n<ul>\n<li>Load dcm, resize and save to png: <a href=\"https://www.kaggle.com/c/siim-covid19-detection/discussion/239918\" target=\"_blank\">https://www.kaggle.com/c/siim-covid19-detection/discussion/239918</a></li>\n<li>Timm usage: <a href=\"https://www.kaggle.com/cpmpml/stft-transformer-infer\" target=\"_blank\">https://www.kaggle.com/cpmpml/stft-transformer-infer</a> </li>\n<li>Segmentation_models.pytorch usage: <a href=\"https://www.kaggle.com/haqishen/1st-place-soluiton-code-small-ver\" target=\"_blank\">https://www.kaggle.com/haqishen/1st-place-soluiton-code-small-ver</a> </li>\n<li>CascadeRCNN: <a href=\"https://www.kaggle.com/sreevishnudamodaran/siim-mmdetection-cascadercnn-weight-bias\" target=\"_blank\">https://www.kaggle.com/sreevishnudamodaran/siim-mmdetection-cascadercnn-weight-bias</a> </li>\n<li>Weighted boxes fusion: <a href=\"https://www.kaggle.com/shonenkov/weightedboxesfusion\" target=\"_blank\">https://www.kaggle.com/shonenkov/weightedboxesfusion</a> </li></ul></li>\n<li><p><strong>External datasets</strong><br>\nNIH Chest X-rays: <a href=\"https://www.kaggle.com/nih-chest-xrays/data\" target=\"_blank\">https://www.kaggle.com/nih-chest-xrays/data</a> </p></li>\n</ul>\n<p>Thank you for reading and congratulations to all winners.<br>\nThere could be missing details in the solution. I will keep update the solution as I get the missing details in my mind back.</p>\n<hr>\n<p>*20210811: Add data duplication in Others part. <a href=\"https://www.kaggle.com/c/siim-covid19-detection/discussion/263945\" target=\"_blank\">5th solution</a> makes me remind this detail. <br>\n*20210811: Update used GPUs in Reproducilibity part*<br>\n*20210813: Add Image opacity detection part solution written by <a href=\"https://www.kaggle.com/normalkim0\" target=\"_blank\">@normalkim0</a><br>\n*20210817: Attach submitted kernel link<br>\n*20210818: Add reproducible github repository link</p>",
      "rawMarkdown": "*submitted kernel: [https://www.kaggle.com/jihunlorenzopark/siim-covid-sub-mmdet?scriptVersionId=70842068](https://www.kaggle.com/jihunlorenzopark/siim-covid-sub-mmdet?scriptVersionId=70842068)\n*full training scripts on github: [https://github.com/lorenzo-park/siim-covid-kaggle-model-sub](https://github.com/lorenzo-park/siim-covid-kaggle-model-sub)\n\n--------------------------------------------\n\nThank you for hosting the competition to Kaggle, SIIM, FISABIO, RSNA. I am so happy to get the first gold for two years of Kaggling. I and my teammates keep working hard until the last night and finally the last day's submission ranked at 8th on private leaderboard!\n\n# Solution\n\nOur model consists of three parts as most of the people have used: \nStudy-level prediction, two class prediction and opacity bounding box detection. \n### 1. Study-Level 4-class Classification (negative, typical, indeterminate, atypical)\n\n- **CV Strategy** Stratified Grouped 5 Fold, using PatientID for grouping\n- **Optimizer** AdamW with CosineAnnealingWarmRestarts\n- **Model**\n  - Unet++ (Efficientnetv2)\n  - Unet++ (Efficientnetv2) pretrained on NIH Chest X-rays with 5 epochs\n  - Swin Transformer pretrained on NIH Chest X-rays with 5 epochs\n  - [Architecture overview](https://drive.google.com/file/d/1SyDLq5LJBs5bm9sj9heUJ61Ss-nUPY-2/view?usp=sharing)\n- **Loss** \n  - Classification loss (CrossEntropy) + Segmentation auxiliary loss (1/3*BCELossWithLogits + 2/3*LovaSz loss) for Unet++ \n(2 class for opacity bounding box binary mask and lung binary mask, Lung mask obtained [by this heuristics](https://drive.google.com/file/d/1jsq_zAERAwVPYEBGXhETxwBE3L3smom1/view?usp=sharing) and opacity bbox mask))\n  - **Note that samples with ground truth empty masks are not contributing to segmentation loss calculation by multiplying zero to both of outputs and targets** mentioned in [this RANZCR 4th solution](https://www.kaggle.com/c/ranzcr-clip-catheter-line-classification/discussion/229706)\n  - Classification loss (CrossEntropy) for Swin Transformer\n  \n- **Augmentation**\n  ```\n    A.Compose([\n        A.Resize(img_size,img_size),\n        A.HorizontalFlip(p=0.5),\n        RandomBrightness(limit=0.1, p=0.75),\n        A.ShiftScaleRotate(shift_limit=0.2, scale_limit=0.2, rotate_limit=30, border_mode=0, p=0.75),\n        A.Cutout(max_h_size=int(img_size * 0.3), max_w_size=int(img_size * 0.3), num_holes=1, p=0.75),\n        ToTensorV2(p=1.0),\n    ])\n  ```\n    \n- **Ensemble** Unet++_640x640 + Unet++_512x512 + Unet++_NIH_640x640 + Swin Transformer_384x384\n    \n\n\n### 2. Image-Level Opacity Detection for “opacity” by @normalkim0\n- Ensemble of 3 YOLO models and 1 CascadedRCNN model \n    - yolov5x6 input size 640 (best CV score)\n    - yolov5x6 input size 1280\n    - yolov5x input size 512\n    - cascadedRCNN input size 640 (refer to https://www.kaggle.com/sreevishnudamodaran/siim-effnetv2-l-cascadercnn-mmdetection-infer @sreevishnudamodaran)\n    - used also Stratified Grouped 5 Fold for each, using PatientID for grouping\n    - In case of Yolo, use ‘none’ image for background images. 0~10% backgound images helps to reduce False Positives.\n    - In case of cascadedRCNN, only use ‘opacity’ images.\n\n- use YOLOv5 Hyperparameter Evolution\n    - Hyperparameter evolution is a method of Hyperparameter Optimization using a Genetic Algorithm (GA) for optimization. (https://github.com/ultralytics/yolov5/issues/607) \n    - it improved LB scores +0.003\n\n- Ensemble method : weighted boxes fusion\n    - IoU threshold : 0.5\n    - doubled the weight on the best model (yolov5x6 input size 640)\n    - the key to improving scores was diversity. we used various input image size and added cascadedRCNN at the end. There was another yolo model using 640 input size with higher score than cascadedRCNN, however the result of ensemble was reversed. (Of course, it would be better to use all the models. However it caused the timeout error.)\n\n### 3. Image-Level Binary Classification for \"none\"\n\n- Fine-tuned by replacing the last layer of Study-Level 4-class Classification\n- Sharing the exact same train/valid fold of 4-class training stage to prevent potential leakage\n  \n- **Ensemble** Unet++_384x384 + Swin Transformer_384x384\n\n# Reproducibility\n- Results can be reproducible with above github repository\n- Note that some models require 48G VRAM and we've used RTX A6000 and RTX3090. Image-level opacity model will be released soon.\n\n# Others\n- Believed CV than LB\n- Used **early stopping** for all training runs except pretraining runs. I think it contributes a lot for our public LB (0.635) to be close to private LB (0.625).\n- For multiple images in single study, we choose the one with opacity bbox. (if all images have no bounding box, choose the random one.)\n\n# Reference\n- **Tools**\n  - segmentation_models.pytorch https://github.com/qubvel/segmentation_models.pytorch \n  - pytorch-image-models https://github.com/rwightman/pytorch-image-models \n  - YOLOv5 https://github.com/ultralytics/yolov5 \n  - Mmdetection https://github.com/open-mmlab/mmdetection \n- **Idea threads**\n  - Segmentation loss: https://www.kaggle.com/c/siim-covid19-detection/discussion/240233\n  - Segmentation loss calculation: https://www.kaggle.com/c/ranzcr-clip-catheter-line-classification/discussion/229706 \n- **Kernels**\n  - Load dcm, resize and save to png: https://www.kaggle.com/c/siim-covid19-detection/discussion/239918\n  - Timm usage: https://www.kaggle.com/cpmpml/stft-transformer-infer \n  - Segmentation_models.pytorch usage: https://www.kaggle.com/haqishen/1st-place-soluiton-code-small-ver \n  - CascadeRCNN: https://www.kaggle.com/sreevishnudamodaran/siim-mmdetection-cascadercnn-weight-bias \n  - Weighted boxes fusion: https://www.kaggle.com/shonenkov/weightedboxesfusion \n\n- **External datasets**\nNIH Chest X-rays: https://www.kaggle.com/nih-chest-xrays/data \n\n    \nThank you for reading and congratulations to all winners.\nThere could be missing details in the solution. I will keep update the solution as I get the missing details in my mind back.\n\n------------------------------------------------------------------------------------------------\n*20210811: Add data duplication in Others part. [5th solution](https://www.kaggle.com/c/siim-covid19-detection/discussion/263945) makes me remind this detail. \n*20210811: Update used GPUs in Reproducilibity part*\n*20210813: Add Image opacity detection part solution written by @normalkim0\n*20210817: Attach submitted kernel link\n*20210818: Add reproducible github repository link",
      "votes": 26
    },
    {
      "id": 1466109,
      "postDate": "2021-08-11T10:16:16.317Z",
      "content": "<p>Congratulation <a href=\"https://www.kaggle.com/jihunlorenzopark\" target=\"_blank\">@jihunlorenzopark</a> Thanks for sharing.<br>\nCan you tell me how to use the Swin Transformer.</p>",
      "rawMarkdown": "Congratulation @jihunlorenzopark Thanks for sharing.\nCan you tell me how to use the Swin Transformer.",
      "votes": 1,
      "replies": [
        {
          "id": 1466157,
          "postDate": "2021-08-11T10:37:54.550Z",
          "content": "<p>Thanks!<br>\nI used the one in timm library. It provides you the module and pretrained models with few lines of code. You can check the example usage on the kernel I mentioned in the article or my solution github repository <code>model/timm.py</code>.</p>",
          "rawMarkdown": "Thanks!\nI used the one in timm library. It provides you the module and pretrained models with few lines of code. You can check the example usage on the kernel I mentioned in the article or my solution github repository `model/timm.py`."
        }
      ]
    },
    {
      "id": 1464584,
      "postDate": "2021-08-10T16:15:34.600Z",
      "content": "<p>Congrats on the gold medal! <br>\nI obtained similar public LB score but significantly lower private LB score. May I ask how you performed \"early stopping\"? </p>",
      "rawMarkdown": "Congrats on the gold medal! \nI obtained similar public LB score but significantly lower private LB score. May I ask how you performed \"early stopping\"? ",
      "votes": 1,
      "replies": [
        {
          "id": 1465227,
          "postDate": "2021-08-11T00:43:15.033Z",
          "content": "<p>Thank you!<br>\nI used pytorch lightning and it has the early stopping callback. <br>\nIf you are asking how early stopping works, we set patience and if validation loss is not decreased for more epochs than the patience, then we stop the training and use the checkpoint at minimum validation loss.</p>",
          "rawMarkdown": "Thank you!\nI used pytorch lightning and it has the early stopping callback. \nIf you are asking how early stopping works, we set patience and if validation loss is not decreased for more epochs than the patience, then we stop the training and use the checkpoint at minimum validation loss."
        },
        {
          "id": 1465453,
          "postDate": "2021-08-11T04:02:39.367Z",
          "content": "<p>Also, the best private LB is come with 0.635 public LB submission which uses WBF for different object detection models. So WBF with different kind of model can be the reason to relatively small decrease in private LB.</p>",
          "rawMarkdown": "Also, the best private LB is come with 0.635 public LB submission which uses WBF for different object detection models. So WBF with different kind of model can be the reason to relatively small decrease in private LB."
        },
        {
          "id": 1466865,
          "postDate": "2021-08-11T16:58:22.583Z",
          "content": "<p>Thanks for your reply!</p>\n<p>I agree with you that ensemble more models can make the prediction more generalized and therefor lower decrease in private LB. 💯 In our case, we only trained one pipeline with  yolov5 and Effnet v2, thus drop from 0.636 public LB to 0.611 private LB. 😛 </p>\n<p>As you explained for early stopping, we actually applied it similarly. After you obtained the checkpoint by early stopping, did you perform a fune-tuning with smaller lr? Thanks!</p>",
          "rawMarkdown": "Thanks for your reply!\n\nI agree with you that ensemble more models can make the prediction more generalized and therefor lower decrease in private LB. 💯 In our case, we only trained one pipeline with  yolov5 and Effnet v2, thus drop from 0.636 public LB to 0.611 private LB. 😛 \n\nAs you explained for early stopping, we actually applied it similarly. After you obtained the checkpoint by early stopping, did you perform a fune-tuning with smaller lr? Thanks!\n\n",
          "votes": 1
        },
        {
          "id": 1467027,
          "postDate": "2021-08-11T18:25:48.557Z",
          "content": "<p>One more question is on the \"Lung mask obtained by this heuristics and opacity bbox mask))\". Is there a link for the tool available to use? I am curious to see how its extracted lung masks compared to the DL model. </p>\n<p>Sorry for my so many questions. 😀</p>",
          "rawMarkdown": "One more question is on the \"Lung mask obtained by this heuristics and opacity bbox mask))\". Is there a link for the tool available to use? I am curious to see how its extracted lung masks compared to the DL model. \n\nSorry for my so many questions. 😀",
          "votes": 1
        },
        {
          "id": 1467468,
          "postDate": "2021-08-12T02:20:17.917Z",
          "content": "<blockquote>\n  <p>After you obtained the checkpoint by early stopping, did you perform a fune-tuning with smaller lr? Thanks!</p>\n</blockquote>\n<p>For this part, we don't to re-train the model. The 5 checkpoints for each fold obtained by early stopping is used to submission (averaging results of 5 models). If you meant training with NIH pretrained weight, we tried with 0.1*(original LR) to encoder but using the same LR gives better CV. </p>",
          "rawMarkdown": "> After you obtained the checkpoint by early stopping, did you perform a fune-tuning with smaller lr? Thanks!\n\nFor this part, we don't to re-train the model. The 5 checkpoints for each fold obtained by early stopping is used to submission (averaging results of 5 models). If you meant training with NIH pretrained weight, we tried with 0.1*(original LR) to encoder but using the same LR gives better CV. ",
          "replies": [
            {
              "id": 1468786,
              "postDate": "2021-08-12T15:12:25.117Z",
              "rawMarkdown": "",
              "isDeleted": true
            }
          ]
        },
        {
          "id": 1467472,
          "postDate": "2021-08-12T02:22:34.783Z",
          "content": "<blockquote>\n  <p>One more question is on the \"Lung mask obtained by this heuristics and opacity bbox mask))\". Is there a link for the tool available to use?</p>\n</blockquote>\n<p>This one is done with the series of cv2 and skimage functions. Here is the snippet link <a href=\"https://github.com/lorenzo-park/kaggle-solution-siim-fisabio-rsna-covid19-detection/blob/master/dataset.py#L71\" target=\"_blank\">dataset.py file (line71-line84)</a> in my repo.<br>\nI think the quality of the lung mask would be not good as DL based method, but the advantage is clear - No need additional trainings for Lung mask segmentation DL model.</p>\n<p>I'd love to share my thoughts on any questions. Feel free to do even more :)</p>",
          "rawMarkdown": "> One more question is on the \"Lung mask obtained by this heuristics and opacity bbox mask))\". Is there a link for the tool available to use?\n\nThis one is done with the series of cv2 and skimage functions. Here is the snippet link [dataset.py file (line71-line84)](https://github.com/lorenzo-park/kaggle-solution-siim-fisabio-rsna-covid19-detection/blob/master/dataset.py#L71) in my repo.\nI think the quality of the lung mask would be not good as DL based method, but the advantage is clear - No need additional trainings for Lung mask segmentation DL model.\n\nI'd love to share my thoughts on any questions. Feel free to do even more :)"
        },
        {
          "id": 1468830,
          "postDate": "2021-08-12T15:31:05.237Z",
          "content": "<blockquote>\n  <p>For this part, we don't to re-train the model. The 5 checkpoints for each fold obtained by early stopping is used to submission (averaging results of 5 models). If you meant training with NIH pretrained weight, we tried with 0.1*(original LR) to encoder but using the same LR gives better CV. </p>\n</blockquote>\n<p>I see, thanks for your explanation! To obtain the 5 checkpoints from the 5 folds, I guess you use a constant LR during training, right?</p>\n<blockquote>\n  <p>This one is done with the series of cv2 and skimage functions. Here is the snippet link dataset.py file (line71-line84) in my repo.<br>\n  I think the quality of the lung mask would be not good as DL based method, but the advantage is clear - No need additional trainings for Lung mask segmentation DL model.</p>\n</blockquote>\n<p>Thanks for sharing! I will be happy to try your method and compare with DL. 🤓</p>",
          "rawMarkdown": "> For this part, we don't to re-train the model. The 5 checkpoints for each fold obtained by early stopping is used to submission (averaging results of 5 models). If you meant training with NIH pretrained weight, we tried with 0.1*(original LR) to encoder but using the same LR gives better CV. \n\nI see, thanks for your explanation! To obtain the 5 checkpoints from the 5 folds, I guess you use a constant LR during training, right?\n\n> This one is done with the series of cv2 and skimage functions. Here is the snippet link dataset.py file (line71-line84) in my repo.\nI think the quality of the lung mask would be not good as DL based method, but the advantage is clear - No need additional trainings for Lung mask segmentation DL model.\n\nThanks for sharing! I will be happy to try your method and compare with DL. 🤓\n\n",
          "votes": 1
        },
        {
          "id": 1469451,
          "postDate": "2021-08-13T00:10:47.817Z",
          "content": "<p>I used LR scheduler, so LR is changing during the training for each fold, but the LR should be the same across all fold.</p>",
          "rawMarkdown": "I used LR scheduler, so LR is changing during the training for each fold, but the LR should be the same across all fold."
        }
      ]
    },
    {
      "id": 1464143,
      "postDate": "2021-08-10T13:13:07.633Z",
      "content": "<p>Thanks for the detailed solution and congrats.</p>",
      "rawMarkdown": "Thanks for the detailed solution and congrats.",
      "votes": 1
    },
    {
      "id": 1463401,
      "postDate": "2021-08-10T07:19:12.970Z",
      "content": "<p>Congratulations, And thanks a lot for your share,<br>\nCan you tell me what is Segmentation auxiliary loss?</p>",
      "rawMarkdown": "Congratulations, And thanks a lot for your share,\nCan you tell me what is Segmentation auxiliary loss?",
      "votes": 1,
      "replies": [
        {
          "id": 1463435,
          "postDate": "2021-08-10T07:30:35.473Z",
          "content": "<p>Thanks! You can check <a href=\"https://www.kaggle.com/c/siim-covid19-detection/discussion/240233\" target=\"_blank\">this thread</a> out. Basically, it is multi-task training. Model gets the ability to extract more important feature for classification task by training with segmentation decoder together using segmentation auxiliary loss. </p>",
          "rawMarkdown": "Thanks! You can check [this thread](https://www.kaggle.com/c/siim-covid19-detection/discussion/240233) out. Basically, it is multi-task training. Model gets the ability to extract more important feature for classification task by training with segmentation decoder together using segmentation auxiliary loss. ",
          "votes": 1
        },
        {
          "id": 1464763,
          "postDate": "2021-08-10T17:40:29.143Z",
          "content": "<p>Sorry for the late response,<br>\nThank you <a href=\"https://www.kaggle.com/jihunlorenzopark\" target=\"_blank\">@jihunlorenzopark</a> sir for your answer,<br>\nI've understood it very well</p>",
          "rawMarkdown": "Sorry for the late response,\nThank you @jihunlorenzopark sir for your answer,\nI've understood it very well",
          "votes": 1
        }
      ]
    },
    {
      "id": 1466110,
      "postDate": "2021-08-11T10:16:20.583Z",
      "content": "<p>Congratulation <a href=\"https://www.kaggle.com/jihunlorenzopark\" target=\"_blank\">@jihunlorenzopark</a> Thanks for sharing.<br>\nCan you tell me how to use the Swin Transformer.</p>",
      "rawMarkdown": "Congratulation @jihunlorenzopark Thanks for sharing.\nCan you tell me how to use the Swin Transformer."
    }
  ],
  "comments": [
    {
      "id": 1466109,
      "author_name": "AI Dev",
      "author_url": "",
      "post_date": "2021-08-11T10:16:16.317000",
      "content": "<p>Congratulation <a href=\"https://www.kaggle.com/jihunlorenzopark\" target=\"_blank\">@jihunlorenzopark</a> Thanks for sharing.<br>\nCan you tell me how to use the Swin Transformer.</p>",
      "votes": 1,
      "replies": [
        {
          "id": 1466157,
          "author_name": "Jihun Lorenzo Park",
          "author_url": "",
          "post_date": "2021-08-11T10:37:54.550000",
          "content": "<p>Thanks!<br>\nI used the one in timm library. It provides you the module and pretrained models with few lines of code. You can check the example usage on the kernel I mentioned in the article or my solution github repository <code>model/timm.py</code>.</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 1464584,
      "author_name": "Kuan Zhang",
      "author_url": "",
      "post_date": "2021-08-10T16:15:34.600000",
      "content": "<p>Congrats on the gold medal! <br>\nI obtained similar public LB score but significantly lower private LB score. May I ask how you performed \"early stopping\"? </p>",
      "votes": 1,
      "replies": [
        {
          "id": 1465227,
          "author_name": "Jihun Lorenzo Park",
          "author_url": "",
          "post_date": "2021-08-11T00:43:15.033000",
          "content": "<p>Thank you!<br>\nI used pytorch lightning and it has the early stopping callback. <br>\nIf you are asking how early stopping works, we set patience and if validation loss is not decreased for more epochs than the patience, then we stop the training and use the checkpoint at minimum validation loss.</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1465453,
          "author_name": "Jihun Lorenzo Park",
          "author_url": "",
          "post_date": "2021-08-11T04:02:39.367000",
          "content": "<p>Also, the best private LB is come with 0.635 public LB submission which uses WBF for different object detection models. So WBF with different kind of model can be the reason to relatively small decrease in private LB.</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1466865,
          "author_name": "Kuan Zhang",
          "author_url": "",
          "post_date": "2021-08-11T16:58:22.583000",
          "content": "<p>Thanks for your reply!</p>\n<p>I agree with you that ensemble more models can make the prediction more generalized and therefor lower decrease in private LB. 💯 In our case, we only trained one pipeline with  yolov5 and Effnet v2, thus drop from 0.636 public LB to 0.611 private LB. 😛 </p>\n<p>As you explained for early stopping, we actually applied it similarly. After you obtained the checkpoint by early stopping, did you perform a fune-tuning with smaller lr? Thanks!</p>",
          "votes": 1,
          "replies": []
        },
        {
          "id": 1467027,
          "author_name": "Kuan Zhang",
          "author_url": "",
          "post_date": "2021-08-11T18:25:48.557000",
          "content": "<p>One more question is on the \"Lung mask obtained by this heuristics and opacity bbox mask))\". Is there a link for the tool available to use? I am curious to see how its extracted lung masks compared to the DL model. </p>\n<p>Sorry for my so many questions. 😀</p>",
          "votes": 1,
          "replies": []
        },
        {
          "id": 1467468,
          "author_name": "Jihun Lorenzo Park",
          "author_url": "",
          "post_date": "2021-08-12T02:20:17.917000",
          "content": "<blockquote>\n  <p>After you obtained the checkpoint by early stopping, did you perform a fune-tuning with smaller lr? Thanks!</p>\n</blockquote>\n<p>For this part, we don't to re-train the model. The 5 checkpoints for each fold obtained by early stopping is used to submission (averaging results of 5 models). If you meant training with NIH pretrained weight, we tried with 0.1*(original LR) to encoder but using the same LR gives better CV. </p>",
          "votes": 0,
          "replies": [
            {
              "id": 1468786,
              "author_name": "",
              "author_url": "",
              "post_date": "2021-08-12T15:12:25.117000",
              "content": "",
              "votes": 0,
              "replies": []
            }
          ]
        },
        {
          "id": 1467472,
          "author_name": "Jihun Lorenzo Park",
          "author_url": "",
          "post_date": "2021-08-12T02:22:34.783000",
          "content": "<blockquote>\n  <p>One more question is on the \"Lung mask obtained by this heuristics and opacity bbox mask))\". Is there a link for the tool available to use?</p>\n</blockquote>\n<p>This one is done with the series of cv2 and skimage functions. Here is the snippet link <a href=\"https://github.com/lorenzo-park/kaggle-solution-siim-fisabio-rsna-covid19-detection/blob/master/dataset.py#L71\" target=\"_blank\">dataset.py file (line71-line84)</a> in my repo.<br>\nI think the quality of the lung mask would be not good as DL based method, but the advantage is clear - No need additional trainings for Lung mask segmentation DL model.</p>\n<p>I'd love to share my thoughts on any questions. Feel free to do even more :)</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1468830,
          "author_name": "Kuan Zhang",
          "author_url": "",
          "post_date": "2021-08-12T15:31:05.237000",
          "content": "<blockquote>\n  <p>For this part, we don't to re-train the model. The 5 checkpoints for each fold obtained by early stopping is used to submission (averaging results of 5 models). If you meant training with NIH pretrained weight, we tried with 0.1*(original LR) to encoder but using the same LR gives better CV. </p>\n</blockquote>\n<p>I see, thanks for your explanation! To obtain the 5 checkpoints from the 5 folds, I guess you use a constant LR during training, right?</p>\n<blockquote>\n  <p>This one is done with the series of cv2 and skimage functions. Here is the snippet link dataset.py file (line71-line84) in my repo.<br>\n  I think the quality of the lung mask would be not good as DL based method, but the advantage is clear - No need additional trainings for Lung mask segmentation DL model.</p>\n</blockquote>\n<p>Thanks for sharing! I will be happy to try your method and compare with DL. 🤓</p>",
          "votes": 1,
          "replies": []
        },
        {
          "id": 1469451,
          "author_name": "Jihun Lorenzo Park",
          "author_url": "",
          "post_date": "2021-08-13T00:10:47.817000",
          "content": "<p>I used LR scheduler, so LR is changing during the training for each fold, but the LR should be the same across all fold.</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 1464143,
      "author_name": "Zabir Al Nazi Nabil",
      "author_url": "",
      "post_date": "2021-08-10T13:13:07.633000",
      "content": "<p>Thanks for the detailed solution and congrats.</p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 1463401,
      "author_name": "Ifti",
      "author_url": "",
      "post_date": "2021-08-10T07:19:12.970000",
      "content": "<p>Congratulations, And thanks a lot for your share,<br>\nCan you tell me what is Segmentation auxiliary loss?</p>",
      "votes": 1,
      "replies": [
        {
          "id": 1463435,
          "author_name": "Jihun Lorenzo Park",
          "author_url": "",
          "post_date": "2021-08-10T07:30:35.473000",
          "content": "<p>Thanks! You can check <a href=\"https://www.kaggle.com/c/siim-covid19-detection/discussion/240233\" target=\"_blank\">this thread</a> out. Basically, it is multi-task training. Model gets the ability to extract more important feature for classification task by training with segmentation decoder together using segmentation auxiliary loss. </p>",
          "votes": 1,
          "replies": []
        },
        {
          "id": 1464763,
          "author_name": "Ifti",
          "author_url": "",
          "post_date": "2021-08-10T17:40:29.143000",
          "content": "<p>Sorry for the late response,<br>\nThank you <a href=\"https://www.kaggle.com/jihunlorenzopark\" target=\"_blank\">@jihunlorenzopark</a> sir for your answer,<br>\nI've understood it very well</p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 1466110,
      "author_name": "AI Dev",
      "author_url": "",
      "post_date": "2021-08-11T10:16:20.583000",
      "content": "<p>Congratulation <a href=\"https://www.kaggle.com/jihunlorenzopark\" target=\"_blank\">@jihunlorenzopark</a> Thanks for sharing.<br>\nCan you tell me how to use the Swin Transformer.</p>",
      "votes": 0,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1463165": "*submitted kernel: [https://www.kaggle.com/jihunlorenzopark/siim-covid-sub-mmdet?scriptVersionId=70842068](https://www.kaggle.com/jihunlorenzopark/siim-covid-sub-mmdet?scriptVersionId=70842068)\n*full training scripts on github: [https://github.com/lorenzo-park/siim-covid-kaggle-model-sub](https://github.com/lorenzo-park/siim-covid-kaggle-model-sub)\n\n--------------------------------------------\n\nThank you for hosting the competition to Kaggle, SIIM, FISABIO, RSNA. I am so happy to get the first gold for two years of Kaggling. I and my teammates keep working hard until the last night and finally the last day's submission ranked at 8th on private leaderboard!\n\n# Solution\n\nOur model consists of three parts as most of the people have used: \nStudy-level prediction, two class prediction and opacity bounding box detection. \n### 1. Study-Level 4-class Classification (negative, typical, indeterminate, atypical)\n\n- **CV Strategy** Stratified Grouped 5 Fold, using PatientID for grouping\n- **Optimizer** AdamW with CosineAnnealingWarmRestarts\n- **Model**\n  - Unet++ (Efficientnetv2)\n  - Unet++ (Efficientnetv2) pretrained on NIH Chest X-rays with 5 epochs\n  - Swin Transformer pretrained on NIH Chest X-rays with 5 epochs\n  - [Architecture overview](https://drive.google.com/file/d/1SyDLq5LJBs5bm9sj9heUJ61Ss-nUPY-2/view?usp=sharing)\n- **Loss** \n  - Classification loss (CrossEntropy) + Segmentation auxiliary loss (1/3*BCELossWithLogits + 2/3*LovaSz loss) for Unet++ \n(2 class for opacity bounding box binary mask and lung binary mask, Lung mask obtained [by this heuristics](https://drive.google.com/file/d/1jsq_zAERAwVPYEBGXhETxwBE3L3smom1/view?usp=sharing) and opacity bbox mask))\n  - **Note that samples with ground truth empty masks are not contributing to segmentation loss calculation by multiplying zero to both of outputs and targets** mentioned in [this RANZCR 4th solution](https://www.kaggle.com/c/ranzcr-clip-catheter-line-classification/discussion/229706)\n  - Classification loss (CrossEntropy) for Swin Transformer\n  \n- **Augmentation**\n  ```\n    A.Compose([\n        A.Resize(img_size,img_size),\n        A.HorizontalFlip(p=0.5),\n        RandomBrightness(limit=0.1, p=0.75),\n        A.ShiftScaleRotate(shift_limit=0.2, scale_limit=0.2, rotate_limit=30, border_mode=0, p=0.75),\n        A.Cutout(max_h_size=int(img_size * 0.3), max_w_size=int(img_size * 0.3), num_holes=1, p=0.75),\n        ToTensorV2(p=1.0),\n    ])\n  ```\n    \n- **Ensemble** Unet++_640x640 + Unet++_512x512 + Unet++_NIH_640x640 + Swin Transformer_384x384\n    \n\n\n### 2. Image-Level Opacity Detection for “opacity” by @normalkim0\n- Ensemble of 3 YOLO models and 1 CascadedRCNN model \n    - yolov5x6 input size 640 (best CV score)\n    - yolov5x6 input size 1280\n    - yolov5x input size 512\n    - cascadedRCNN input size 640 (refer to https://www.kaggle.com/sreevishnudamodaran/siim-effnetv2-l-cascadercnn-mmdetection-infer @sreevishnudamodaran)\n    - used also Stratified Grouped 5 Fold for each, using PatientID for grouping\n    - In case of Yolo, use ‘none’ image for background images. 0~10% backgound images helps to reduce False Positives.\n    - In case of cascadedRCNN, only use ‘opacity’ images.\n\n- use YOLOv5 Hyperparameter Evolution\n    - Hyperparameter evolution is a method of Hyperparameter Optimization using a Genetic Algorithm (GA) for optimization. (https://github.com/ultralytics/yolov5/issues/607) \n    - it improved LB scores +0.003\n\n- Ensemble method : weighted boxes fusion\n    - IoU threshold : 0.5\n    - doubled the weight on the best model (yolov5x6 input size 640)\n    - the key to improving scores was diversity. we used various input image size and added cascadedRCNN at the end. There was another yolo model using 640 input size with higher score than cascadedRCNN, however the result of ensemble was reversed. (Of course, it would be better to use all the models. However it caused the timeout error.)\n\n### 3. Image-Level Binary Classification for \"none\"\n\n- Fine-tuned by replacing the last layer of Study-Level 4-class Classification\n- Sharing the exact same train/valid fold of 4-class training stage to prevent potential leakage\n  \n- **Ensemble** Unet++_384x384 + Swin Transformer_384x384\n\n# Reproducibility\n- Results can be reproducible with above github repository\n- Note that some models require 48G VRAM and we've used RTX A6000 and RTX3090. Image-level opacity model will be released soon.\n\n# Others\n- Believed CV than LB\n- Used **early stopping** for all training runs except pretraining runs. I think it contributes a lot for our public LB (0.635) to be close to private LB (0.625).\n- For multiple images in single study, we choose the one with opacity bbox. (if all images have no bounding box, choose the random one.)\n\n# Reference\n- **Tools**\n  - segmentation_models.pytorch https://github.com/qubvel/segmentation_models.pytorch \n  - pytorch-image-models https://github.com/rwightman/pytorch-image-models \n  - YOLOv5 https://github.com/ultralytics/yolov5 \n  - Mmdetection https://github.com/open-mmlab/mmdetection \n- **Idea threads**\n  - Segmentation loss: https://www.kaggle.com/c/siim-covid19-detection/discussion/240233\n  - Segmentation loss calculation: https://www.kaggle.com/c/ranzcr-clip-catheter-line-classification/discussion/229706 \n- **Kernels**\n  - Load dcm, resize and save to png: https://www.kaggle.com/c/siim-covid19-detection/discussion/239918\n  - Timm usage: https://www.kaggle.com/cpmpml/stft-transformer-infer \n  - Segmentation_models.pytorch usage: https://www.kaggle.com/haqishen/1st-place-soluiton-code-small-ver \n  - CascadeRCNN: https://www.kaggle.com/sreevishnudamodaran/siim-mmdetection-cascadercnn-weight-bias \n  - Weighted boxes fusion: https://www.kaggle.com/shonenkov/weightedboxesfusion \n\n- **External datasets**\nNIH Chest X-rays: https://www.kaggle.com/nih-chest-xrays/data \n\n    \nThank you for reading and congratulations to all winners.\nThere could be missing details in the solution. I will keep update the solution as I get the missing details in my mind back.\n\n------------------------------------------------------------------------------------------------\n*20210811: Add data duplication in Others part. [5th solution](https://www.kaggle.com/c/siim-covid19-detection/discussion/263945) makes me remind this detail. \n*20210811: Update used GPUs in Reproducilibity part*\n*20210813: Add Image opacity detection part solution written by @normalkim0\n*20210817: Attach submitted kernel link\n*20210818: Add reproducible github repository link",
    "1466109": "Congratulation @jihunlorenzopark Thanks for sharing.\nCan you tell me how to use the Swin Transformer.",
    "1464584": "Congrats on the gold medal! \nI obtained similar public LB score but significantly lower private LB score. May I ask how you performed \"early stopping\"? ",
    "1464143": "Thanks for the detailed solution and congrats.",
    "1463401": "Congratulations, And thanks a lot for your share,\nCan you tell me what is Segmentation auxiliary loss?",
    "1466110": "Congratulation @jihunlorenzopark Thanks for sharing.\nCan you tell me how to use the Swin Transformer."
  }
}