{
  "id": 228374,
  "title": "Question about masks encodings",
  "url": "/competitions/hpa-single-cell-image-classification/discussion/228374",
  "author_name": "Antonio Reche",
  "post_date": "2021-03-24T12:22:48.062000",
  "votes": 1,
  "comment_count": 4,
  "views": 0,
  "content": "<p>Hello everyone!</p>\n<p>I have been reading several discussions and notebooks for this competition, and I have now a clear understanding of how to get the masks, what is the goal of the competition, and how the submission file should be. However, there is a matter with the cell masks and the encodings that I still don't fully understand and I haven't seen explained anywhere, so I was hoping you could help me with this 😁</p>\n<p>I will use an example to explain myself. Please, correct me if I am mistaken somewhere.</p>\n<p>Let's say, using a cell segmentation model, I have obtained the following mask for a given image in the set:<br>\n<img src=\"https://imgur.com/MV7Xnx6.png\" alt=\"\"><br>\nThis segmentation has 19 cells. Now, let's say my classification model is going to predict the label (or labels) for the cell marked as red:<br>\n<img src=\"https://i.imgur.com/P6db581.png\" alt=\"\"><br>\nSince it is an instance segmentation problem, I should separate each cell in a different mask and encode each one separately (there will be 19 different encodings for this image in the <code>PredictionString</code>), so for the red cell, I extract it in the following mask:<br>\n<img src=\"https://i.imgur.com/OlrsN2B.png\" alt=\"\"><br>\nMy  question is,  <strong>how is exactly the mask I need to encode for the submission? Like the one just above, or should I crop the cell mask?</strong> and obtain a mask like this one:<br>\n<img src=\"https://i.imgur.com/QbghqIN.png\" alt=\"\"></p>\n<p>And <strong>what is the size of the mask I need to encode? does it matter?</strong> For example, let's say I have an image of 4048x4048, but my model resizes the images to 400x400 and work with that size, so the obtained segmentation masks will have size 400x400. Do I need to resize the masks back to 4048x4048 before encoding, or can I keep my model's size? This is for the first case, but in the case I need to upload the cropped mask, what is the size I need for that mask? or it doesn't matter?</p>\n<p>Thank you very much for your help, much appreciated 🙂</p>",
  "messages": [
    {
      "id": 1251320,
      "postDate": "2021-03-24T17:11:30.340Z",
      "content": "<p>Agree with <a href=\"https://www.kaggle.com/novice03\" target=\"_blank\">novice03</a> that the mask must reference the original large image.  You would have needed to create that mask when you did the segmentation - so you already have the data - just need to encode it correctly.  </p>\n<p>There is a post or two about segmentation and the size of the images used - but I don't think you get very good segmentation unless you do the segmentation on the original image size.  Since we were not supplied with any ground truth for segmentation it's a bit difficult to run well measured experiments, I used the eye ball examination method in my experiments and found that smaller sizes than the original did not look correct (I only have used the HPA segmentation library).  If you decide to stick with 400x400 than as you noted you should probably resize back to original before encoding the mask.</p>\n<p><a href=\"https://www.kaggle.com/c/hpa-single-cell-image-classification/discussion/219305\" target=\"_blank\">https://www.kaggle.com/c/hpa-single-cell-image-classification/discussion/219305</a></p>",
      "rawMarkdown": "Agree with [novice03](https://www.kaggle.com/novice03) that the mask must reference the original large image.  You would have needed to create that mask when you did the segmentation - so you already have the data - just need to encode it correctly.  \n\nThere is a post or two about segmentation and the size of the images used - but I don't think you get very good segmentation unless you do the segmentation on the original image size.  Since we were not supplied with any ground truth for segmentation it's a bit difficult to run well measured experiments, I used the eye ball examination method in my experiments and found that smaller sizes than the original did not look correct (I only have used the HPA segmentation library).  If you decide to stick with 400x400 than as you noted you should probably resize back to original before encoding the mask.\n\nhttps://www.kaggle.com/c/hpa-single-cell-image-classification/discussion/219305\n\n",
      "votes": 1
    },
    {
      "id": 1251129,
      "postDate": "2021-03-24T14:03:20.773Z",
      "content": "<blockquote>\n  <p>The binary segmentation masks are run-length encoded (RLE), zlib compressed, and base64 encoded</p>\n</blockquote>\n<p>Check the <a href=\"https://www.kaggle.com/c/hpa-single-cell-image-classification/overview/evaluation\" target=\"_blank\">evaluation page</a> for more information on this. I think the mask has to be taken from the original image. You have to convert the binary mask for a cell (like the 3rd image from the top) to an encoded string. I don't think the encoding of the cropped binary mask of a cell (like the last image) will be equivalent to the binary mask of the original image (like the 3rd image).</p>",
      "rawMarkdown": "> The binary segmentation masks are run-length encoded (RLE), zlib compressed, and base64 encoded\n\nCheck the [evaluation page](https://www.kaggle.com/c/hpa-single-cell-image-classification/overview/evaluation) for more information on this. I think the mask has to be taken from the original image. You have to convert the binary mask for a cell (like the 3rd image from the top) to an encoded string. I don't think the encoding of the cropped binary mask of a cell (like the last image) will be equivalent to the binary mask of the original image (like the 3rd image).",
      "votes": 1
    },
    {
      "id": 1250998,
      "postDate": "2021-03-24T12:22:48.063Z",
      "content": "<p>Hello everyone!</p>\n<p>I have been reading several discussions and notebooks for this competition, and I have now a clear understanding of how to get the masks, what is the goal of the competition, and how the submission file should be. However, there is a matter with the cell masks and the encodings that I still don't fully understand and I haven't seen explained anywhere, so I was hoping you could help me with this 😁</p>\n<p>I will use an example to explain myself. Please, correct me if I am mistaken somewhere.</p>\n<p>Let's say, using a cell segmentation model, I have obtained the following mask for a given image in the set:<br>\n<img src=\"https://imgur.com/MV7Xnx6.png\" alt=\"\"><br>\nThis segmentation has 19 cells. Now, let's say my classification model is going to predict the label (or labels) for the cell marked as red:<br>\n<img src=\"https://i.imgur.com/P6db581.png\" alt=\"\"><br>\nSince it is an instance segmentation problem, I should separate each cell in a different mask and encode each one separately (there will be 19 different encodings for this image in the <code>PredictionString</code>), so for the red cell, I extract it in the following mask:<br>\n<img src=\"https://i.imgur.com/OlrsN2B.png\" alt=\"\"><br>\nMy  question is,  <strong>how is exactly the mask I need to encode for the submission? Like the one just above, or should I crop the cell mask?</strong> and obtain a mask like this one:<br>\n<img src=\"https://i.imgur.com/QbghqIN.png\" alt=\"\"></p>\n<p>And <strong>what is the size of the mask I need to encode? does it matter?</strong> For example, let's say I have an image of 4048x4048, but my model resizes the images to 400x400 and work with that size, so the obtained segmentation masks will have size 400x400. Do I need to resize the masks back to 4048x4048 before encoding, or can I keep my model's size? This is for the first case, but in the case I need to upload the cropped mask, what is the size I need for that mask? or it doesn't matter?</p>\n<p>Thank you very much for your help, much appreciated 🙂</p>",
      "rawMarkdown": "Hello everyone!\n\nI have been reading several discussions and notebooks for this competition, and I have now a clear understanding of how to get the masks, what is the goal of the competition, and how the submission file should be. However, there is a matter with the cell masks and the encodings that I still don't fully understand and I haven't seen explained anywhere, so I was hoping you could help me with this 😁\n\nI will use an example to explain myself. Please, correct me if I am mistaken somewhere.\n\nLet's say, using a cell segmentation model, I have obtained the following mask for a given image in the set:\n![](https://imgur.com/MV7Xnx6.png)\nThis segmentation has 19 cells. Now, let's say my classification model is going to predict the label (or labels) for the cell marked as red:\n![](https://i.imgur.com/P6db581.png)\nSince it is an instance segmentation problem, I should separate each cell in a different mask and encode each one separately (there will be 19 different encodings for this image in the `PredictionString`), so for the red cell, I extract it in the following mask:\n![](https://i.imgur.com/OlrsN2B.png)\nMy  question is,  **how is exactly the mask I need to encode for the submission? Like the one just above, or should I crop the cell mask?** and obtain a mask like this one:\n![](https://i.imgur.com/QbghqIN.png)\n\nAnd **what is the size of the mask I need to encode? does it matter?** For example, let's say I have an image of 4048x4048, but my model resizes the images to 400x400 and work with that size, so the obtained segmentation masks will have size 400x400. Do I need to resize the masks back to 4048x4048 before encoding, or can I keep my model's size? This is for the first case, but in the case I need to upload the cropped mask, what is the size I need for that mask? or it doesn't matter?\n\nThank you very much for your help, much appreciated 🙂",
      "votes": 1
    },
    {
      "id": 1251331,
      "postDate": "2021-03-24T17:27:41.330Z",
      "content": "<p>Thank you both <a href=\"https://www.kaggle.com/novice03\" target=\"_blank\">@novice03</a> and <a href=\"https://www.kaggle.com/pcjimmmy\" target=\"_blank\">@pcjimmmy</a> ! 😁 I thought that too, but I got confused seeing some code from some kagglers that cropped images to classify. And thanks for the extra info on segmentation sizes. I already did it with the original image size, but was thinking on building a model with smaller sizes. Thank you!</p>",
      "rawMarkdown": "Thank you both @novice03 and @pcjimmmy ! 😁 I thought that too, but I got confused seeing some code from some kagglers that cropped images to classify. And thanks for the extra info on segmentation sizes. I already did it with the original image size, but was thinking on building a model with smaller sizes. Thank you!",
      "replies": [
        {
          "id": 1251793,
          "postDate": "2021-03-25T06:17:12.713Z",
          "content": "<p>My current model is using 299x299 image size for training and prediction - starting with 512x512 single cell images I created for the training.  So your model can still be any size as the segmentation process can be a pre-training creation of single cell images to any desired size.  It's just my experience that the segmentation looked better when performed on the full size initial image.  </p>",
          "rawMarkdown": "My current model is using 299x299 image size for training and prediction - starting with 512x512 single cell images I created for the training.  So your model can still be any size as the segmentation process can be a pre-training creation of single cell images to any desired size.  It's just my experience that the segmentation looked better when performed on the full size initial image.  "
        }
      ]
    }
  ],
  "comments": [
    {
      "id": 1251320,
      "author_name": "PC Jimmmy",
      "author_url": "",
      "post_date": "2021-03-24T17:11:30.340000",
      "content": "<p>Agree with <a href=\"https://www.kaggle.com/novice03\" target=\"_blank\">novice03</a> that the mask must reference the original large image.  You would have needed to create that mask when you did the segmentation - so you already have the data - just need to encode it correctly.  </p>\n<p>There is a post or two about segmentation and the size of the images used - but I don't think you get very good segmentation unless you do the segmentation on the original image size.  Since we were not supplied with any ground truth for segmentation it's a bit difficult to run well measured experiments, I used the eye ball examination method in my experiments and found that smaller sizes than the original did not look correct (I only have used the HPA segmentation library).  If you decide to stick with 400x400 than as you noted you should probably resize back to original before encoding the mask.</p>\n<p><a href=\"https://www.kaggle.com/c/hpa-single-cell-image-classification/discussion/219305\" target=\"_blank\">https://www.kaggle.com/c/hpa-single-cell-image-classification/discussion/219305</a></p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 1251129,
      "author_name": "novice03",
      "author_url": "",
      "post_date": "2021-03-24T14:03:20.773000",
      "content": "<blockquote>\n  <p>The binary segmentation masks are run-length encoded (RLE), zlib compressed, and base64 encoded</p>\n</blockquote>\n<p>Check the <a href=\"https://www.kaggle.com/c/hpa-single-cell-image-classification/overview/evaluation\" target=\"_blank\">evaluation page</a> for more information on this. I think the mask has to be taken from the original image. You have to convert the binary mask for a cell (like the 3rd image from the top) to an encoded string. I don't think the encoding of the cropped binary mask of a cell (like the last image) will be equivalent to the binary mask of the original image (like the 3rd image).</p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 1251331,
      "author_name": "Antonio Reche",
      "author_url": "",
      "post_date": "2021-03-24T17:27:41.330000",
      "content": "<p>Thank you both <a href=\"https://www.kaggle.com/novice03\" target=\"_blank\">@novice03</a> and <a href=\"https://www.kaggle.com/pcjimmmy\" target=\"_blank\">@pcjimmmy</a> ! 😁 I thought that too, but I got confused seeing some code from some kagglers that cropped images to classify. And thanks for the extra info on segmentation sizes. I already did it with the original image size, but was thinking on building a model with smaller sizes. Thank you!</p>",
      "votes": 0,
      "replies": [
        {
          "id": 1251793,
          "author_name": "PC Jimmmy",
          "author_url": "",
          "post_date": "2021-03-25T06:17:12.713000",
          "content": "<p>My current model is using 299x299 image size for training and prediction - starting with 512x512 single cell images I created for the training.  So your model can still be any size as the segmentation process can be a pre-training creation of single cell images to any desired size.  It's just my experience that the segmentation looked better when performed on the full size initial image.  </p>",
          "votes": 0,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1251320": "Agree with [novice03](https://www.kaggle.com/novice03) that the mask must reference the original large image.  You would have needed to create that mask when you did the segmentation - so you already have the data - just need to encode it correctly.  \n\nThere is a post or two about segmentation and the size of the images used - but I don't think you get very good segmentation unless you do the segmentation on the original image size.  Since we were not supplied with any ground truth for segmentation it's a bit difficult to run well measured experiments, I used the eye ball examination method in my experiments and found that smaller sizes than the original did not look correct (I only have used the HPA segmentation library).  If you decide to stick with 400x400 than as you noted you should probably resize back to original before encoding the mask.\n\nhttps://www.kaggle.com/c/hpa-single-cell-image-classification/discussion/219305\n\n",
    "1251129": "> The binary segmentation masks are run-length encoded (RLE), zlib compressed, and base64 encoded\n\nCheck the [evaluation page](https://www.kaggle.com/c/hpa-single-cell-image-classification/overview/evaluation) for more information on this. I think the mask has to be taken from the original image. You have to convert the binary mask for a cell (like the 3rd image from the top) to an encoded string. I don't think the encoding of the cropped binary mask of a cell (like the last image) will be equivalent to the binary mask of the original image (like the 3rd image).",
    "1250998": "Hello everyone!\n\nI have been reading several discussions and notebooks for this competition, and I have now a clear understanding of how to get the masks, what is the goal of the competition, and how the submission file should be. However, there is a matter with the cell masks and the encodings that I still don't fully understand and I haven't seen explained anywhere, so I was hoping you could help me with this 😁\n\nI will use an example to explain myself. Please, correct me if I am mistaken somewhere.\n\nLet's say, using a cell segmentation model, I have obtained the following mask for a given image in the set:\n![](https://imgur.com/MV7Xnx6.png)\nThis segmentation has 19 cells. Now, let's say my classification model is going to predict the label (or labels) for the cell marked as red:\n![](https://i.imgur.com/P6db581.png)\nSince it is an instance segmentation problem, I should separate each cell in a different mask and encode each one separately (there will be 19 different encodings for this image in the `PredictionString`), so for the red cell, I extract it in the following mask:\n![](https://i.imgur.com/OlrsN2B.png)\nMy  question is,  **how is exactly the mask I need to encode for the submission? Like the one just above, or should I crop the cell mask?** and obtain a mask like this one:\n![](https://i.imgur.com/QbghqIN.png)\n\nAnd **what is the size of the mask I need to encode? does it matter?** For example, let's say I have an image of 4048x4048, but my model resizes the images to 400x400 and work with that size, so the obtained segmentation masks will have size 400x400. Do I need to resize the masks back to 4048x4048 before encoding, or can I keep my model's size? This is for the first case, but in the case I need to upload the cropped mask, what is the size I need for that mask? or it doesn't matter?\n\nThank you very much for your help, much appreciated 🙂",
    "1251331": "Thank you both @novice03 and @pcjimmmy ! 😁 I thought that too, but I got confused seeing some code from some kagglers that cropped images to classify. And thanks for the extra info on segmentation sizes. I already did it with the original image size, but was thinking on building a model with smaller sizes. Thank you!"
  }
}