{
  "id": 294795,
  "title": "Anyone using cellpose notice that diameter has so much impact on LB score?",
  "url": "/competitions/sartorius-cell-instance-segmentation/discussion/294795",
  "author_name": "Swikwislkdjc",
  "post_date": "2021-12-12T21:18:49.930000",
  "votes": 11,
  "comment_count": 12,
  "views": 0,
  "content": "<p>Same cellpose model, but setting different diameter when submitting using the cellpose inference notebook leads to big difference on LB score. </p>\n<p>One diameter is 30 (default), LB score is 0.239<br>\nThe other diameter is 19, LB score is 0.304</p>\n<p>I'm just surprised that same model, with only difference of diameter, can lead to such different LB score</p>",
  "messages": [
    {
      "id": 1615887,
      "postDate": "2021-12-12T21:18:49.930Z",
      "content": "<p>Same cellpose model, but setting different diameter when submitting using the cellpose inference notebook leads to big difference on LB score. </p>\n<p>One diameter is 30 (default), LB score is 0.239<br>\nThe other diameter is 19, LB score is 0.304</p>\n<p>I'm just surprised that same model, with only difference of diameter, can lead to such different LB score</p>",
      "rawMarkdown": "Same cellpose model, but setting different diameter when submitting using the cellpose inference notebook leads to big difference on LB score. \n\nOne diameter is 30 (default), LB score is 0.239\nThe other diameter is 19, LB score is 0.304\n\nI'm just surprised that same model, with only difference of diameter, can lead to such different LB score",
      "votes": 11
    },
    {
      "id": 1615906,
      "postDate": "2021-12-12T22:18:08.197Z",
      "content": "<p>To answer that you can look at how the generated flows differ. Below the same image with two diameters:<br>\n<img src=\"https://raw.githubusercontent.com/slawekslex/random/main/cellpose_flows.png\" alt=\"\"></p>\n<p>And here are the resulting mask with the target as rightmost:</p>\n<p><img src=\"https://raw.githubusercontent.com/slawekslex/random/main/cellpose_mask.png\" alt=\"\"></p>\n<p>You can see how this would result in a big score difference.</p>",
      "rawMarkdown": "To answer that you can look at how the generated flows differ. Below the same image with two diameters:\n![](https://raw.githubusercontent.com/slawekslex/random/main/cellpose_flows.png)\n\nAnd here are the resulting mask with the target as rightmost:\n\n![](https://raw.githubusercontent.com/slawekslex/random/main/cellpose_mask.png)\n\nYou can see how this would result in a big score difference.",
      "votes": 3,
      "replies": [
        {
          "id": 1615908,
          "postDate": "2021-12-12T22:26:29.893Z",
          "content": "<p>Fantastic visualization! Is this visualization method same with the one you shared in the other discussion post <a href=\"https://www.kaggle.com/c/sartorius-cell-instance-segmentation/discussion/292094#1602325\" target=\"_blank\">https://www.kaggle.com/c/sartorius-cell-instance-segmentation/discussion/292094#1602325</a>?</p>",
          "rawMarkdown": "Fantastic visualization! Is this visualization method same with the one you shared in the other discussion post https://www.kaggle.com/c/sartorius-cell-instance-segmentation/discussion/292094#1602325?"
        },
        {
          "id": 1615910,
          "postDate": "2021-12-12T22:28:37.057Z",
          "content": "<p>No, this is just directly plotted what <code>CellposeModel.eval()</code> returns.</p>",
          "rawMarkdown": "No, this is just directly plotted what `CellposeModel.eval()` returns.",
          "votes": 1
        },
        {
          "id": 1615912,
          "postDate": "2021-12-12T22:32:07.117Z",
          "content": "<p>Got it. I should've read through their documents.</p>",
          "rawMarkdown": "Got it. I should've read through their documents."
        },
        {
          "id": 1616923,
          "postDate": "2021-12-13T17:57:53.943Z",
          "content": "<p>hi <a href=\"https://www.kaggle.com/slawekbiel\" target=\"_blank\">@slawekbiel</a>,  could you please tell if the following code would produce correct .tif masks or what code you used to do the same? </p>\n<pre><code>from pycocotools.coco import COCO\nimport scipy.ndimage as ndi\nfrom PIL import Image as im\n\ncoco=COCO('/content/drive/MyDrive/Kaggle/sartorius-cell/annotations_all.json') #path to all train anns from kaggle public datasets\ncat_ids = coco.getCatIds()\ndata_root = Path(\"/content/\")\ndf = pd.read_csv(str(data_root.joinpath(\"train.csv\")))\nimg_dir = data_root.joinpath(\"train\")\n\nfor idx, row in df.iterrows():\n\n    anns_ids = coco.getAnnIds(imgIds=row['id'], catIds=cat_ids, iscrowd=None)\n    anns = coco.loadAnns(anns_ids)\n    anns_img = np.zeros((row['height'],row['width']))\n    for ann in anns:\n        anns_img = np.maximum(anns_img,coco.annToMask(ann)*ann['category_id'])\n    #mask = rle2mask(row['annotation'], row['width'], row['height'])\n    name = row[\"id\"]\n\n    mask = ndi.binary_fill_holes(anns_img).astype(np.uint8)\n    data = im.fromarray(mask)\n    data.save(f'{name}_masks.tif')\n</code></pre>\n<p>it has been adapted from <a href=\"https://stackoverflow.com/questions/50805634/how-to-create-mask-images-from-coco-dataset\" target=\"_blank\">this</a> website and the broken masks Kaggle Notebook</p>\n<p>UPD: For anyone still stuck I found <a href=\"https://www.kaggle.com/dschettler8845/sartorius-segmentation-mask-dataset/notebook\" target=\"_blank\">this</a> notebook that implement numpy mask creation that can be easily configured to save as a tif files</p>",
          "rawMarkdown": "hi @slawekbiel,  could you please tell if the following code would produce correct .tif masks or what code you used to do the same? \n\n```\n\nfrom pycocotools.coco import COCO\nimport scipy.ndimage as ndi\nfrom PIL import Image as im\n\ncoco=COCO('/content/drive/MyDrive/Kaggle/sartorius-cell/annotations_all.json') #path to all train anns from kaggle public datasets\ncat_ids = coco.getCatIds()\ndata_root = Path(\"/content/\")\ndf = pd.read_csv(str(data_root.joinpath(\"train.csv\")))\nimg_dir = data_root.joinpath(\"train\")\n\nfor idx, row in df.iterrows():\n\n    anns_ids = coco.getAnnIds(imgIds=row['id'], catIds=cat_ids, iscrowd=None)\n    anns = coco.loadAnns(anns_ids)\n    anns_img = np.zeros((row['height'],row['width']))\n    for ann in anns:\n        anns_img = np.maximum(anns_img,coco.annToMask(ann)*ann['category_id'])\n    #mask = rle2mask(row['annotation'], row['width'], row['height'])\n    name = row[\"id\"]\n    \n    mask = ndi.binary_fill_holes(anns_img).astype(np.uint8)\n    data = im.fromarray(mask)\n    data.save(f'{name}_masks.tif')\n    \n```\nit has been adapted from [this](https://stackoverflow.com/questions/50805634/how-to-create-mask-images-from-coco-dataset) website and the broken masks Kaggle Notebook\n\nUPD: For anyone still stuck I found [this](https://www.kaggle.com/dschettler8845/sartorius-segmentation-mask-dataset/notebook) notebook that implement numpy mask creation that can be easily configured to save as a tif files"
        },
        {
          "id": 1617078,
          "postDate": "2021-12-13T20:15:05.580Z",
          "content": "<p>I’m sorry <a href=\"https://www.kaggle.com/ferlockx\" target=\"_blank\">@ferlockx</a> I feel like I’ve shared enough throughout this competition. In the final weeks I’m focusing sorely on my team score.</p>",
          "rawMarkdown": "I’m sorry @ferlockx I feel like I’ve shared enough throughout this competition. In the final weeks I’m focusing sorely on my team score.",
          "votes": 5
        },
        {
          "id": 1617094,
          "postDate": "2021-12-13T20:40:23.560Z",
          "content": "<p>okay that's completely fair, thanks for all your public work and best of luck :) </p>",
          "rawMarkdown": "okay that's completely fair, thanks for all your public work and best of luck :) ",
          "votes": 1
        }
      ]
    },
    {
      "id": 1631940,
      "postDate": "2021-12-29T00:37:58.340Z",
      "content": "<p>Using cellpose will be valid on oficial submission? (In the sense that is it is a free software? )</p>",
      "rawMarkdown": "Using cellpose will be valid on oficial submission? (In the sense that is it is a free software? )"
    },
    {
      "id": 1624266,
      "postDate": "2021-12-20T17:25:41.657Z",
      "content": "<p>that's true. I realize that the diameter actully go for a hyperparameter of cellpose.Differ among classes as well as images.</p>",
      "rawMarkdown": "that's true. I realize that the diameter actully go for a hyperparameter of cellpose.Differ among classes as well as images."
    },
    {
      "id": 1623481,
      "postDate": "2021-12-19T23:58:00.800Z",
      "content": "<p>I think the diameter actually change the resize. Then</p>\n<ol>\n<li>smaller resize give worse segmentation in general.</li>\n<li>the minimum cell size threshold also depends on resize</li>\n</ol>",
      "rawMarkdown": "I think the diameter actually change the resize. Then\n1. smaller resize give worse segmentation in general.\n2. the minimum cell size threshold also depends on resize"
    },
    {
      "id": 1616578,
      "postDate": "2021-12-13T14:09:00.223Z",
      "content": "<p>what was the corresponding CV for 0.304 LB? 😅 Also did you try pretraining with all of LiveCell data using lowered diameter param?</p>",
      "rawMarkdown": "what was the corresponding CV for 0.304 LB? 😅 Also did you try pretraining with all of LiveCell data using lowered diameter param?"
    },
    {
      "id": 1616918,
      "postDate": "2021-12-13T17:56:21.350Z",
      "rawMarkdown": "",
      "isDeleted": true
    }
  ],
  "comments": [
    {
      "id": 1615906,
      "author_name": "Slawek Biel",
      "author_url": "",
      "post_date": "2021-12-12T22:18:08.197000",
      "content": "<p>To answer that you can look at how the generated flows differ. Below the same image with two diameters:<br>\n<img src=\"https://raw.githubusercontent.com/slawekslex/random/main/cellpose_flows.png\" alt=\"\"></p>\n<p>And here are the resulting mask with the target as rightmost:</p>\n<p><img src=\"https://raw.githubusercontent.com/slawekslex/random/main/cellpose_mask.png\" alt=\"\"></p>\n<p>You can see how this would result in a big score difference.</p>",
      "votes": 3,
      "replies": [
        {
          "id": 1615908,
          "author_name": "Swikwislkdjc",
          "author_url": "",
          "post_date": "2021-12-12T22:26:29.893000",
          "content": "<p>Fantastic visualization! Is this visualization method same with the one you shared in the other discussion post <a href=\"https://www.kaggle.com/c/sartorius-cell-instance-segmentation/discussion/292094#1602325\" target=\"_blank\">https://www.kaggle.com/c/sartorius-cell-instance-segmentation/discussion/292094#1602325</a>?</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1615910,
          "author_name": "Slawek Biel",
          "author_url": "",
          "post_date": "2021-12-12T22:28:37.057000",
          "content": "<p>No, this is just directly plotted what <code>CellposeModel.eval()</code> returns.</p>",
          "votes": 1,
          "replies": []
        },
        {
          "id": 1615912,
          "author_name": "Swikwislkdjc",
          "author_url": "",
          "post_date": "2021-12-12T22:32:07.117000",
          "content": "<p>Got it. I should've read through their documents.</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1616923,
          "author_name": "Hannah B",
          "author_url": "",
          "post_date": "2021-12-13T17:57:53.943000",
          "content": "<p>hi <a href=\"https://www.kaggle.com/slawekbiel\" target=\"_blank\">@slawekbiel</a>,  could you please tell if the following code would produce correct .tif masks or what code you used to do the same? </p>\n<pre><code>from pycocotools.coco import COCO\nimport scipy.ndimage as ndi\nfrom PIL import Image as im\n\ncoco=COCO('/content/drive/MyDrive/Kaggle/sartorius-cell/annotations_all.json') #path to all train anns from kaggle public datasets\ncat_ids = coco.getCatIds()\ndata_root = Path(\"/content/\")\ndf = pd.read_csv(str(data_root.joinpath(\"train.csv\")))\nimg_dir = data_root.joinpath(\"train\")\n\nfor idx, row in df.iterrows():\n\n    anns_ids = coco.getAnnIds(imgIds=row['id'], catIds=cat_ids, iscrowd=None)\n    anns = coco.loadAnns(anns_ids)\n    anns_img = np.zeros((row['height'],row['width']))\n    for ann in anns:\n        anns_img = np.maximum(anns_img,coco.annToMask(ann)*ann['category_id'])\n    #mask = rle2mask(row['annotation'], row['width'], row['height'])\n    name = row[\"id\"]\n\n    mask = ndi.binary_fill_holes(anns_img).astype(np.uint8)\n    data = im.fromarray(mask)\n    data.save(f'{name}_masks.tif')\n</code></pre>\n<p>it has been adapted from <a href=\"https://stackoverflow.com/questions/50805634/how-to-create-mask-images-from-coco-dataset\" target=\"_blank\">this</a> website and the broken masks Kaggle Notebook</p>\n<p>UPD: For anyone still stuck I found <a href=\"https://www.kaggle.com/dschettler8845/sartorius-segmentation-mask-dataset/notebook\" target=\"_blank\">this</a> notebook that implement numpy mask creation that can be easily configured to save as a tif files</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1617078,
          "author_name": "Slawek Biel",
          "author_url": "",
          "post_date": "2021-12-13T20:15:05.580000",
          "content": "<p>I’m sorry <a href=\"https://www.kaggle.com/ferlockx\" target=\"_blank\">@ferlockx</a> I feel like I’ve shared enough throughout this competition. In the final weeks I’m focusing sorely on my team score.</p>",
          "votes": 5,
          "replies": []
        },
        {
          "id": 1617094,
          "author_name": "Hannah B",
          "author_url": "",
          "post_date": "2021-12-13T20:40:23.560000",
          "content": "<p>okay that's completely fair, thanks for all your public work and best of luck :) </p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 1631940,
      "author_name": "rpsantosa_kaggle",
      "author_url": "",
      "post_date": "2021-12-29T00:37:58.340000",
      "content": "<p>Using cellpose will be valid on oficial submission? (In the sense that is it is a free software? )</p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1624266,
      "author_name": "Lupin",
      "author_url": "",
      "post_date": "2021-12-20T17:25:41.657000",
      "content": "<p>that's true. I realize that the diameter actully go for a hyperparameter of cellpose.Differ among classes as well as images.</p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1623481,
      "author_name": "Jun Huang",
      "author_url": "",
      "post_date": "2021-12-19T23:58:00.800000",
      "content": "<p>I think the diameter actually change the resize. Then</p>\n<ol>\n<li>smaller resize give worse segmentation in general.</li>\n<li>the minimum cell size threshold also depends on resize</li>\n</ol>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1616578,
      "author_name": "Hannah B",
      "author_url": "",
      "post_date": "2021-12-13T14:09:00.223000",
      "content": "<p>what was the corresponding CV for 0.304 LB? 😅 Also did you try pretraining with all of LiveCell data using lowered diameter param?</p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1616918,
      "author_name": "",
      "author_url": "",
      "post_date": "2021-12-13T17:56:21.350000",
      "content": "",
      "votes": 0,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1615887": "Same cellpose model, but setting different diameter when submitting using the cellpose inference notebook leads to big difference on LB score. \n\nOne diameter is 30 (default), LB score is 0.239\nThe other diameter is 19, LB score is 0.304\n\nI'm just surprised that same model, with only difference of diameter, can lead to such different LB score",
    "1615906": "To answer that you can look at how the generated flows differ. Below the same image with two diameters:\n![](https://raw.githubusercontent.com/slawekslex/random/main/cellpose_flows.png)\n\nAnd here are the resulting mask with the target as rightmost:\n\n![](https://raw.githubusercontent.com/slawekslex/random/main/cellpose_mask.png)\n\nYou can see how this would result in a big score difference.",
    "1631940": "Using cellpose will be valid on oficial submission? (In the sense that is it is a free software? )",
    "1624266": "that's true. I realize that the diameter actully go for a hyperparameter of cellpose.Differ among classes as well as images.",
    "1623481": "I think the diameter actually change the resize. Then\n1. smaller resize give worse segmentation in general.\n2. the minimum cell size threshold also depends on resize",
    "1616578": "what was the corresponding CV for 0.304 LB? 😅 Also did you try pretraining with all of LiveCell data using lowered diameter param?",
    "1616918": ""
  }
}