{
  "id": 238401,
  "title": "24th place (private) solution - Single model approach",
  "url": "/competitions/hpa-single-cell-image-classification/discussion/238401",
  "author_name": "Shai",
  "post_date": "2021-05-12T05:58:28.697000",
  "votes": 32,
  "comment_count": 14,
  "views": 0,
  "content": "<p>In this competition, multiple different approaches like cell level classification or image level heat-map prediction both seemed possible. During the early phase of the competition, I tried detection models (mmdetection and yolo) using the raw image level labels. But failed get a good score. This made me assume that image level labels are far to represent labels for each cell.</p>\n<p>Moving forward, I wanted to try CAM based models. Puzzle-CAM paper and their implementation was easy to follow. My final model was based on Puzzle-CAM without much modification of training schema or model architecture.</p>\n<h1>Hyperparameters</h1>\n<p><strong>Augmentation:</strong><br>\nRandom crop of ~80% of input image size<br>\nRandom flip/transpose<br>\nRandom brightness/contrast<br>\nRandom cutout<br>\n<strong>Optimizer:</strong> AdamW<br>\n<strong>Epoch:</strong> 10<br>\n<strong>Loss:</strong> Multilabel soft-margin loss for classification + L1 loss for reconstruction<br>\n<strong>Learning rate:</strong> linearly decreasing from 1e-4 to 1e-6</p>\n<h1>Inference</h1>\n<p>Probability for each cell was calculated by multiplying image level probability with normalized CAM logits. Sliding window was used to predict on input image.<br>\nTTA: 2 times flip and 3 scales (0.75, 1.00, 1.50)</p>\n<h1>Ablation study</h1>\n<p>Model: Densenet121 <br>\nInput resolution: 800x800 -&gt; 512x512 crop<br>\nDataset: Only competition <br>\nLB: 0.457 (public)<br>\nDataset: Competition + External data <br>\nLB: 0.481 (public)<br>\nInput resolution: 1280x1280 -&gt; 1024x1024 crop<br>\nLB: 0.503(public)</p>\n<p>Model: Xception<br>\nLB: 0.527(public)<br>\nLB: 0.495(private)</p>\n<p>I have tried cell level classifier by cropping individual cells and training with the labels found from CAM model. But the labels were still noisy and didn't produce better results than CAM models. So cell level models were not used in the final solution.</p>\n<p>I have also tried to ensemble CAM based models. Trained Densenet121, Resnest50 and Xception models (each single fold). Xception performed better than others and ensemble provided a little gain. So decided to go with single model (xception) and TTA.</p>\n<p>I did experiment with a few loss functions. Focal Loss, Asymmetric Loss For Multi-Label Classification and Sharpness-Aware Minimization are some of them. They are all good fit for this problem, but probably needed more hyperparameter tuning.</p>\n<p>Inference code: <a href=\"https://www.kaggle.com/sgalib/0-495-private-single-model-puzzlecam\" target=\"_blank\">Xception-0.495 private</a></p>\n<p>Thanks for reading!</p>",
  "messages": [
    {
      "id": 1303540,
      "postDate": "2021-05-12T05:58:28.697Z",
      "content": "<p>In this competition, multiple different approaches like cell level classification or image level heat-map prediction both seemed possible. During the early phase of the competition, I tried detection models (mmdetection and yolo) using the raw image level labels. But failed get a good score. This made me assume that image level labels are far to represent labels for each cell.</p>\n<p>Moving forward, I wanted to try CAM based models. Puzzle-CAM paper and their implementation was easy to follow. My final model was based on Puzzle-CAM without much modification of training schema or model architecture.</p>\n<h1>Hyperparameters</h1>\n<p><strong>Augmentation:</strong><br>\nRandom crop of ~80% of input image size<br>\nRandom flip/transpose<br>\nRandom brightness/contrast<br>\nRandom cutout<br>\n<strong>Optimizer:</strong> AdamW<br>\n<strong>Epoch:</strong> 10<br>\n<strong>Loss:</strong> Multilabel soft-margin loss for classification + L1 loss for reconstruction<br>\n<strong>Learning rate:</strong> linearly decreasing from 1e-4 to 1e-6</p>\n<h1>Inference</h1>\n<p>Probability for each cell was calculated by multiplying image level probability with normalized CAM logits. Sliding window was used to predict on input image.<br>\nTTA: 2 times flip and 3 scales (0.75, 1.00, 1.50)</p>\n<h1>Ablation study</h1>\n<p>Model: Densenet121 <br>\nInput resolution: 800x800 -&gt; 512x512 crop<br>\nDataset: Only competition <br>\nLB: 0.457 (public)<br>\nDataset: Competition + External data <br>\nLB: 0.481 (public)<br>\nInput resolution: 1280x1280 -&gt; 1024x1024 crop<br>\nLB: 0.503(public)</p>\n<p>Model: Xception<br>\nLB: 0.527(public)<br>\nLB: 0.495(private)</p>\n<p>I have tried cell level classifier by cropping individual cells and training with the labels found from CAM model. But the labels were still noisy and didn't produce better results than CAM models. So cell level models were not used in the final solution.</p>\n<p>I have also tried to ensemble CAM based models. Trained Densenet121, Resnest50 and Xception models (each single fold). Xception performed better than others and ensemble provided a little gain. So decided to go with single model (xception) and TTA.</p>\n<p>I did experiment with a few loss functions. Focal Loss, Asymmetric Loss For Multi-Label Classification and Sharpness-Aware Minimization are some of them. They are all good fit for this problem, but probably needed more hyperparameter tuning.</p>\n<p>Inference code: <a href=\"https://www.kaggle.com/sgalib/0-495-private-single-model-puzzlecam\" target=\"_blank\">Xception-0.495 private</a></p>\n<p>Thanks for reading!</p>",
      "rawMarkdown": "In this competition, multiple different approaches like cell level classification or image level heat-map prediction both seemed possible. During the early phase of the competition, I tried detection models (mmdetection and yolo) using the raw image level labels. But failed get a good score. This made me assume that image level labels are far to represent labels for each cell.\n\nMoving forward, I wanted to try CAM based models. Puzzle-CAM paper and their implementation was easy to follow. My final model was based on Puzzle-CAM without much modification of training schema or model architecture.\n\n#  Hyperparameters\n**Augmentation:**\nRandom crop of ~80% of input image size\nRandom flip/transpose\nRandom brightness/contrast\nRandom cutout\n**Optimizer:** AdamW\n**Epoch:** 10\n**Loss:** Multilabel soft-margin loss for classification + L1 loss for reconstruction\n**Learning rate:** linearly decreasing from 1e-4 to 1e-6\n\n# Inference\nProbability for each cell was calculated by multiplying image level probability with normalized CAM logits. Sliding window was used to predict on input image.\nTTA: 2 times flip and 3 scales (0.75, 1.00, 1.50)\n\n# Ablation study\nModel: Densenet121 \nInput resolution: 800x800 -> 512x512 crop\nDataset: Only competition \nLB: 0.457 (public)\nDataset: Competition + External data \nLB: 0.481 (public)\nInput resolution: 1280x1280 -> 1024x1024 crop\nLB: 0.503(public)\n\nModel: Xception\nLB: 0.527(public)\nLB: 0.495(private)\n\n\nI have tried cell level classifier by cropping individual cells and training with the labels found from CAM model. But the labels were still noisy and didn't produce better results than CAM models. So cell level models were not used in the final solution.\n\nI have also tried to ensemble CAM based models. Trained Densenet121, Resnest50 and Xception models (each single fold). Xception performed better than others and ensemble provided a little gain. So decided to go with single model (xception) and TTA.\n\nI did experiment with a few loss functions. Focal Loss, Asymmetric Loss For Multi-Label Classification and Sharpness-Aware Minimization are some of them. They are all good fit for this problem, but probably needed more hyperparameter tuning.\n\nInference code: [Xception-0.495 private](https://www.kaggle.com/sgalib/0-495-private-single-model-puzzlecam)\n\nThanks for reading!\n",
      "votes": 32
    },
    {
      "id": 1305036,
      "postDate": "2021-05-13T04:30:43.833Z",
      "content": "<p><a href=\"https://www.kaggle.com/sgalib\" target=\"_blank\">@sgalib</a> Congratulations on Solo Medal and thanks for sharing the approach </p>",
      "rawMarkdown": "@sgalib Congratulations on Solo Medal and thanks for sharing the approach ",
      "votes": 1,
      "replies": [
        {
          "id": 1305836,
          "postDate": "2021-05-13T13:57:55.113Z",
          "content": "<p>You are most welcome! I appreciate your contribution to the community. Thanks!</p>",
          "rawMarkdown": "You are most welcome! I appreciate your contribution to the community. Thanks!"
        }
      ]
    },
    {
      "id": 1304820,
      "postDate": "2021-05-12T22:59:39.270Z",
      "content": "<p>Congrats <a href=\"https://www.kaggle.com/sgalib\" target=\"_blank\">@sgalib</a> achieving strong solo finish!</p>",
      "rawMarkdown": "Congrats @sgalib achieving strong solo finish!",
      "votes": 1,
      "replies": [
        {
          "id": 1304966,
          "postDate": "2021-05-13T03:22:03.323Z",
          "content": "<p>You are most welcome <a href=\"https://www.kaggle.com/cdeotte\" target=\"_blank\">@cdeotte</a> !! Your solo gold in shopee is yet another display of your sorcery 😉. Congrats for that!</p>",
          "rawMarkdown": "You are most welcome @cdeotte !! Your solo gold in shopee is yet another display of your sorcery 😉. Congrats for that!",
          "votes": 1
        }
      ]
    },
    {
      "id": 1304597,
      "postDate": "2021-05-12T18:15:54.933Z",
      "content": "<p>Thank <a href=\"https://www.kaggle.com/sgalib\" target=\"_blank\">@sgalib</a> for your sharings and Congrats ! </p>",
      "rawMarkdown": "Thank @sgalib for your sharings and Congrats ! ",
      "votes": 1,
      "replies": [
        {
          "id": 1304725,
          "postDate": "2021-05-12T20:04:25.100Z",
          "content": "<p>You are most welcome <a href=\"https://www.kaggle.com/mathurinache\" target=\"_blank\">@mathurinache</a> ! Someone forgot to predict on private! 😬😬</p>",
          "rawMarkdown": "You are most welcome @mathurinache ! Someone forgot to predict on private! 😬😬"
        }
      ]
    },
    {
      "id": 1304180,
      "postDate": "2021-05-12T13:23:56.850Z",
      "content": "<p>Thank you for the write-up! And congrats!</p>",
      "rawMarkdown": "Thank you for the write-up! And congrats!",
      "votes": 1,
      "replies": [
        {
          "id": 1304314,
          "postDate": "2021-05-12T14:50:39.567Z",
          "content": "<p>Thanks and congrats to you too!</p>",
          "rawMarkdown": "Thanks and congrats to you too!"
        }
      ]
    },
    {
      "id": 1304145,
      "postDate": "2021-05-12T12:56:43.957Z",
      "content": "<p>Congrats &amp; thanks for sharing!</p>",
      "rawMarkdown": "Congrats & thanks for sharing!",
      "votes": 1,
      "replies": [
        {
          "id": 1304316,
          "postDate": "2021-05-12T14:51:25.420Z",
          "content": "<p>Thanks and congratulations on your gold!</p>",
          "rawMarkdown": "Thanks and congratulations on your gold!"
        }
      ]
    },
    {
      "id": 1303557,
      "postDate": "2021-05-12T06:16:05.183Z",
      "content": "<p>Hi , congrats! Could you please share your code for training and inference? I tried my way with PuzzleCAM , but didn't manage to get it working for me. </p>",
      "rawMarkdown": "Hi , congrats! Could you please share your code for training and inference? I tried my way with PuzzleCAM , but didn't manage to get it working for me. ",
      "votes": 2,
      "replies": [
        {
          "id": 1304321,
          "postDate": "2021-05-12T14:54:07.430Z",
          "content": "<p>I will try to share the code soon. It's a simple code. Training is mostly plug and play puzzle CAM. But the inference has a few lines more!</p>",
          "rawMarkdown": "I will try to share the code soon. It's a simple code. Training is mostly plug and play puzzle CAM. But the inference has a few lines more!",
          "votes": 2
        },
        {
          "id": 1304347,
          "postDate": "2021-05-12T15:07:19.277Z",
          "content": "<p>Sure ,thanks a lot!</p>",
          "rawMarkdown": "Sure ,thanks a lot!",
          "votes": 1
        },
        {
          "id": 1305834,
          "postDate": "2021-05-13T13:54:10.133Z",
          "content": "<p>I have uploaded a cleaned version of the inference <a href=\"https://www.kaggle.com/sgalib/0-495-private-single-model-puzzlecam\" target=\"_blank\">code</a>. Training code may take a little more time. Thanks!</p>",
          "rawMarkdown": "I have uploaded a cleaned version of the inference [code](https://www.kaggle.com/sgalib/0-495-private-single-model-puzzlecam). Training code may take a little more time. Thanks!",
          "votes": 1
        }
      ]
    }
  ],
  "comments": [
    {
      "id": 1305036,
      "author_name": "Tensor Girl",
      "author_url": "",
      "post_date": "2021-05-13T04:30:43.833000",
      "content": "<p><a href=\"https://www.kaggle.com/sgalib\" target=\"_blank\">@sgalib</a> Congratulations on Solo Medal and thanks for sharing the approach </p>",
      "votes": 1,
      "replies": [
        {
          "id": 1305836,
          "author_name": "Shai",
          "author_url": "",
          "post_date": "2021-05-13T13:57:55.113000",
          "content": "<p>You are most welcome! I appreciate your contribution to the community. Thanks!</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 1304820,
      "author_name": "Chris Deotte",
      "author_url": "",
      "post_date": "2021-05-12T22:59:39.270000",
      "content": "<p>Congrats <a href=\"https://www.kaggle.com/sgalib\" target=\"_blank\">@sgalib</a> achieving strong solo finish!</p>",
      "votes": 1,
      "replies": [
        {
          "id": 1304966,
          "author_name": "Shai",
          "author_url": "",
          "post_date": "2021-05-13T03:22:03.323000",
          "content": "<p>You are most welcome <a href=\"https://www.kaggle.com/cdeotte\" target=\"_blank\">@cdeotte</a> !! Your solo gold in shopee is yet another display of your sorcery 😉. Congrats for that!</p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 1304597,
      "author_name": "Mathurin Ache",
      "author_url": "",
      "post_date": "2021-05-12T18:15:54.933000",
      "content": "<p>Thank <a href=\"https://www.kaggle.com/sgalib\" target=\"_blank\">@sgalib</a> for your sharings and Congrats ! </p>",
      "votes": 1,
      "replies": [
        {
          "id": 1304725,
          "author_name": "Shai",
          "author_url": "",
          "post_date": "2021-05-12T20:04:25.100000",
          "content": "<p>You are most welcome <a href=\"https://www.kaggle.com/mathurinache\" target=\"_blank\">@mathurinache</a> ! Someone forgot to predict on private! 😬😬</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 1304180,
      "author_name": "Raman",
      "author_url": "",
      "post_date": "2021-05-12T13:23:56.850000",
      "content": "<p>Thank you for the write-up! And congrats!</p>",
      "votes": 1,
      "replies": [
        {
          "id": 1304314,
          "author_name": "Shai",
          "author_url": "",
          "post_date": "2021-05-12T14:50:39.567000",
          "content": "<p>Thanks and congrats to you too!</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 1304145,
      "author_name": "corochann",
      "author_url": "",
      "post_date": "2021-05-12T12:56:43.957000",
      "content": "<p>Congrats &amp; thanks for sharing!</p>",
      "votes": 1,
      "replies": [
        {
          "id": 1304316,
          "author_name": "Shai",
          "author_url": "",
          "post_date": "2021-05-12T14:51:25.420000",
          "content": "<p>Thanks and congratulations on your gold!</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 1303557,
      "author_name": "Satwik",
      "author_url": "",
      "post_date": "2021-05-12T06:16:05.183000",
      "content": "<p>Hi , congrats! Could you please share your code for training and inference? I tried my way with PuzzleCAM , but didn't manage to get it working for me. </p>",
      "votes": 2,
      "replies": [
        {
          "id": 1304321,
          "author_name": "Shai",
          "author_url": "",
          "post_date": "2021-05-12T14:54:07.430000",
          "content": "<p>I will try to share the code soon. It's a simple code. Training is mostly plug and play puzzle CAM. But the inference has a few lines more!</p>",
          "votes": 2,
          "replies": []
        },
        {
          "id": 1304347,
          "author_name": "Satwik",
          "author_url": "",
          "post_date": "2021-05-12T15:07:19.277000",
          "content": "<p>Sure ,thanks a lot!</p>",
          "votes": 1,
          "replies": []
        },
        {
          "id": 1305834,
          "author_name": "Shai",
          "author_url": "",
          "post_date": "2021-05-13T13:54:10.133000",
          "content": "<p>I have uploaded a cleaned version of the inference <a href=\"https://www.kaggle.com/sgalib/0-495-private-single-model-puzzlecam\" target=\"_blank\">code</a>. Training code may take a little more time. Thanks!</p>",
          "votes": 1,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1303540": "In this competition, multiple different approaches like cell level classification or image level heat-map prediction both seemed possible. During the early phase of the competition, I tried detection models (mmdetection and yolo) using the raw image level labels. But failed get a good score. This made me assume that image level labels are far to represent labels for each cell.\n\nMoving forward, I wanted to try CAM based models. Puzzle-CAM paper and their implementation was easy to follow. My final model was based on Puzzle-CAM without much modification of training schema or model architecture.\n\n#  Hyperparameters\n**Augmentation:**\nRandom crop of ~80% of input image size\nRandom flip/transpose\nRandom brightness/contrast\nRandom cutout\n**Optimizer:** AdamW\n**Epoch:** 10\n**Loss:** Multilabel soft-margin loss for classification + L1 loss for reconstruction\n**Learning rate:** linearly decreasing from 1e-4 to 1e-6\n\n# Inference\nProbability for each cell was calculated by multiplying image level probability with normalized CAM logits. Sliding window was used to predict on input image.\nTTA: 2 times flip and 3 scales (0.75, 1.00, 1.50)\n\n# Ablation study\nModel: Densenet121 \nInput resolution: 800x800 -> 512x512 crop\nDataset: Only competition \nLB: 0.457 (public)\nDataset: Competition + External data \nLB: 0.481 (public)\nInput resolution: 1280x1280 -> 1024x1024 crop\nLB: 0.503(public)\n\nModel: Xception\nLB: 0.527(public)\nLB: 0.495(private)\n\n\nI have tried cell level classifier by cropping individual cells and training with the labels found from CAM model. But the labels were still noisy and didn't produce better results than CAM models. So cell level models were not used in the final solution.\n\nI have also tried to ensemble CAM based models. Trained Densenet121, Resnest50 and Xception models (each single fold). Xception performed better than others and ensemble provided a little gain. So decided to go with single model (xception) and TTA.\n\nI did experiment with a few loss functions. Focal Loss, Asymmetric Loss For Multi-Label Classification and Sharpness-Aware Minimization are some of them. They are all good fit for this problem, but probably needed more hyperparameter tuning.\n\nInference code: [Xception-0.495 private](https://www.kaggle.com/sgalib/0-495-private-single-model-puzzlecam)\n\nThanks for reading!\n",
    "1305036": "@sgalib Congratulations on Solo Medal and thanks for sharing the approach ",
    "1304820": "Congrats @sgalib achieving strong solo finish!",
    "1304597": "Thank @sgalib for your sharings and Congrats ! ",
    "1304180": "Thank you for the write-up! And congrats!",
    "1304145": "Congrats & thanks for sharing!",
    "1303557": "Hi , congrats! Could you please share your code for training and inference? I tried my way with PuzzleCAM , but didn't manage to get it working for me. "
  }
}