{
  "id": 110998,
  "title": "117th place solution [0.718] using PyTorch & fastai",
  "url": "/competitions/recursion-cellular-image-classification/writeups/first-team-117th-place-solution-0-718-using-pytorc",
  "author_name": "",
  "post_date": "2019-10-18T19:15:35.120Z",
  "votes": 1,
  "comment_count": 2,
  "views": 0,
  "content": "<p><em>A big thank you goes out to the competition organizers and they great community!</em></p>\n\n<p><em>This was my first kaggle competition I joined from the beginning and I learned a lot! :-D</em></p>\n\n<p><strong>Final setup for highest score:</strong>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F1686473%2F0b3b7757f33b40bd54f75953d3d49659%2Frcic_network.png?generation=1570045807295295&amp;alt=media\" alt=\"\">\n- <a href=\"https://github.com/lukemelas/EfficientNet-PyTorch\">ImageNet-pretained EfficientNet-B3</a> with 6D input stage (2x 3D weights copied to get 6D input stage at the beginning of training).\n- <a href=\"https://arxiv.org/abs/1905.00292\">AdaCos metric learning approach</a> was implemented, which should be more stable without hyperparameter tuning when compared to other cosine-based softmax losses.\n- Standard data augmentation (flip vertical/horizontal, rotation, zoom, lighting, warp) with custom implementation of <a href=\"https://arxiv.org/abs/1707.06183\">„Color Augmentation for histopathology images”</a>. Data visualization function displaying the 6D images as 3D+3D image:\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F1686473%2F83c27c07dc7a61366fe8bc1a9f3bfbbe%2Frcic_data.png?generation=1570045826942943&amp;alt=media\" alt=\"\">\n- Embedding layers for meta data to let the model learn from celltype, plategroup, and experiment data (i.e., data leak). (However, there was no time in the end to optimize the embeddings used for the full training and test predictions. Something like a similarity search for the test experiments would have been an interesting approach.)\n- <a href=\"https://github.com/oguiza/fastai_extensions/tree/master/shared/0_image_data_augmentation\">CutMix</a> was used for the image data for some parts of the training. In addition, a linear interpolation of the embeddings was used during CutMix training.\n- Predictions were carried out with 3x TTA to obtain the feature embeddings of the image and meta data input.\n- Finally, <a href=\"https://github.com/facebookresearch/faiss\">FAISS</a> was used for cosine similarity search of the extracted feature embeddings.</p>\n\n<p><strong>General training setup:</strong>\n1. Train new network output stage/head with frozen pretrained feature extractor network.\n1. Retrain pretrained extractor network with new head (approx. 60 epochs).\n1. Add meta data embeddings, freeze feature extractor network and train embeddings and output stage (approx. 50 epochs).\n1. Train entire network (approx. 150 epochs).</p>\n\n<p>For all training stages the <a href=\"https://sgugger.github.io/the-1cycle-policy.html\">1cycle policy</a> was used for several cycles. EfficientNet training was carried out with AdamW. CutMix was used for the late training stages.</p>\n\n<p><strong><a href=\"https://github.com/MicPie/recursion-cellular-image-classification/blob/master/README.md\">Notebooks from the GitHub repo</a>:</strong>\n- EfficientNet-B3 training:\n  - <a href=\"https://github.com/MicPie/recursion-cellular-image-classification/blob/master/rcic_v20_efficientnet-b3.ipynb\">Pretraining</a>\n  - <a href=\"https://github.com/MicPie/recursion-cellular-image-classification/blob/master/rcic_v32_efficientnet-b3_celltype_plate-group-exp_Full.ipynb\">Complex network</a>\n  - <a href=\"https://github.com/MicPie/recursion-cellular-image-classification/blob/master/rcic_v41_efficientnet-b3_celltype_plate-group-exp_12D.ipynb\">Complex network 12D</a> (2x 6 channel images)\n- EfficientNet-B4 (training not finished):\n  - <a href=\"https://github.com/MicPie/recursion-cellular-image-classification/blob/master/rcic_v43_efficientnet-b4_Mish_Ranger_LabelSmoothingLoss.ipynb\">Pretraining</a>\n  - <a href=\"https://github.com/MicPie/recursion-cellular-image-classification/blob/master/rcic_v44_efficientnet-b4_celltype_plate-group-exp_12D_model-exchange.ipynb\">Complex network 12D</a> (2x 6 channel images)</p>\n\n<p><strong>What didn’t work out or had no impact over a more basic setup:</strong>\n- Separate classifiers for celltypes and/or plategroups (i.e., siRNA groups of 277).\n- Some domain adaption techniques.\n- Mean or k-means clustering of siRNA feature embeddings for cosine similarity search.</p>\n\n<p><strong>Learnings:</strong>\n- A lot about PyTorch, fastai, and adjacent DL/ML topics.\n- Stay longer on the smaller model side, do more A/B or CV testing of improvements, then first really over-fit, and then try to reduce it.\n- EfficientNet-B3 retraining took forever and training of EfficientNet-B4 was not finished at the competition deadline (however, this looked very promising).</p>\n\n<p>If you have any questions or are interested in further information, please feel free to contact me! :-)</p>\n\n<p>Thank you very much!</p>",
  "messages": [
    {
      "id": "639139",
      "postDate": "10/02/2019 19:59:04",
      "content": "<p><em>A big thank you goes out to the competition organizers and they great community!</em></p>\n\n<p><em>This was my first kaggle competition I joined from the beginning and I learned a lot! :-D</em></p>\n\n<p><strong>Final setup for highest score:</strong>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F1686473%2F0b3b7757f33b40bd54f75953d3d49659%2Frcic_network.png?generation=1570045807295295&amp;alt=media\" alt=\"\">\n- <a href=\"https://github.com/lukemelas/EfficientNet-PyTorch\">ImageNet-pretained EfficientNet-B3</a> with 6D input stage (2x 3D weights copied to get 6D input stage at the beginning of training).\n- <a href=\"https://arxiv.org/abs/1905.00292\">AdaCos metric learning approach</a> was implemented, which should be more stable without hyperparameter tuning when compared to other cosine-based softmax losses.\n- Standard data augmentation (flip vertical/horizontal, rotation, zoom, lighting, warp) with custom implementation of <a href=\"https://arxiv.org/abs/1707.06183\">„Color Augmentation for histopathology images”</a>. Data visualization function displaying the 6D images as 3D+3D image:\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F1686473%2F83c27c07dc7a61366fe8bc1a9f3bfbbe%2Frcic_data.png?generation=1570045826942943&amp;alt=media\" alt=\"\">\n- Embedding layers for meta data to let the model learn from celltype, plategroup, and experiment data (i.e., data leak). (However, there was no time in the end to optimize the embeddings used for the full training and test predictions. Something like a similarity search for the test experiments would have been an interesting approach.)\n- <a href=\"https://github.com/oguiza/fastai_extensions/tree/master/shared/0_image_data_augmentation\">CutMix</a> was used for the image data for some parts of the training. In addition, a linear interpolation of the embeddings was used during CutMix training.\n- Predictions were carried out with 3x TTA to obtain the feature embeddings of the image and meta data input.\n- Finally, <a href=\"https://github.com/facebookresearch/faiss\">FAISS</a> was used for cosine similarity search of the extracted feature embeddings.</p>\n\n<p><strong>General training setup:</strong>\n1. Train new network output stage/head with frozen pretrained feature extractor network.\n1. Retrain pretrained extractor network with new head (approx. 60 epochs).\n1. Add meta data embeddings, freeze feature extractor network and train embeddings and output stage (approx. 50 epochs).\n1. Train entire network (approx. 150 epochs).</p>\n\n<p>For all training stages the <a href=\"https://sgugger.github.io/the-1cycle-policy.html\">1cycle policy</a> was used for several cycles. EfficientNet training was carried out with AdamW. CutMix was used for the late training stages.</p>\n\n<p><strong><a href=\"https://github.com/MicPie/recursion-cellular-image-classification/blob/master/README.md\">Notebooks from the GitHub repo</a>:</strong>\n- EfficientNet-B3 training:\n  - <a href=\"https://github.com/MicPie/recursion-cellular-image-classification/blob/master/rcic_v20_efficientnet-b3.ipynb\">Pretraining</a>\n  - <a href=\"https://github.com/MicPie/recursion-cellular-image-classification/blob/master/rcic_v32_efficientnet-b3_celltype_plate-group-exp_Full.ipynb\">Complex network</a>\n  - <a href=\"https://github.com/MicPie/recursion-cellular-image-classification/blob/master/rcic_v41_efficientnet-b3_celltype_plate-group-exp_12D.ipynb\">Complex network 12D</a> (2x 6 channel images)\n- EfficientNet-B4 (training not finished):\n  - <a href=\"https://github.com/MicPie/recursion-cellular-image-classification/blob/master/rcic_v43_efficientnet-b4_Mish_Ranger_LabelSmoothingLoss.ipynb\">Pretraining</a>\n  - <a href=\"https://github.com/MicPie/recursion-cellular-image-classification/blob/master/rcic_v44_efficientnet-b4_celltype_plate-group-exp_12D_model-exchange.ipynb\">Complex network 12D</a> (2x 6 channel images)</p>\n\n<p><strong>What didn’t work out or had no impact over a more basic setup:</strong>\n- Separate classifiers for celltypes and/or plategroups (i.e., siRNA groups of 277).\n- Some domain adaption techniques.\n- Mean or k-means clustering of siRNA feature embeddings for cosine similarity search.</p>\n\n<p><strong>Learnings:</strong>\n- A lot about PyTorch, fastai, and adjacent DL/ML topics.\n- Stay longer on the smaller model side, do more A/B or CV testing of improvements, then first really over-fit, and then try to reduce it.\n- EfficientNet-B3 retraining took forever and training of EfficientNet-B4 was not finished at the competition deadline (however, this looked very promising).</p>\n\n<p>If you have any questions or are interested in further information, please feel free to contact me! :-)</p>\n\n<p>Thank you very much!</p>",
      "rawMarkdown": "*A big thank you goes out to the competition organizers and they great community!*\n\n*This was my first kaggle competition I joined from the beginning and I learned a lot! :-D*\n\n**Final setup for highest score:**\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F1686473%2F0b3b7757f33b40bd54f75953d3d49659%2Frcic_network.png?generation=1570045807295295&amp;alt=media)\n- [ImageNet-pretained EfficientNet-B3](https://github.com/lukemelas/EfficientNet-PyTorch) with 6D input stage (2x 3D weights copied to get 6D input stage at the beginning of training).\n- [AdaCos metric learning approach](https://arxiv.org/abs/1905.00292) was implemented, which should be more stable without hyperparameter tuning when compared to other cosine-based softmax losses.\n- Standard data augmentation (flip vertical/horizontal, rotation, zoom, lighting, warp) with custom implementation of [„Color Augmentation for histopathology images”](https://arxiv.org/abs/1707.06183). Data visualization function displaying the 6D images as 3D+3D image:\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F1686473%2F83c27c07dc7a61366fe8bc1a9f3bfbbe%2Frcic_data.png?generation=1570045826942943&amp;alt=media)\n- Embedding layers for meta data to let the model learn from celltype, plategroup, and experiment data (i.e., data leak). (However, there was no time in the end to optimize the embeddings used for the full training and test predictions. Something like a similarity search for the test experiments would have been an interesting approach.)\n- [CutMix]( https://github.com/oguiza/fastai_extensions/tree/master/shared/0_image_data_augmentation) was used for the image data for some parts of the training. In addition, a linear interpolation of the embeddings was used during CutMix training.\n- Predictions were carried out with 3x TTA to obtain the feature embeddings of the image and meta data input.\n- Finally, [FAISS]( https://github.com/facebookresearch/faiss) was used for cosine similarity search of the extracted feature embeddings.\n\n**General training setup:**\n1. Train new network output stage/head with frozen pretrained feature extractor network.\n1. Retrain pretrained extractor network with new head (approx. 60 epochs).\n1. Add meta data embeddings, freeze feature extractor network and train embeddings and output stage (approx. 50 epochs).\n1. Train entire network (approx. 150 epochs).\n\nFor all training stages the [1cycle policy](https://sgugger.github.io/the-1cycle-policy.html) was used for several cycles. EfficientNet training was carried out with AdamW. CutMix was used for the late training stages.\n\n**[Notebooks from the GitHub repo](https://github.com/MicPie/recursion-cellular-image-classification/blob/master/README.md):**\n- EfficientNet-B3 training:\n  - [Pretraining](https://github.com/MicPie/recursion-cellular-image-classification/blob/master/rcic_v20_efficientnet-b3.ipynb)\n  - [Complex network](https://github.com/MicPie/recursion-cellular-image-classification/blob/master/rcic_v32_efficientnet-b3_celltype_plate-group-exp_Full.ipynb)\n  - [Complex network 12D](https://github.com/MicPie/recursion-cellular-image-classification/blob/master/rcic_v41_efficientnet-b3_celltype_plate-group-exp_12D.ipynb) (2x 6 channel images)\n- EfficientNet-B4 (training not finished):\n  - [Pretraining](https://github.com/MicPie/recursion-cellular-image-classification/blob/master/rcic_v43_efficientnet-b4_Mish_Ranger_LabelSmoothingLoss.ipynb)\n  - [Complex network 12D](https://github.com/MicPie/recursion-cellular-image-classification/blob/master/rcic_v44_efficientnet-b4_celltype_plate-group-exp_12D_model-exchange.ipynb) (2x 6 channel images)\n\n**What didn’t work out or had no impact over a more basic setup:**\n- Separate classifiers for celltypes and/or plategroups (i.e., siRNA groups of 277).\n- Some domain adaption techniques.\n- Mean or k-means clustering of siRNA feature embeddings for cosine similarity search.\n\n**Learnings:**\n- A lot about PyTorch, fastai, and adjacent DL/ML topics.\n- Stay longer on the smaller model side, do more A/B or CV testing of improvements, then first really over-fit, and then try to reduce it.\n- EfficientNet-B3 retraining took forever and training of EfficientNet-B4 was not finished at the competition deadline (however, this looked very promising).\n\nIf you have any questions or are interested in further information, please feel free to contact me! :-)\n\nThank you very much!",
      "votes": null
    },
    {
      "id": "639341",
      "postDate": "10/03/2019 05:11:16",
      "content": "<p>Congrats.....\nThank you for Sharing your Approach &amp; Insights.....!! <a href=\"/micpie\">@micpie</a> </p>",
      "rawMarkdown": "Congrats.....\nThank you for Sharing your Approach &amp; Insights.....!! @micpie",
      "votes": null
    },
    {
      "id": "786131",
      "postDate": "03/25/2020 16:42:10",
      "content": "<p>I hadn't thought of using the data from both sites to classify or embedding the additional information on the images. Thanks for sharing your approach!</p>",
      "rawMarkdown": "I hadn't thought of using the data from both sites to classify or embedding the additional information on the images. Thanks for sharing your approach!",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 639341,
      "author_name": "veeralakrishna",
      "author_url": "",
      "post_date": "10/03/2019 05:11:16",
      "content": "<p>Congrats.....\nThank you for Sharing your Approach &amp; Insights.....!! <a href=\"/micpie\">@micpie</a> </p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 786131,
      "author_name": "skylerg022",
      "author_url": "",
      "post_date": "03/25/2020 16:42:10",
      "content": "<p>I hadn't thought of using the data from both sites to classify or embedding the additional information on the images. Thanks for sharing your approach!</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "639139": "*A big thank you goes out to the competition organizers and they great community!*\n\n*This was my first kaggle competition I joined from the beginning and I learned a lot! :-D*\n\n**Final setup for highest score:**\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F1686473%2F0b3b7757f33b40bd54f75953d3d49659%2Frcic_network.png?generation=1570045807295295&amp;alt=media)\n- [ImageNet-pretained EfficientNet-B3](https://github.com/lukemelas/EfficientNet-PyTorch) with 6D input stage (2x 3D weights copied to get 6D input stage at the beginning of training).\n- [AdaCos metric learning approach](https://arxiv.org/abs/1905.00292) was implemented, which should be more stable without hyperparameter tuning when compared to other cosine-based softmax losses.\n- Standard data augmentation (flip vertical/horizontal, rotation, zoom, lighting, warp) with custom implementation of [„Color Augmentation for histopathology images”](https://arxiv.org/abs/1707.06183). Data visualization function displaying the 6D images as 3D+3D image:\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F1686473%2F83c27c07dc7a61366fe8bc1a9f3bfbbe%2Frcic_data.png?generation=1570045826942943&amp;alt=media)\n- Embedding layers for meta data to let the model learn from celltype, plategroup, and experiment data (i.e., data leak). (However, there was no time in the end to optimize the embeddings used for the full training and test predictions. Something like a similarity search for the test experiments would have been an interesting approach.)\n- [CutMix]( https://github.com/oguiza/fastai_extensions/tree/master/shared/0_image_data_augmentation) was used for the image data for some parts of the training. In addition, a linear interpolation of the embeddings was used during CutMix training.\n- Predictions were carried out with 3x TTA to obtain the feature embeddings of the image and meta data input.\n- Finally, [FAISS]( https://github.com/facebookresearch/faiss) was used for cosine similarity search of the extracted feature embeddings.\n\n**General training setup:**\n1. Train new network output stage/head with frozen pretrained feature extractor network.\n1. Retrain pretrained extractor network with new head (approx. 60 epochs).\n1. Add meta data embeddings, freeze feature extractor network and train embeddings and output stage (approx. 50 epochs).\n1. Train entire network (approx. 150 epochs).\n\nFor all training stages the [1cycle policy](https://sgugger.github.io/the-1cycle-policy.html) was used for several cycles. EfficientNet training was carried out with AdamW. CutMix was used for the late training stages.\n\n**[Notebooks from the GitHub repo](https://github.com/MicPie/recursion-cellular-image-classification/blob/master/README.md):**\n- EfficientNet-B3 training:\n  - [Pretraining](https://github.com/MicPie/recursion-cellular-image-classification/blob/master/rcic_v20_efficientnet-b3.ipynb)\n  - [Complex network](https://github.com/MicPie/recursion-cellular-image-classification/blob/master/rcic_v32_efficientnet-b3_celltype_plate-group-exp_Full.ipynb)\n  - [Complex network 12D](https://github.com/MicPie/recursion-cellular-image-classification/blob/master/rcic_v41_efficientnet-b3_celltype_plate-group-exp_12D.ipynb) (2x 6 channel images)\n- EfficientNet-B4 (training not finished):\n  - [Pretraining](https://github.com/MicPie/recursion-cellular-image-classification/blob/master/rcic_v43_efficientnet-b4_Mish_Ranger_LabelSmoothingLoss.ipynb)\n  - [Complex network 12D](https://github.com/MicPie/recursion-cellular-image-classification/blob/master/rcic_v44_efficientnet-b4_celltype_plate-group-exp_12D_model-exchange.ipynb) (2x 6 channel images)\n\n**What didn’t work out or had no impact over a more basic setup:**\n- Separate classifiers for celltypes and/or plategroups (i.e., siRNA groups of 277).\n- Some domain adaption techniques.\n- Mean or k-means clustering of siRNA feature embeddings for cosine similarity search.\n\n**Learnings:**\n- A lot about PyTorch, fastai, and adjacent DL/ML topics.\n- Stay longer on the smaller model side, do more A/B or CV testing of improvements, then first really over-fit, and then try to reduce it.\n- EfficientNet-B3 retraining took forever and training of EfficientNet-B4 was not finished at the competition deadline (however, this looked very promising).\n\nIf you have any questions or are interested in further information, please feel free to contact me! :-)\n\nThank you very much!",
    "639341": "Congrats.....\nThank you for Sharing your Approach &amp; Insights.....!! @micpie",
    "786131": "I hadn't thought of using the data from both sites to classify or embedding the additional information on the images. Thanks for sharing your approach!"
  },
  "source": "meta"
}