{
  "id": 572008,
  "title": "How do I create segmentation masks for unet?",
  "url": "/competitions/byu-locating-bacterial-flagellar-motors-2025/discussion/572008",
  "author_name": "",
  "post_date": "2025-04-07T05:30:33.025650500Z",
  "votes": 4,
  "comment_count": 8,
  "views": 0,
  "content": "<p>Hi, I'm currently trying to create masked targets for my unet2d model but I'm unsure how to shape the 3d masks<br>\nIn the previous czii competition, the main approach was to create a sphere around the target coordinates with the radius specified in the dataset.<br>\nEach voxel would be annotated with its corresponding class(hard label?).<br>\n(c.f. <a href=\"https://www.kaggle.com/code/fnands/create-numpy-dataset-exp-name\" target=\"_blank\">https://www.kaggle.com/code/fnands/create-numpy-dataset-exp-name</a>)<br>\nHowever, the motors in this competition seem to have an elongated shape and it doesn't feel right to set the target to a sphere.<br>\nShould I forget about said shape and hope the model learns with a conservative radius or is there a better way to approach this?<br>\nAlso, the czii 1st place solution(I think) mentioned using soft labels(3d gaussian centered at target coordinates).<br>\nIn this approach, it feels like it would have to be obvious from the models point of view that voxels with low gaussian values are far from the center in 3d space.<br>\nHowever, the model I'm aiming for is unet2d so it feels like a lot of the context in 3d would be missing, making the method a bit awkward.<br>\nWould you agree with this?</p>",
  "messages": [
    {
      "id": "3172717",
      "postDate": "04/07/2025 05:30:33",
      "content": "<p>Hi, I'm currently trying to create masked targets for my unet2d model but I'm unsure how to shape the 3d masks<br>\nIn the previous czii competition, the main approach was to create a sphere around the target coordinates with the radius specified in the dataset.<br>\nEach voxel would be annotated with its corresponding class(hard label?).<br>\n(c.f. <a href=\"https://www.kaggle.com/code/fnands/create-numpy-dataset-exp-name\" target=\"_blank\">https://www.kaggle.com/code/fnands/create-numpy-dataset-exp-name</a>)<br>\nHowever, the motors in this competition seem to have an elongated shape and it doesn't feel right to set the target to a sphere.<br>\nShould I forget about said shape and hope the model learns with a conservative radius or is there a better way to approach this?<br>\nAlso, the czii 1st place solution(I think) mentioned using soft labels(3d gaussian centered at target coordinates).<br>\nIn this approach, it feels like it would have to be obvious from the models point of view that voxels with low gaussian values are far from the center in 3d space.<br>\nHowever, the model I'm aiming for is unet2d so it feels like a lot of the context in 3d would be missing, making the method a bit awkward.<br>\nWould you agree with this?</p>",
      "rawMarkdown": "Hi, I'm currently trying to create masked targets for my unet2d model but I'm unsure how to shape the 3d masks\nIn the previous czii competition, the main approach was to create a sphere around the target coordinates with the radius specified in the dataset.\nEach voxel would be annotated with its corresponding class(hard label?).\n(c.f. https://www.kaggle.com/code/fnands/create-numpy-dataset-exp-name)\nHowever, the motors in this competition seem to have an elongated shape and it doesn't feel right to set the target to a sphere.\nShould I forget about said shape and hope the model learns with a conservative radius or is there a better way to approach this?\nAlso, the czii 1st place solution(I think) mentioned using soft labels(3d gaussian centered at target coordinates).\nIn this approach, it feels like it would have to be obvious from the models point of view that voxels with low gaussian values are far from the center in 3d space.\nHowever, the model I'm aiming for is unet2d so it feels like a lot of the context in 3d would be missing, making the method a bit awkward.\nWould you agree with this?",
      "votes": null
    },
    {
      "id": "3173454",
      "postDate": "04/08/2025 00:02:27",
      "content": "<p>Gaussian ball is really good in this comp. You can create the labels by expanding a circle around the target point as positive.</p>",
      "rawMarkdown": "Gaussian ball is really good in this comp. You can create the labels by expanding a circle around the target point as positive.",
      "votes": null
    },
    {
      "id": "3174348",
      "postDate": "04/09/2025 02:23:23",
      "content": "<p>Thanks for replying!!<br>\nSo your recommendation is hard labels where foreground=1 and background=0?</p>\n<p>Also apologies if I feel a bit nosy but a couple days ago I saw a post where you mentioned gaussian balls don't work well.</p>\n<blockquote>\n  <p>I currently work on label development. I found that 3d unet is very hard to capture the motor if we give a single voxel, even using class_weight. Gaussian ball does not work as well cause it cannot show strong connection between label and image. Other methods from czii do not work. Their performance are bad. Maybe structural target can show up.<br>\n  (<a href=\"https://www.kaggle.com/competitions/byu-locating-bacterial-flagellar-motors-2025/discussion/568930\" target=\"_blank\">https://www.kaggle.com/competitions/byu-locating-bacterial-flagellar-motors-2025/discussion/568930</a>)</p>\n</blockquote>\n<p>I'm guessing it didn't work well initially but you found a way to make the connection between labels and images more obvious to the model?</p>",
      "rawMarkdown": "Thanks for replying!!\nSo your recommendation is hard labels where foreground=1 and background=0?\n\nAlso apologies if I feel a bit nosy but a couple days ago I saw a post where you mentioned gaussian balls don't work well.\n\n> I currently work on label development. I found that 3d unet is very hard to capture the motor if we give a single voxel, even using class_weight. Gaussian ball does not work as well cause it cannot show strong connection between label and image. Other methods from czii do not work. Their performance are bad. Maybe structural target can show up.\n(https://www.kaggle.com/competitions/byu-locating-bacterial-flagellar-motors-2025/discussion/568930)\n\nI'm guessing it didn't work well initially but you found a way to make the connection between labels and images more obvious to the model?",
      "votes": null
    },
    {
      "id": "3174370",
      "postDate": "04/09/2025 03:01:26",
      "content": "<p><a href=\"https://www.kaggle.com/k8tems\" target=\"_blank\">@k8tems</a> Refer to my notebook. I use HDBSCAN to capture the prediction result where the model is trained on gaussian ball. <a href=\"https://www.kaggle.com/code/tom99763/gnn-example-byu\" target=\"_blank\">https://www.kaggle.com/code/tom99763/gnn-example-byu</a></p>",
      "rawMarkdown": "k8tems Refer to my notebook. I use HDBSCAN to capture the prediction result where the model is trained on gaussian ball. https://www.kaggle.com/code/tom99763/gnn-example-byu",
      "votes": null
    },
    {
      "id": "3174375",
      "postDate": "04/09/2025 03:20:10",
      "content": "<p>Thanks! Looking into it</p>",
      "rawMarkdown": "Thanks! Looking into it",
      "votes": null
    },
    {
      "id": "3187480",
      "postDate": "04/26/2025 05:06:10",
      "content": "<p>Hi <a href=\"https://www.kaggle.com/tom99763\" target=\"_blank\">@tom99763</a> , I have also taken this approach by using gaussian balls - but have had a lot of trouble with (1) memory constraints (2) learning anything.</p>\n<p>Would you be able to suggest to me how you have gone about resizing/cropping/scaling?</p>\n<p>Additionally, is there any information you could provide me on your loss functions? </p>\n<ul>\n<li>I am using the focal loss from the center net paper, but model consistently predicts background for all pixels, despite a setting alpha =1 and beta = 4 to 6 (to focus on foreground pixels). </li>\n</ul>",
      "rawMarkdown": "Hi @tom99763 , I have also taken this approach by using gaussian balls - but have had a lot of trouble with (1) memory constraints (2) learning anything.\n\nWould you be able to suggest to me how you have gone about resizing/cropping/scaling?\n\nAdditionally, is there any information you could provide me on your loss functions? \n- I am using the focal loss from the center net paper, but model consistently predicts background for all pixels, despite a setting alpha =1 and beta = 4 to 6 (to focus on foreground pixels).",
      "votes": null
    },
    {
      "id": "3187492",
      "postDate": "04/26/2025 05:18:17",
      "content": "<ol>\n<li>Sub volume inference e.g. take (64x64x192）</li>\n<li>Focal loss does not do well in this comp. So just use positive weight to address imbalance.</li>\n<li>I think label development and preprocessing are the most critical, my current strategy is based on these ingredients.</li>\n</ol>",
      "rawMarkdown": "1. Sub volume inference e.g. take (64x64x192）\n2. Focal loss does not do well in this comp. So just use positive weight to address imbalance.\n3. I think label development and preprocessing are the most critical, my current strategy is based on these ingredients.",
      "votes": null
    },
    {
      "id": "3187686",
      "postDate": "04/26/2025 11:37:42",
      "content": "<p>Okay, thanks!</p>\n<p>So no resizing? Some of the image shapes are quite large e.g. (500, 1912, 1847) I am surprised that the scoring of these can fit within the time frame, based on my experience with training, and also the previous cryoet comp.</p>\n<p>Is there any explanation you might have for why focal loss doesn't work? The winning solution from previous cryoet comp used this loss in one of the experiments.</p>",
      "rawMarkdown": "Okay, thanks!\n\nSo no resizing? Some of the image shapes are quite large e.g. (500, 1912, 1847) I am surprised that the scoring of these can fit within the time frame, based on my experience with training, and also the previous cryoet comp.\n\nIs there any explanation you might have for why focal loss doesn't work? The winning solution from previous cryoet comp used this loss in one of the experiments.",
      "votes": null
    },
    {
      "id": "3188033",
      "postDate": "04/27/2025 00:01:23",
      "content": "<p>Hi everyone,Thanks a lot for this discussion! <br>\nQuick question:<br>\nFrom my understanding, YOLO models like hard label (bounding box) formats and not soft 3D masks.<br>\nIf I were doing segmentation with U-Net 3D/2D, I would try gaussian balls or soft masks for better learning. But for YOLO, keeping it simple (hard labels) seems to work better. Is that right? Thanks again</p>",
      "rawMarkdown": "Hi everyone,Thanks a lot for this discussion! \nQuick question:\nFrom my understanding, YOLO models like hard label (bounding box) formats and not soft 3D masks.\nIf I were doing segmentation with U-Net 3D/2D, I would try gaussian balls or soft masks for better learning. But for YOLO, keeping it simple (hard labels) seems to work better. Is that right? Thanks again",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 3173454,
      "author_name": "tom99763",
      "author_url": "",
      "post_date": "04/08/2025 00:02:27",
      "content": "<p>Gaussian ball is really good in this comp. You can create the labels by expanding a circle around the target point as positive.</p>",
      "votes": null,
      "replies": [
        {
          "id": 3174348,
          "author_name": "k8tems",
          "author_url": "",
          "post_date": "04/09/2025 02:23:23",
          "content": "<p>Thanks for replying!!<br>\nSo your recommendation is hard labels where foreground=1 and background=0?</p>\n<p>Also apologies if I feel a bit nosy but a couple days ago I saw a post where you mentioned gaussian balls don't work well.</p>\n<blockquote>\n  <p>I currently work on label development. I found that 3d unet is very hard to capture the motor if we give a single voxel, even using class_weight. Gaussian ball does not work as well cause it cannot show strong connection between label and image. Other methods from czii do not work. Their performance are bad. Maybe structural target can show up.<br>\n  (<a href=\"https://www.kaggle.com/competitions/byu-locating-bacterial-flagellar-motors-2025/discussion/568930\" target=\"_blank\">https://www.kaggle.com/competitions/byu-locating-bacterial-flagellar-motors-2025/discussion/568930</a>)</p>\n</blockquote>\n<p>I'm guessing it didn't work well initially but you found a way to make the connection between labels and images more obvious to the model?</p>",
          "votes": null,
          "replies": [
            {
              "id": 3174370,
              "author_name": "tom99763",
              "author_url": "",
              "post_date": "04/09/2025 03:01:26",
              "content": "<p><a href=\"https://www.kaggle.com/k8tems\" target=\"_blank\">@k8tems</a> Refer to my notebook. I use HDBSCAN to capture the prediction result where the model is trained on gaussian ball. <a href=\"https://www.kaggle.com/code/tom99763/gnn-example-byu\" target=\"_blank\">https://www.kaggle.com/code/tom99763/gnn-example-byu</a></p>",
              "votes": null,
              "replies": [
                {
                  "id": 3174375,
                  "author_name": "k8tems",
                  "author_url": "",
                  "post_date": "04/09/2025 03:20:10",
                  "content": "<p>Thanks! Looking into it</p>",
                  "votes": null,
                  "replies": []
                }
              ]
            }
          ]
        },
        {
          "id": 3187480,
          "author_name": "homiecal",
          "author_url": "",
          "post_date": "04/26/2025 05:06:10",
          "content": "<p>Hi <a href=\"https://www.kaggle.com/tom99763\" target=\"_blank\">@tom99763</a> , I have also taken this approach by using gaussian balls - but have had a lot of trouble with (1) memory constraints (2) learning anything.</p>\n<p>Would you be able to suggest to me how you have gone about resizing/cropping/scaling?</p>\n<p>Additionally, is there any information you could provide me on your loss functions? </p>\n<ul>\n<li>I am using the focal loss from the center net paper, but model consistently predicts background for all pixels, despite a setting alpha =1 and beta = 4 to 6 (to focus on foreground pixels). </li>\n</ul>",
          "votes": null,
          "replies": [
            {
              "id": 3187492,
              "author_name": "tom99763",
              "author_url": "",
              "post_date": "04/26/2025 05:18:17",
              "content": "<ol>\n<li>Sub volume inference e.g. take (64x64x192）</li>\n<li>Focal loss does not do well in this comp. So just use positive weight to address imbalance.</li>\n<li>I think label development and preprocessing are the most critical, my current strategy is based on these ingredients.</li>\n</ol>",
              "votes": null,
              "replies": [
                {
                  "id": 3187686,
                  "author_name": "homiecal",
                  "author_url": "",
                  "post_date": "04/26/2025 11:37:42",
                  "content": "<p>Okay, thanks!</p>\n<p>So no resizing? Some of the image shapes are quite large e.g. (500, 1912, 1847) I am surprised that the scoring of these can fit within the time frame, based on my experience with training, and also the previous cryoet comp.</p>\n<p>Is there any explanation you might have for why focal loss doesn't work? The winning solution from previous cryoet comp used this loss in one of the experiments.</p>",
                  "votes": null,
                  "replies": []
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "id": 3188033,
      "author_name": "achievement",
      "author_url": "",
      "post_date": "04/27/2025 00:01:23",
      "content": "<p>Hi everyone,Thanks a lot for this discussion! <br>\nQuick question:<br>\nFrom my understanding, YOLO models like hard label (bounding box) formats and not soft 3D masks.<br>\nIf I were doing segmentation with U-Net 3D/2D, I would try gaussian balls or soft masks for better learning. But for YOLO, keeping it simple (hard labels) seems to work better. Is that right? Thanks again</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "3172717": "Hi, I'm currently trying to create masked targets for my unet2d model but I'm unsure how to shape the 3d masks\nIn the previous czii competition, the main approach was to create a sphere around the target coordinates with the radius specified in the dataset.\nEach voxel would be annotated with its corresponding class(hard label?).\n(c.f. https://www.kaggle.com/code/fnands/create-numpy-dataset-exp-name)\nHowever, the motors in this competition seem to have an elongated shape and it doesn't feel right to set the target to a sphere.\nShould I forget about said shape and hope the model learns with a conservative radius or is there a better way to approach this?\nAlso, the czii 1st place solution(I think) mentioned using soft labels(3d gaussian centered at target coordinates).\nIn this approach, it feels like it would have to be obvious from the models point of view that voxels with low gaussian values are far from the center in 3d space.\nHowever, the model I'm aiming for is unet2d so it feels like a lot of the context in 3d would be missing, making the method a bit awkward.\nWould you agree with this?",
    "3173454": "Gaussian ball is really good in this comp. You can create the labels by expanding a circle around the target point as positive.",
    "3174348": "Thanks for replying!!\nSo your recommendation is hard labels where foreground=1 and background=0?\n\nAlso apologies if I feel a bit nosy but a couple days ago I saw a post where you mentioned gaussian balls don't work well.\n\n> I currently work on label development. I found that 3d unet is very hard to capture the motor if we give a single voxel, even using class_weight. Gaussian ball does not work as well cause it cannot show strong connection between label and image. Other methods from czii do not work. Their performance are bad. Maybe structural target can show up.\n(https://www.kaggle.com/competitions/byu-locating-bacterial-flagellar-motors-2025/discussion/568930)\n\nI'm guessing it didn't work well initially but you found a way to make the connection between labels and images more obvious to the model?",
    "3174370": "k8tems Refer to my notebook. I use HDBSCAN to capture the prediction result where the model is trained on gaussian ball. https://www.kaggle.com/code/tom99763/gnn-example-byu",
    "3174375": "Thanks! Looking into it",
    "3187480": "Hi @tom99763 , I have also taken this approach by using gaussian balls - but have had a lot of trouble with (1) memory constraints (2) learning anything.\n\nWould you be able to suggest to me how you have gone about resizing/cropping/scaling?\n\nAdditionally, is there any information you could provide me on your loss functions? \n- I am using the focal loss from the center net paper, but model consistently predicts background for all pixels, despite a setting alpha =1 and beta = 4 to 6 (to focus on foreground pixels).",
    "3187492": "1. Sub volume inference e.g. take (64x64x192）\n2. Focal loss does not do well in this comp. So just use positive weight to address imbalance.\n3. I think label development and preprocessing are the most critical, my current strategy is based on these ingredients.",
    "3187686": "Okay, thanks!\n\nSo no resizing? Some of the image shapes are quite large e.g. (500, 1912, 1847) I am surprised that the scoring of these can fit within the time frame, based on my experience with training, and also the previous cryoet comp.\n\nIs there any explanation you might have for why focal loss doesn't work? The winning solution from previous cryoet comp used this loss in one of the experiments.",
    "3188033": "Hi everyone,Thanks a lot for this discussion! \nQuick question:\nFrom my understanding, YOLO models like hard label (bounding box) formats and not soft 3D masks.\nIf I were doing segmentation with U-Net 3D/2D, I would try gaussian balls or soft masks for better learning. But for YOLO, keeping it simple (hard labels) seems to work better. Is that right? Thanks again"
  },
  "source": "meta"
}