{
  "id": 263676,
  "title": "Easy Trick to Add Aux Loss",
  "url": "/competitions/siim-covid19-detection/discussion/263676",
  "author_name": "",
  "post_date": "2021-08-10T02:02:09.087716700Z",
  "votes": 51,
  "comment_count": 18,
  "views": 0,
  "content": "<h1>Silver Medal Model</h1>\n<p>The following model achieves <strong>top 50 public LB 631</strong>. My teammates <a href=\"https://www.kaggle.com/awsaf49\" target=\"_blank\">@awsaf49</a> <a href=\"https://www.kaggle.com/zaber666\" target=\"_blank\">@zaber666</a> <a href=\"https://www.kaggle.com/nexh98\" target=\"_blank\">@nexh98</a> <a href=\"https://www.kaggle.com/artemenon\" target=\"_blank\">@artemenon</a> have published our full team solution soon explaining how our team accomplished the amazing public LB 654 and private LB 631 and achieved 4th place Gold <a href=\"https://www.kaggle.com/c/siim-covid19-detection/discussion/264243\" target=\"_blank\">here</a></p>\n<h1>Easy Way to Add Aux Loss to Model</h1>\n<p>Many people were asking in the forum how to add segmentation loss to a classification model. An easy trick is to instead add classification to a segmentation model 😄</p>\n<h1>GitHub Segmentation Models</h1>\n<p>To create a model that uses both classification targets and segmentation mask, first create a segmentation model, then add a classification head in the middle of the network. We can use <a href=\"https://www.kaggle.com/pavel92\" target=\"_blank\">@pavel92</a> great GitHub repository <a href=\"https://github.com/qubvel/segmentation_models\" target=\"_blank\">here</a>. </p>\n<pre><code>import segmentation_models as sm\n\nbuild_model():\n    base_model = sm.FPN(BACKBONE, encoder_weights='imagenet', \n       input_shape=(None, None, 3), classes=3, activation='sigmoid')\n\n    x = base_model.get_layer(name='top_activation').output \n    x = tf.keras.layers.GlobalAveragePooling2D()(x)\n    x = tf.keras.layers.Dense(4, activation='sigmoid', name='out2')(x)\n\n    model = tf.keras.Model(inputs=base_model.input, \n       outputs=[base_model.output,x]) \n\n    opt = tf.keras.optimizers.Adam()\n    met1 = sm.metrics.iou_score\n    met2 = tf.keras.metrics.AUC(curve='PR',multi_label=True)\n    loss1 = sm.losses.bce_jaccard_loss\n    loss2 = tf.keras.losses.BinaryCrossentropy()\n\n    model.compile(loss={'sigmoid':loss1,'out2':loss2}, \n              loss_weights = [1.0,1.0], optimizer = opt,\n              metrics={'sigmoid':met1, 'out2':met2}) \n\n    return model\n</code></pre>\n<h1>Data Loader</h1>\n<p>We then train with xray images, classification targets, and segmentation masks (created from train bbox). The targets above the segmentation masks below are <code>\"negative\", \"typical\", \"indeterminate\", \"atypical\"</code> respectively. Adding data augmentation and reduce learning rate on plateau improves training.</p>\n<p><img src=\"https://raw.githubusercontent.com/cdeotte/Kaggle_Images/main/Aug-2021/seg_mask.png\" alt=\"\"></p>\n<h1>LB 0.631</h1>\n<p>During inference, this model produces targets, \"negative\", \"typical\", \"indeterminate\", \"atypical\" and we discard the segmentation masks. If we train a few models with EffNetB2, B3, B4 backbones and a few image sizes 448, 512, 576 then using this model's \"negative\" target as \"none\" target achieve LB 0.535 without detection \"opacity\". Next add a strong Detection model (like VFNet, EffDet, or Yolo) for \"opacity\" and you have LB 0.631 silver medal model.</p>\n<p>(According to Heng's terminology in his study kit <a href=\"https://www.kaggle.com/c/siim-covid19-detection/discussion/240233\" target=\"_blank\">here</a>, the model described above achieves \"LB 0.455 (study only)\" with \"none 1 0 0 1 1\". Or \"LB 0.405 without none 1 0 0 1 1\")</p>\n<h1>Starter Notebook</h1>\n<p>Kaggle user <a href=\"https://www.kaggle.com/tt195361\" target=\"_blank\">@tt195361</a> created a starter notebook using this model <a href=\"https://www.kaggle.com/tt195361/siim-covid-19-tf-study-level-model-with-aux-loss\" target=\"_blank\">here</a>. Great work tt195361, thanks for posting!</p>\n<h1>Gold Medal Model</h1>\n<p>My teammates <a href=\"https://www.kaggle.com/awsaf49\" target=\"_blank\">@awsaf49</a> <a href=\"https://www.kaggle.com/zaber666\" target=\"_blank\">@zaber666</a> <a href=\"https://www.kaggle.com/nexh98\" target=\"_blank\">@nexh98</a> <a href=\"https://www.kaggle.com/artemenon\" target=\"_blank\">@artemenon</a> will describe how our team achieved a LB 0.654 Gold medal solution soon. Stay tuned!</p>",
  "messages": [
    {
      "id": "1462778",
      "postDate": "08/10/2021 02:02:09",
      "content": "<h1>Silver Medal Model</h1>\n<p>The following model achieves <strong>top 50 public LB 631</strong>. My teammates <a href=\"https://www.kaggle.com/awsaf49\" target=\"_blank\">@awsaf49</a> <a href=\"https://www.kaggle.com/zaber666\" target=\"_blank\">@zaber666</a> <a href=\"https://www.kaggle.com/nexh98\" target=\"_blank\">@nexh98</a> <a href=\"https://www.kaggle.com/artemenon\" target=\"_blank\">@artemenon</a> have published our full team solution soon explaining how our team accomplished the amazing public LB 654 and private LB 631 and achieved 4th place Gold <a href=\"https://www.kaggle.com/c/siim-covid19-detection/discussion/264243\" target=\"_blank\">here</a></p>\n<h1>Easy Way to Add Aux Loss to Model</h1>\n<p>Many people were asking in the forum how to add segmentation loss to a classification model. An easy trick is to instead add classification to a segmentation model 😄</p>\n<h1>GitHub Segmentation Models</h1>\n<p>To create a model that uses both classification targets and segmentation mask, first create a segmentation model, then add a classification head in the middle of the network. We can use <a href=\"https://www.kaggle.com/pavel92\" target=\"_blank\">@pavel92</a> great GitHub repository <a href=\"https://github.com/qubvel/segmentation_models\" target=\"_blank\">here</a>. </p>\n<pre><code>import segmentation_models as sm\n\nbuild_model():\n    base_model = sm.FPN(BACKBONE, encoder_weights='imagenet', \n       input_shape=(None, None, 3), classes=3, activation='sigmoid')\n\n    x = base_model.get_layer(name='top_activation').output \n    x = tf.keras.layers.GlobalAveragePooling2D()(x)\n    x = tf.keras.layers.Dense(4, activation='sigmoid', name='out2')(x)\n\n    model = tf.keras.Model(inputs=base_model.input, \n       outputs=[base_model.output,x]) \n\n    opt = tf.keras.optimizers.Adam()\n    met1 = sm.metrics.iou_score\n    met2 = tf.keras.metrics.AUC(curve='PR',multi_label=True)\n    loss1 = sm.losses.bce_jaccard_loss\n    loss2 = tf.keras.losses.BinaryCrossentropy()\n\n    model.compile(loss={'sigmoid':loss1,'out2':loss2}, \n              loss_weights = [1.0,1.0], optimizer = opt,\n              metrics={'sigmoid':met1, 'out2':met2}) \n\n    return model\n</code></pre>\n<h1>Data Loader</h1>\n<p>We then train with xray images, classification targets, and segmentation masks (created from train bbox). The targets above the segmentation masks below are <code>\"negative\", \"typical\", \"indeterminate\", \"atypical\"</code> respectively. Adding data augmentation and reduce learning rate on plateau improves training.</p>\n<p><img src=\"https://raw.githubusercontent.com/cdeotte/Kaggle_Images/main/Aug-2021/seg_mask.png\" alt=\"\"></p>\n<h1>LB 0.631</h1>\n<p>During inference, this model produces targets, \"negative\", \"typical\", \"indeterminate\", \"atypical\" and we discard the segmentation masks. If we train a few models with EffNetB2, B3, B4 backbones and a few image sizes 448, 512, 576 then using this model's \"negative\" target as \"none\" target achieve LB 0.535 without detection \"opacity\". Next add a strong Detection model (like VFNet, EffDet, or Yolo) for \"opacity\" and you have LB 0.631 silver medal model.</p>\n<p>(According to Heng's terminology in his study kit <a href=\"https://www.kaggle.com/c/siim-covid19-detection/discussion/240233\" target=\"_blank\">here</a>, the model described above achieves \"LB 0.455 (study only)\" with \"none 1 0 0 1 1\". Or \"LB 0.405 without none 1 0 0 1 1\")</p>\n<h1>Starter Notebook</h1>\n<p>Kaggle user <a href=\"https://www.kaggle.com/tt195361\" target=\"_blank\">@tt195361</a> created a starter notebook using this model <a href=\"https://www.kaggle.com/tt195361/siim-covid-19-tf-study-level-model-with-aux-loss\" target=\"_blank\">here</a>. Great work tt195361, thanks for posting!</p>\n<h1>Gold Medal Model</h1>\n<p>My teammates <a href=\"https://www.kaggle.com/awsaf49\" target=\"_blank\">@awsaf49</a> <a href=\"https://www.kaggle.com/zaber666\" target=\"_blank\">@zaber666</a> <a href=\"https://www.kaggle.com/nexh98\" target=\"_blank\">@nexh98</a> <a href=\"https://www.kaggle.com/artemenon\" target=\"_blank\">@artemenon</a> will describe how our team achieved a LB 0.654 Gold medal solution soon. Stay tuned!</p>",
      "rawMarkdown": "# Silver Medal Model\nThe following model achieves **top 50 public LB 631**. My teammates @awsaf49 @zaber666 @nexh98 @artemenon have published our full team solution soon explaining how our team accomplished the amazing public LB 654 and private LB 631 and achieved 4th place Gold [here][4]\n\n# Easy Way to Add Aux Loss to Model\nMany people were asking in the forum how to add segmentation loss to a classification model. An easy trick is to instead add classification to a segmentation model 😄\n\n# GitHub Segmentation Models\nTo create a model that uses both classification targets and segmentation mask, first create a segmentation model, then add a classification head in the middle of the network. We can use @pavel92 great GitHub repository [here][1]. \n\n    import segmentation_models as sm\n\n    build_model():\n        base_model = sm.FPN(BACKBONE, encoder_weights='imagenet', \n           input_shape=(None, None, 3), classes=3, activation='sigmoid')\n    \n        x = base_model.get_layer(name='top_activation').output \n        x = tf.keras.layers.GlobalAveragePooling2D()(x)\n        x = tf.keras.layers.Dense(4, activation='sigmoid', name='out2')(x)\n            \n        model = tf.keras.Model(inputs=base_model.input, \n           outputs=[base_model.output,x]) \n    \n        opt = tf.keras.optimizers.Adam()\n        met1 = sm.metrics.iou_score\n        met2 = tf.keras.metrics.AUC(curve='PR',multi_label=True)\n        loss1 = sm.losses.bce_jaccard_loss\n        loss2 = tf.keras.losses.BinaryCrossentropy()\n        \n        model.compile(loss={'sigmoid':loss1,'out2':loss2}, \n                  loss_weights = [1.0,1.0], optimizer = opt,\n                  metrics={'sigmoid':met1, 'out2':met2}) \n        \n        return model\n\n# Data Loader\nWe then train with xray images, classification targets, and segmentation masks (created from train bbox). The targets above the segmentation masks below are `\"negative\", \"typical\", \"indeterminate\", \"atypical\"` respectively. Adding data augmentation and reduce learning rate on plateau improves training.\n\n![](https://raw.githubusercontent.com/cdeotte/Kaggle_Images/main/Aug-2021/seg_mask.png)\n\n# LB 0.631\nDuring inference, this model produces targets, \"negative\", \"typical\", \"indeterminate\", \"atypical\" and we discard the segmentation masks. If we train a few models with EffNetB2, B3, B4 backbones and a few image sizes 448, 512, 576 then using this model's \"negative\" target as \"none\" target achieve LB 0.535 without detection \"opacity\". Next add a strong Detection model (like VFNet, EffDet, or Yolo) for \"opacity\" and you have LB 0.631 silver medal model.\n\n(According to Heng's terminology in his study kit [here][2], the model described above achieves \"LB 0.455 (study only)\" with \"none 1 0 0 1 1\". Or \"LB 0.405 without none 1 0 0 1 1\")\n\n# Starter Notebook\nKaggle user @tt195361 created a starter notebook using this model [here][3]. Great work tt195361, thanks for posting!\n\n# Gold Medal Model\nMy teammates @awsaf49 @zaber666 @nexh98 @artemenon will describe how our team achieved a LB 0.654 Gold medal solution soon. Stay tuned!\n\n[1]: https://github.com/qubvel/segmentation_models\n[2]: https://www.kaggle.com/c/siim-covid19-detection/discussion/240233\n[3]: https://www.kaggle.com/tt195361/siim-covid-19-tf-study-level-model-with-aux-loss\n[4]: https://www.kaggle.com/c/siim-covid19-detection/discussion/264243",
      "votes": null
    },
    {
      "id": "1462814",
      "postDate": "08/10/2021 02:22:26",
      "content": "<p>\"none\" target achieve LB 0.535 without detection \"opacity\". </p>\n<p>I am also using this (because my \"none\" classifier was performing worse). </p>\n<p>Code to convert \"negative to opacity\" , see  function:  def make_fake_opacity_prediction(df_image, df_study, df_meta)</p>\n<p><a href=\"https://www.kaggle.com/hengck23/final-v-00-private-public-score-0-615-0-628?scriptVersionId=70933214\" target=\"_blank\">https://www.kaggle.com/hengck23/final-v-00-private-public-score-0-615-0-628?scriptVersionId=70933214</a></p>\n<hr>\n<p>Here are some statics for some who wonder why:<br>\n<img src=\"https://i.ibb.co/QMcSywS/Selection-666.png\" alt=\"https://i.ibb.co/QMcSywS/Selection-666.png\"></p>\n<p>\"none\" = 1-\"opacity\"</p>\n<p>all negative study are \"none\" images. about more than 96% of \"non\" images are negative study. </p>\n<p>also, comparing negative, none and max opacity box:</p>\n<p><img src=\"https://i.ibb.co/YpqmTtH/Selection-667.png\" alt=\"https://i.ibb.co/YpqmTtH/Selection-667.png\"></p>",
      "rawMarkdown": "\"none\" target achieve LB 0.535 without detection \"opacity\". \n\nI am also using this (because my \"none\" classifier was performing worse). \n\nCode to convert \"negative to opacity\" , see  function:  def make_fake_opacity_prediction(df_image, df_study, df_meta)\n\nhttps://www.kaggle.com/hengck23/final-v-00-private-public-score-0-615-0-628?scriptVersionId=70933214\n\n----\n\n\nHere are some statics for some who wonder why:\n![https://i.ibb.co/QMcSywS/Selection-666.png](https://i.ibb.co/QMcSywS/Selection-666.png)\n\n\"none\" = 1-\"opacity\"\n\nall negative study are \"none\" images. about more than 96% of \"non\" images are negative study. \n\nalso, comparing negative, none and max opacity box:\n\n\n![https://i.ibb.co/YpqmTtH/Selection-667.png](https://i.ibb.co/YpqmTtH/Selection-667.png)",
      "votes": null
    },
    {
      "id": "1462877",
      "postDate": "08/10/2021 03:01:47",
      "content": "<p>Congratulations! I look forward to reading your solutions. </p>",
      "rawMarkdown": "Congratulations! I look forward to reading your solutions.",
      "votes": null
    },
    {
      "id": "1463376",
      "postDate": "08/10/2021 07:10:38",
      "content": "<p>Congrats! Great work. </p>",
      "rawMarkdown": "Congrats! Great work.",
      "votes": null
    },
    {
      "id": "1463414",
      "postDate": "08/10/2021 07:23:39",
      "content": "<p>Congratulations <a href=\"https://www.kaggle.com/cdeotte\" target=\"_blank\">@cdeotte</a>, I'm your big fan and I'm a beginner in kaggle,<br>\nCan you tell me what is Aux Loss?</p>",
      "rawMarkdown": "Congratulations @cdeotte, I'm your big fan and I'm a beginner in kaggle,\nCan you tell me what is Aux Loss?",
      "votes": null
    },
    {
      "id": "1463794",
      "postDate": "08/10/2021 10:36:23",
      "content": "<p>Aux Loss is auxiliary loss. It is adding an auxiliary (additional, i.e. mulit-task) target to your classification model.</p>\n<p>Regarding the 4 study labels, we are asked to predict 4 classification targets \"negative\", \"typical\", \"indeterminate\", \"atypical\". So all your classification model needs are 4 softmax or sigmoid outputs. However, we are also given train segmentation masks. So in addition to outputting what we need (4 classification targets), we can have our model have an extra head which predicts segmentation masks.</p>\n<p>During training, our model receives training (i.e. loss function) from how it does on both the 4 classification targets and how it does making segmentation masks. This helps it learn to produce better classification targets.</p>\n<p>Finally, during inference when our model predicts both 4 classification and segmentation mask. We discard the segmentation mask because we don't need them. And only submit the 4 classification targets to Kaggle.</p>",
      "rawMarkdown": "Aux Loss is auxiliary loss. It is adding an auxiliary (additional, i.e. mulit-task) target to your classification model.\n\nRegarding the 4 study labels, we are asked to predict 4 classification targets \"negative\", \"typical\", \"indeterminate\", \"atypical\". So all your classification model needs are 4 softmax or sigmoid outputs. However, we are also given train segmentation masks. So in addition to outputting what we need (4 classification targets), we can have our model have an extra head which predicts segmentation masks.\n\nDuring training, our model receives training (i.e. loss function) from how it does on both the 4 classification targets and how it does making segmentation masks. This helps it learn to produce better classification targets.\n\nFinally, during inference when our model predicts both 4 classification and segmentation mask. We discard the segmentation mask because we don't need them. And only submit the 4 classification targets to Kaggle.",
      "votes": null
    },
    {
      "id": "1463900",
      "postDate": "08/10/2021 11:26:41",
      "content": "<p>Thanks a lot, <a href=\"https://www.kaggle.com/cdeotte\" target=\"_blank\">@cdeotte</a> sir for your detailed answer, <br>\nAs I'm a beginner I'm confused about    what is segmentation masks and how it helps to learn models to produce better classification target?</p>",
      "rawMarkdown": "Thanks a lot, @cdeotte sir for your detailed answer, \nAs I'm a beginner I'm confused about    what is segmentation masks and how it helps to learn models to produce better classification target?",
      "votes": null
    },
    {
      "id": "1463926",
      "postDate": "08/10/2021 11:41:31",
      "content": "<p>Segmentation masks are the given bounding boxes converted into an image with rectangles. Below are segmentation masks beside their associated xray image. This is what we train our model with. </p>\n<p>For example, we show our model the image. Above the masks are the classification targets, <code>['Negative for Pneumonia','Typical Appearance', 'Indeterminate Appearance', 'Atypical Appearance']</code>. The left xray is <code>Indeterminate</code> and the right xray is <code>Typical</code>. We will ask our model to predict these targets and predict the segmentation mask, i.e. the model will draw where the yellow and red rectangles are.</p>\n<p>By requiring the model to locate the anomaly in addition to classifying it, the model will become smarter.</p>\n<p><img src=\"https://storage.googleapis.com/kagglesdsdata/datasets/1509614/2514753/seg_mask.png?X-Goog-Algorithm=GOOG4-RSA-SHA256&amp;X-Goog-Credential=databundle-worker-v2%40kaggle-161607.iam.gserviceaccount.com%2F20210810%2Fauto%2Fstorage%2Fgoog4_request&amp;X-Goog-Date=20210810T113314Z&amp;X-Goog-Expires=345599&amp;X-Goog-SignedHeaders=host&amp;X-Goog-Signature=56ee06946310cdfa38e4436bb0c3542eaef8284a09857aaab90cb1708452c1150e824d9db00eaad85535509d4491e07784c0f2f905c707641011ef969ece06eb5003079d5beb538e99a64b3bdf4ac8f4224b8cb1af114bd219b7a87cb6b0239dd14cc41bd5876dfd42185e3ca20bbfc234ce89fe57110a5db5cfde7da6b67a3852f8ffd65ca7fdd26aa5983d9e339b11290debec2af759667f6e10db7e8eb99a87af4e0fdd3df191f808339482d5c68c3052114fd681925345b9c1d6b32a03838a81f935dd8e2fe63a481cab86632a419d5f245a6065c7f5fbf7b0238858def4a2e807325b276a668817633f9ac56b54623e155603e2d805698efd61562e1ec8\" alt=\"\"></p>",
      "rawMarkdown": "Segmentation masks are the given bounding boxes converted into an image with rectangles. Below are segmentation masks beside their associated xray image. This is what we train our model with. \n\nFor example, we show our model the image. Above the masks are the classification targets, `['Negative for Pneumonia','Typical Appearance', 'Indeterminate Appearance', 'Atypical Appearance']`. The left xray is `Indeterminate` and the right xray is `Typical`. We will ask our model to predict these targets and predict the segmentation mask, i.e. the model will draw where the yellow and red rectangles are.\n\nBy requiring the model to locate the anomaly in addition to classifying it, the model will become smarter.\n\n![](https://storage.googleapis.com/kagglesdsdata/datasets/1509614/2514753/seg_mask.png?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=databundle-worker-v2%40kaggle-161607.iam.gserviceaccount.com%2F20210810%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20210810T113314Z&X-Goog-Expires=345599&X-Goog-SignedHeaders=host&X-Goog-Signature=56ee06946310cdfa38e4436bb0c3542eaef8284a09857aaab90cb1708452c1150e824d9db00eaad85535509d4491e07784c0f2f905c707641011ef969ece06eb5003079d5beb538e99a64b3bdf4ac8f4224b8cb1af114bd219b7a87cb6b0239dd14cc41bd5876dfd42185e3ca20bbfc234ce89fe57110a5db5cfde7da6b67a3852f8ffd65ca7fdd26aa5983d9e339b11290debec2af759667f6e10db7e8eb99a87af4e0fdd3df191f808339482d5c68c3052114fd681925345b9c1d6b32a03838a81f935dd8e2fe63a481cab86632a419d5f245a6065c7f5fbf7b0238858def4a2e807325b276a668817633f9ac56b54623e155603e2d805698efd61562e1ec8)",
      "votes": null
    },
    {
      "id": "1464287",
      "postDate": "08/10/2021 14:19:39",
      "content": "<p>Thanks a lot, <a href=\"https://www.kaggle.com/cdeotte\" target=\"_blank\">@cdeotte</a> sir for your great answer😄,<br>\nI'm still learning and I need to study more</p>",
      "rawMarkdown": "Thanks a lot, @cdeotte sir for your great answer😄,\nI'm still learning and I need to study more",
      "votes": null
    },
    {
      "id": "1464297",
      "postDate": "08/10/2021 14:22:38",
      "content": "<p>Welcome to the exciting field of ML, DL and data analytics. Great job achieving LB mAP 614. This was a very difficult competition requiring very complicated models. If you can do this, you can do anything in the domain of image models!</p>",
      "rawMarkdown": "Welcome to the exciting field of ML, DL and data analytics. Great job achieving LB mAP 614. This was a very difficult competition requiring very complicated models. If you can do this, you can do anything in the domain of image models!",
      "votes": null
    },
    {
      "id": "1464677",
      "postDate": "08/10/2021 16:59:10",
      "content": "<p>Thank you, <a href=\"https://www.kaggle.com/cdeotte\" target=\"_blank\">@cdeotte</a> sir, for your motivation,<br>\nI'm actually a class 7 student and I'm also a lover of machine learning 😄,<br>\nI wish there would always be a kaggler like you</p>",
      "rawMarkdown": "Thank you, @cdeotte sir, for your motivation,\nI'm actually a class 7 student and I'm also a lover of machine learning 😄,\nI wish there would always be a kaggler like you",
      "votes": null
    },
    {
      "id": "1466814",
      "postDate": "08/11/2021 16:34:23",
      "content": "<p>Good work i got idea from this info.</p>",
      "rawMarkdown": "Good work i got idea from this info.",
      "votes": null
    },
    {
      "id": "1466951",
      "postDate": "08/11/2021 17:42:16",
      "content": "<p>Great job! Thank you for sharing your baseline kernel. It was very helpful. Good luck to you in future competitions. </p>",
      "rawMarkdown": "Great job! Thank you for sharing your baseline kernel. It was very helpful. Good luck to you in future competitions.",
      "votes": null
    },
    {
      "id": "1467312",
      "postDate": "08/11/2021 23:33:56",
      "content": "<p>Thank you very much for sharing this valuable information <a href=\"https://www.kaggle.com/cdeotte\" target=\"_blank\">@cdeotte</a>! I tried to run the model you explained in the notebook <a href=\"https://www.kaggle.com/tt195361/siim-covid-19-tf-study-level-model-with-aux-loss\" target=\"_blank\">here</a>. From the result, mean AUC of the 4 study classes is improved 0.0166! (with aux loss 0.5766, without 0.5600). It's great!</p>",
      "rawMarkdown": "Thank you very much for sharing this valuable information @cdeotte! I tried to run the model you explained in the notebook [here](https://www.kaggle.com/tt195361/siim-covid-19-tf-study-level-model-with-aux-loss). From the result, mean AUC of the 4 study classes is improved 0.0166! (with aux loss 0.5766, without 0.5600). It's great!",
      "votes": null
    },
    {
      "id": "1467327",
      "postDate": "08/11/2021 23:45:40",
      "content": "<p>I love your topics  😍</p>",
      "rawMarkdown": "I love your topics  😍",
      "votes": null
    },
    {
      "id": "1467400",
      "postDate": "08/12/2021 00:59:37",
      "content": "<p>Thank you so much for sharing the aux loss. I've learned something :) </p>",
      "rawMarkdown": "Thank you so much for sharing the aux loss. I've learned something :)",
      "votes": null
    },
    {
      "id": "1467446",
      "postDate": "08/12/2021 01:50:01",
      "content": "<p>Fantastic work <a href=\"https://www.kaggle.com/tt195361\" target=\"_blank\">@tt195361</a> . Thanks for creating a notebook! Good job</p>",
      "rawMarkdown": "Fantastic work @tt195361 . Thanks for creating a notebook! Good job",
      "votes": null
    },
    {
      "id": "1467451",
      "postDate": "08/12/2021 01:56:12",
      "content": "<p>I updated my post with a link to your wonderful notebook. Thank you.</p>",
      "rawMarkdown": "I updated my post with a link to your wonderful notebook. Thank you.",
      "votes": null
    },
    {
      "id": "1467935",
      "postDate": "08/12/2021 07:32:26",
      "content": "<p>Thank you so much <a href=\"https://www.kaggle.com/cdeotte\" target=\"_blank\">@cdeotte</a>!!!  It's unbelievably wonderful for me!!!</p>",
      "rawMarkdown": "Thank you so much @cdeotte!!!  It's unbelievably wonderful for me!!!",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1462814,
      "author_name": "hengck23",
      "author_url": "",
      "post_date": "08/10/2021 02:22:26",
      "content": "<p>\"none\" target achieve LB 0.535 without detection \"opacity\". </p>\n<p>I am also using this (because my \"none\" classifier was performing worse). </p>\n<p>Code to convert \"negative to opacity\" , see  function:  def make_fake_opacity_prediction(df_image, df_study, df_meta)</p>\n<p><a href=\"https://www.kaggle.com/hengck23/final-v-00-private-public-score-0-615-0-628?scriptVersionId=70933214\" target=\"_blank\">https://www.kaggle.com/hengck23/final-v-00-private-public-score-0-615-0-628?scriptVersionId=70933214</a></p>\n<hr>\n<p>Here are some statics for some who wonder why:<br>\n<img src=\"https://i.ibb.co/QMcSywS/Selection-666.png\" alt=\"https://i.ibb.co/QMcSywS/Selection-666.png\"></p>\n<p>\"none\" = 1-\"opacity\"</p>\n<p>all negative study are \"none\" images. about more than 96% of \"non\" images are negative study. </p>\n<p>also, comparing negative, none and max opacity box:</p>\n<p><img src=\"https://i.ibb.co/YpqmTtH/Selection-667.png\" alt=\"https://i.ibb.co/YpqmTtH/Selection-667.png\"></p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1462877,
      "author_name": "dskswu",
      "author_url": "",
      "post_date": "08/10/2021 03:01:47",
      "content": "<p>Congratulations! I look forward to reading your solutions. </p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1463376,
      "author_name": "kag0306",
      "author_url": "",
      "post_date": "08/10/2021 07:10:38",
      "content": "<p>Congrats! Great work. </p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1463414,
      "author_name": "iftiben10",
      "author_url": "",
      "post_date": "08/10/2021 07:23:39",
      "content": "<p>Congratulations <a href=\"https://www.kaggle.com/cdeotte\" target=\"_blank\">@cdeotte</a>, I'm your big fan and I'm a beginner in kaggle,<br>\nCan you tell me what is Aux Loss?</p>",
      "votes": null,
      "replies": [
        {
          "id": 1463794,
          "author_name": "cdeotte",
          "author_url": "",
          "post_date": "08/10/2021 10:36:23",
          "content": "<p>Aux Loss is auxiliary loss. It is adding an auxiliary (additional, i.e. mulit-task) target to your classification model.</p>\n<p>Regarding the 4 study labels, we are asked to predict 4 classification targets \"negative\", \"typical\", \"indeterminate\", \"atypical\". So all your classification model needs are 4 softmax or sigmoid outputs. However, we are also given train segmentation masks. So in addition to outputting what we need (4 classification targets), we can have our model have an extra head which predicts segmentation masks.</p>\n<p>During training, our model receives training (i.e. loss function) from how it does on both the 4 classification targets and how it does making segmentation masks. This helps it learn to produce better classification targets.</p>\n<p>Finally, during inference when our model predicts both 4 classification and segmentation mask. We discard the segmentation mask because we don't need them. And only submit the 4 classification targets to Kaggle.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1463900,
          "author_name": "iftiben10",
          "author_url": "",
          "post_date": "08/10/2021 11:26:41",
          "content": "<p>Thanks a lot, <a href=\"https://www.kaggle.com/cdeotte\" target=\"_blank\">@cdeotte</a> sir for your detailed answer, <br>\nAs I'm a beginner I'm confused about    what is segmentation masks and how it helps to learn models to produce better classification target?</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1463926,
          "author_name": "cdeotte",
          "author_url": "",
          "post_date": "08/10/2021 11:41:31",
          "content": "<p>Segmentation masks are the given bounding boxes converted into an image with rectangles. Below are segmentation masks beside their associated xray image. This is what we train our model with. </p>\n<p>For example, we show our model the image. Above the masks are the classification targets, <code>['Negative for Pneumonia','Typical Appearance', 'Indeterminate Appearance', 'Atypical Appearance']</code>. The left xray is <code>Indeterminate</code> and the right xray is <code>Typical</code>. We will ask our model to predict these targets and predict the segmentation mask, i.e. the model will draw where the yellow and red rectangles are.</p>\n<p>By requiring the model to locate the anomaly in addition to classifying it, the model will become smarter.</p>\n<p><img src=\"https://storage.googleapis.com/kagglesdsdata/datasets/1509614/2514753/seg_mask.png?X-Goog-Algorithm=GOOG4-RSA-SHA256&amp;X-Goog-Credential=databundle-worker-v2%40kaggle-161607.iam.gserviceaccount.com%2F20210810%2Fauto%2Fstorage%2Fgoog4_request&amp;X-Goog-Date=20210810T113314Z&amp;X-Goog-Expires=345599&amp;X-Goog-SignedHeaders=host&amp;X-Goog-Signature=56ee06946310cdfa38e4436bb0c3542eaef8284a09857aaab90cb1708452c1150e824d9db00eaad85535509d4491e07784c0f2f905c707641011ef969ece06eb5003079d5beb538e99a64b3bdf4ac8f4224b8cb1af114bd219b7a87cb6b0239dd14cc41bd5876dfd42185e3ca20bbfc234ce89fe57110a5db5cfde7da6b67a3852f8ffd65ca7fdd26aa5983d9e339b11290debec2af759667f6e10db7e8eb99a87af4e0fdd3df191f808339482d5c68c3052114fd681925345b9c1d6b32a03838a81f935dd8e2fe63a481cab86632a419d5f245a6065c7f5fbf7b0238858def4a2e807325b276a668817633f9ac56b54623e155603e2d805698efd61562e1ec8\" alt=\"\"></p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1464287,
          "author_name": "iftiben10",
          "author_url": "",
          "post_date": "08/10/2021 14:19:39",
          "content": "<p>Thanks a lot, <a href=\"https://www.kaggle.com/cdeotte\" target=\"_blank\">@cdeotte</a> sir for your great answer😄,<br>\nI'm still learning and I need to study more</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1464297,
          "author_name": "cdeotte",
          "author_url": "",
          "post_date": "08/10/2021 14:22:38",
          "content": "<p>Welcome to the exciting field of ML, DL and data analytics. Great job achieving LB mAP 614. This was a very difficult competition requiring very complicated models. If you can do this, you can do anything in the domain of image models!</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1464677,
          "author_name": "iftiben10",
          "author_url": "",
          "post_date": "08/10/2021 16:59:10",
          "content": "<p>Thank you, <a href=\"https://www.kaggle.com/cdeotte\" target=\"_blank\">@cdeotte</a> sir, for your motivation,<br>\nI'm actually a class 7 student and I'm also a lover of machine learning 😄,<br>\nI wish there would always be a kaggler like you</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1466814,
      "author_name": "hareeshdevababhittam",
      "author_url": "",
      "post_date": "08/11/2021 16:34:23",
      "content": "<p>Good work i got idea from this info.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1466951,
      "author_name": "dskswu",
      "author_url": "",
      "post_date": "08/11/2021 17:42:16",
      "content": "<p>Great job! Thank you for sharing your baseline kernel. It was very helpful. Good luck to you in future competitions. </p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1467312,
      "author_name": "tt195361",
      "author_url": "",
      "post_date": "08/11/2021 23:33:56",
      "content": "<p>Thank you very much for sharing this valuable information <a href=\"https://www.kaggle.com/cdeotte\" target=\"_blank\">@cdeotte</a>! I tried to run the model you explained in the notebook <a href=\"https://www.kaggle.com/tt195361/siim-covid-19-tf-study-level-model-with-aux-loss\" target=\"_blank\">here</a>. From the result, mean AUC of the 4 study classes is improved 0.0166! (with aux loss 0.5766, without 0.5600). It's great!</p>",
      "votes": null,
      "replies": [
        {
          "id": 1467446,
          "author_name": "cdeotte",
          "author_url": "",
          "post_date": "08/12/2021 01:50:01",
          "content": "<p>Fantastic work <a href=\"https://www.kaggle.com/tt195361\" target=\"_blank\">@tt195361</a> . Thanks for creating a notebook! Good job</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1467451,
          "author_name": "cdeotte",
          "author_url": "",
          "post_date": "08/12/2021 01:56:12",
          "content": "<p>I updated my post with a link to your wonderful notebook. Thank you.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1467935,
          "author_name": "tt195361",
          "author_url": "",
          "post_date": "08/12/2021 07:32:26",
          "content": "<p>Thank you so much <a href=\"https://www.kaggle.com/cdeotte\" target=\"_blank\">@cdeotte</a>!!!  It's unbelievably wonderful for me!!!</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1467327,
      "author_name": "iniestamoh",
      "author_url": "",
      "post_date": "08/11/2021 23:45:40",
      "content": "<p>I love your topics  😍</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1467400,
      "author_name": "haenara",
      "author_url": "",
      "post_date": "08/12/2021 00:59:37",
      "content": "<p>Thank you so much for sharing the aux loss. I've learned something :) </p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1462778": "# Silver Medal Model\nThe following model achieves **top 50 public LB 631**. My teammates @awsaf49 @zaber666 @nexh98 @artemenon have published our full team solution soon explaining how our team accomplished the amazing public LB 654 and private LB 631 and achieved 4th place Gold [here][4]\n\n# Easy Way to Add Aux Loss to Model\nMany people were asking in the forum how to add segmentation loss to a classification model. An easy trick is to instead add classification to a segmentation model 😄\n\n# GitHub Segmentation Models\nTo create a model that uses both classification targets and segmentation mask, first create a segmentation model, then add a classification head in the middle of the network. We can use @pavel92 great GitHub repository [here][1]. \n\n    import segmentation_models as sm\n\n    build_model():\n        base_model = sm.FPN(BACKBONE, encoder_weights='imagenet', \n           input_shape=(None, None, 3), classes=3, activation='sigmoid')\n    \n        x = base_model.get_layer(name='top_activation').output \n        x = tf.keras.layers.GlobalAveragePooling2D()(x)\n        x = tf.keras.layers.Dense(4, activation='sigmoid', name='out2')(x)\n            \n        model = tf.keras.Model(inputs=base_model.input, \n           outputs=[base_model.output,x]) \n    \n        opt = tf.keras.optimizers.Adam()\n        met1 = sm.metrics.iou_score\n        met2 = tf.keras.metrics.AUC(curve='PR',multi_label=True)\n        loss1 = sm.losses.bce_jaccard_loss\n        loss2 = tf.keras.losses.BinaryCrossentropy()\n        \n        model.compile(loss={'sigmoid':loss1,'out2':loss2}, \n                  loss_weights = [1.0,1.0], optimizer = opt,\n                  metrics={'sigmoid':met1, 'out2':met2}) \n        \n        return model\n\n# Data Loader\nWe then train with xray images, classification targets, and segmentation masks (created from train bbox). The targets above the segmentation masks below are `\"negative\", \"typical\", \"indeterminate\", \"atypical\"` respectively. Adding data augmentation and reduce learning rate on plateau improves training.\n\n![](https://raw.githubusercontent.com/cdeotte/Kaggle_Images/main/Aug-2021/seg_mask.png)\n\n# LB 0.631\nDuring inference, this model produces targets, \"negative\", \"typical\", \"indeterminate\", \"atypical\" and we discard the segmentation masks. If we train a few models with EffNetB2, B3, B4 backbones and a few image sizes 448, 512, 576 then using this model's \"negative\" target as \"none\" target achieve LB 0.535 without detection \"opacity\". Next add a strong Detection model (like VFNet, EffDet, or Yolo) for \"opacity\" and you have LB 0.631 silver medal model.\n\n(According to Heng's terminology in his study kit [here][2], the model described above achieves \"LB 0.455 (study only)\" with \"none 1 0 0 1 1\". Or \"LB 0.405 without none 1 0 0 1 1\")\n\n# Starter Notebook\nKaggle user @tt195361 created a starter notebook using this model [here][3]. Great work tt195361, thanks for posting!\n\n# Gold Medal Model\nMy teammates @awsaf49 @zaber666 @nexh98 @artemenon will describe how our team achieved a LB 0.654 Gold medal solution soon. Stay tuned!\n\n[1]: https://github.com/qubvel/segmentation_models\n[2]: https://www.kaggle.com/c/siim-covid19-detection/discussion/240233\n[3]: https://www.kaggle.com/tt195361/siim-covid-19-tf-study-level-model-with-aux-loss\n[4]: https://www.kaggle.com/c/siim-covid19-detection/discussion/264243",
    "1462814": "\"none\" target achieve LB 0.535 without detection \"opacity\". \n\nI am also using this (because my \"none\" classifier was performing worse). \n\nCode to convert \"negative to opacity\" , see  function:  def make_fake_opacity_prediction(df_image, df_study, df_meta)\n\nhttps://www.kaggle.com/hengck23/final-v-00-private-public-score-0-615-0-628?scriptVersionId=70933214\n\n----\n\n\nHere are some statics for some who wonder why:\n![https://i.ibb.co/QMcSywS/Selection-666.png](https://i.ibb.co/QMcSywS/Selection-666.png)\n\n\"none\" = 1-\"opacity\"\n\nall negative study are \"none\" images. about more than 96% of \"non\" images are negative study. \n\nalso, comparing negative, none and max opacity box:\n\n\n![https://i.ibb.co/YpqmTtH/Selection-667.png](https://i.ibb.co/YpqmTtH/Selection-667.png)",
    "1462877": "Congratulations! I look forward to reading your solutions.",
    "1463376": "Congrats! Great work.",
    "1463414": "Congratulations @cdeotte, I'm your big fan and I'm a beginner in kaggle,\nCan you tell me what is Aux Loss?",
    "1463794": "Aux Loss is auxiliary loss. It is adding an auxiliary (additional, i.e. mulit-task) target to your classification model.\n\nRegarding the 4 study labels, we are asked to predict 4 classification targets \"negative\", \"typical\", \"indeterminate\", \"atypical\". So all your classification model needs are 4 softmax or sigmoid outputs. However, we are also given train segmentation masks. So in addition to outputting what we need (4 classification targets), we can have our model have an extra head which predicts segmentation masks.\n\nDuring training, our model receives training (i.e. loss function) from how it does on both the 4 classification targets and how it does making segmentation masks. This helps it learn to produce better classification targets.\n\nFinally, during inference when our model predicts both 4 classification and segmentation mask. We discard the segmentation mask because we don't need them. And only submit the 4 classification targets to Kaggle.",
    "1463900": "Thanks a lot, @cdeotte sir for your detailed answer, \nAs I'm a beginner I'm confused about    what is segmentation masks and how it helps to learn models to produce better classification target?",
    "1463926": "Segmentation masks are the given bounding boxes converted into an image with rectangles. Below are segmentation masks beside their associated xray image. This is what we train our model with. \n\nFor example, we show our model the image. Above the masks are the classification targets, `['Negative for Pneumonia','Typical Appearance', 'Indeterminate Appearance', 'Atypical Appearance']`. The left xray is `Indeterminate` and the right xray is `Typical`. We will ask our model to predict these targets and predict the segmentation mask, i.e. the model will draw where the yellow and red rectangles are.\n\nBy requiring the model to locate the anomaly in addition to classifying it, the model will become smarter.\n\n![](https://storage.googleapis.com/kagglesdsdata/datasets/1509614/2514753/seg_mask.png?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=databundle-worker-v2%40kaggle-161607.iam.gserviceaccount.com%2F20210810%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20210810T113314Z&X-Goog-Expires=345599&X-Goog-SignedHeaders=host&X-Goog-Signature=56ee06946310cdfa38e4436bb0c3542eaef8284a09857aaab90cb1708452c1150e824d9db00eaad85535509d4491e07784c0f2f905c707641011ef969ece06eb5003079d5beb538e99a64b3bdf4ac8f4224b8cb1af114bd219b7a87cb6b0239dd14cc41bd5876dfd42185e3ca20bbfc234ce89fe57110a5db5cfde7da6b67a3852f8ffd65ca7fdd26aa5983d9e339b11290debec2af759667f6e10db7e8eb99a87af4e0fdd3df191f808339482d5c68c3052114fd681925345b9c1d6b32a03838a81f935dd8e2fe63a481cab86632a419d5f245a6065c7f5fbf7b0238858def4a2e807325b276a668817633f9ac56b54623e155603e2d805698efd61562e1ec8)",
    "1464287": "Thanks a lot, @cdeotte sir for your great answer😄,\nI'm still learning and I need to study more",
    "1464297": "Welcome to the exciting field of ML, DL and data analytics. Great job achieving LB mAP 614. This was a very difficult competition requiring very complicated models. If you can do this, you can do anything in the domain of image models!",
    "1464677": "Thank you, @cdeotte sir, for your motivation,\nI'm actually a class 7 student and I'm also a lover of machine learning 😄,\nI wish there would always be a kaggler like you",
    "1466814": "Good work i got idea from this info.",
    "1466951": "Great job! Thank you for sharing your baseline kernel. It was very helpful. Good luck to you in future competitions.",
    "1467312": "Thank you very much for sharing this valuable information @cdeotte! I tried to run the model you explained in the notebook [here](https://www.kaggle.com/tt195361/siim-covid-19-tf-study-level-model-with-aux-loss). From the result, mean AUC of the 4 study classes is improved 0.0166! (with aux loss 0.5766, without 0.5600). It's great!",
    "1467327": "I love your topics  😍",
    "1467400": "Thank you so much for sharing the aux loss. I've learned something :)",
    "1467446": "Fantastic work @tt195361 . Thanks for creating a notebook! Good job",
    "1467451": "I updated my post with a link to your wonderful notebook. Thank you.",
    "1467935": "Thank you so much @cdeotte!!!  It's unbelievably wonderful for me!!!"
  },
  "source": "meta"
}