{
  "id": 293159,
  "title": "UNet strikes... a pose!",
  "url": "/competitions/sartorius-cell-instance-segmentation/discussion/293159",
  "author_name": "Slawek Biel",
  "post_date": "2021-12-04T18:21:07.098000",
  "votes": 55,
  "comment_count": 20,
  "views": 0,
  "content": "<p>I tried out the <a href=\"http://www.cellpose.org/\" target=\"_blank\">Cellpose</a>. The model is based on U-Net, however rather than training it directly on bitmask targets they first convert them to \"spatial flows\" representations and train on that. This makes segmentation of dense and touching cells more reliable. See a sample output on the fourth image bellow. </p>\n<p>It works well out of the box (without any custom code in training, nor inference) , and gives a better LB score than the other UNet models I've seen shared so far.</p>\n<p>An example infer notebook here: <a href=\"https://www.kaggle.com/slawekbiel/cellpose-inference-307-lb\" target=\"_blank\">https://www.kaggle.com/slawekbiel/cellpose-inference-307-lb</a></p>\n<p>Thanks to the indispensable <a href=\"https://www.kaggle.com/hengck23\" target=\"_blank\">@hengck23</a> for mentioning the library on the forum, which made me check it out.</p>\n<p><img src=\"https://raw.githubusercontent.com/slawekslex/random/main/cellpose.png\" alt=\"\"></p>\n<p><em>Note: I deliberately did not share model weights, nor detailed training instructions at this point of the competition. The cellpose repo has good documentation and examples, so it doesn't take too much work to get a working model.</em></p>",
  "messages": [
    {
      "id": 1605950,
      "postDate": "2021-12-04T18:21:07.100Z",
      "content": "<p>I tried out the <a href=\"http://www.cellpose.org/\" target=\"_blank\">Cellpose</a>. The model is based on U-Net, however rather than training it directly on bitmask targets they first convert them to \"spatial flows\" representations and train on that. This makes segmentation of dense and touching cells more reliable. See a sample output on the fourth image bellow. </p>\n<p>It works well out of the box (without any custom code in training, nor inference) , and gives a better LB score than the other UNet models I've seen shared so far.</p>\n<p>An example infer notebook here: <a href=\"https://www.kaggle.com/slawekbiel/cellpose-inference-307-lb\" target=\"_blank\">https://www.kaggle.com/slawekbiel/cellpose-inference-307-lb</a></p>\n<p>Thanks to the indispensable <a href=\"https://www.kaggle.com/hengck23\" target=\"_blank\">@hengck23</a> for mentioning the library on the forum, which made me check it out.</p>\n<p><img src=\"https://raw.githubusercontent.com/slawekslex/random/main/cellpose.png\" alt=\"\"></p>\n<p><em>Note: I deliberately did not share model weights, nor detailed training instructions at this point of the competition. The cellpose repo has good documentation and examples, so it doesn't take too much work to get a working model.</em></p>",
      "rawMarkdown": "I tried out the [Cellpose](http://www.cellpose.org/). The model is based on U-Net, however rather than training it directly on bitmask targets they first convert them to \"spatial flows\" representations and train on that. This makes segmentation of dense and touching cells more reliable. See a sample output on the fourth image bellow. \n\nIt works well out of the box (without any custom code in training, nor inference) , and gives a better LB score than the other UNet models I've seen shared so far.\n\nAn example infer notebook here: https://www.kaggle.com/slawekbiel/cellpose-inference-307-lb\n\nThanks to the indispensable @hengck23 for mentioning the library on the forum, which made me check it out.\n\n![](https://raw.githubusercontent.com/slawekslex/random/main/cellpose.png)\n\n*Note: I deliberately did not share model weights, nor detailed training instructions at this point of the competition. The cellpose repo has good documentation and examples, so it doesn't take too much work to get a working model.*",
      "votes": 54
    },
    {
      "id": 1606425,
      "postDate": "2021-12-05T02:11:17.460Z",
      "content": "<p>a few tips:</p>\n<ul>\n<li><p>the official cellpose expects some min size of the cell (I think it is about 15). if you enlarge your image (for training and testing or as TTA), results can be better</p></li>\n<li><p>Unet is easier to ensemble</p></li>\n<li><p>if you check your results image posted,  the post processing of cellpose ignore incomplete \"spatial flows\".(check the missing detection). you can improve on that,e.g. after segmenting the easier ones,  you can use another set of threshold, etc. or you can train an iou prediction to decide to keep post processing results. or you can train a post-processing model to convert flow to mask</p></li>\n<li><p>cellpose doesn't extend segmentation to the long thin structure, but that is easily fixed </p></li>\n</ul>",
      "rawMarkdown": "a few tips:\n\n- the official cellpose expects some min size of the cell (I think it is about 15). if you enlarge your image (for training and testing or as TTA), results can be better\n\n- Unet is easier to ensemble\n\n- if you check your results image posted,  the post processing of cellpose ignore incomplete \"spatial flows\".(check the missing detection). you can improve on that,e.g. after segmenting the easier ones,  you can use another set of threshold, etc. or you can train an iou prediction to decide to keep post processing results. or you can train a post-processing model to convert flow to mask\n\n- cellpose doesn't extend segmentation to the long thin structure, but that is easily fixed ",
      "votes": 9
    },
    {
      "id": 1612347,
      "postDate": "2021-12-08T19:27:29.317Z",
      "content": "<p><a href=\"https://www.kaggle.com/slawekbiel\" target=\"_blank\">@slawekbiel</a> </p>\n<p>maybe you can try this too:<br>\n<a href=\"https://github.com/ruotianluo/adaptis.pytorch/blob/master/notebooks/test_toy_model.ipynb\" target=\"_blank\">https://github.com/ruotianluo/adaptis.pytorch/blob/master/notebooks/test_toy_model.ipynb</a><br>\n<a href=\"https://github.com/saic-vul/adaptis\" target=\"_blank\">https://github.com/saic-vul/adaptis</a></p>\n<p>it looks promising</p>",
      "rawMarkdown": "@slawekbiel \n\nmaybe you can try this too:\nhttps://github.com/ruotianluo/adaptis.pytorch/blob/master/notebooks/test_toy_model.ipynb\nhttps://github.com/saic-vul/adaptis\n\nit looks promising",
      "votes": 8,
      "replies": [
        {
          "id": 1614647,
          "postDate": "2021-12-11T11:09:45.473Z",
          "content": "<p>Here's adaptis-pytorch dataset if you need it <a href=\"https://www.kaggle.com/atamazian/adaptis-pytorch\" target=\"_blank\">https://www.kaggle.com/atamazian/adaptis-pytorch</a></p>",
          "rawMarkdown": "Here's adaptis-pytorch dataset if you need it https://www.kaggle.com/atamazian/adaptis-pytorch"
        }
      ]
    },
    {
      "id": 1605960,
      "postDate": "2021-12-04T18:27:05.563Z",
      "content": "<p>If you wonder about the strange topic title I was trying to connect the <a href=\"https://www.kaggle.com/c/sartorius-cell-instance-segmentation/discussion/286553\" target=\"_blank\">UNet Strikes Back</a> thread with the Cellpose name and … a <a href=\"www.youtube.com/watch?v=GuJQSAiODqI&amp;t=35s\" target=\"_blank\">Madonna song</a><br>\nSorry ;)</p>",
      "rawMarkdown": "If you wonder about the strange topic title I was trying to connect the [UNet Strikes Back](https://www.kaggle.com/c/sartorius-cell-instance-segmentation/discussion/286553) thread with the Cellpose name and ... a [Madonna song](www.youtube.com/watch?v=GuJQSAiODqI&t=35s)\nSorry ;)",
      "votes": 4,
      "replies": [
        {
          "id": 1611372,
          "postDate": "2021-12-07T23:02:57Z",
          "content": "<p>well Kaggle is nothing without it's witty pop culture banter ;)</p>",
          "rawMarkdown": "well Kaggle is nothing without it's witty pop culture banter ;)",
          "votes": 2
        }
      ]
    },
    {
      "id": 1614881,
      "postDate": "2021-12-11T14:35:51.523Z",
      "content": "<p>hello <a href=\"https://www.kaggle.com/slawekbiel\" target=\"_blank\">@slawekbiel</a> , it was a great post …. looking forward to more posts like this</p>",
      "rawMarkdown": "hello @slawekbiel , it was a great post .... looking forward to more posts like this",
      "votes": 1
    },
    {
      "id": 1612954,
      "postDate": "2021-12-09T13:49:41.857Z",
      "content": "<p>Hey <a href=\"https://www.kaggle.com/slawekbiel\" target=\"_blank\">@slawekbiel</a> <br>\nYour notebook is very helpful, Thanks for sharing it. </p>",
      "rawMarkdown": "Hey @slawekbiel \nYour notebook is very helpful, Thanks for sharing it. ",
      "votes": 1
    },
    {
      "id": 1610418,
      "postDate": "2021-12-07T07:48:19.397Z",
      "content": "<p>Thanks for sharing. I just read the paper of the cellpose.Very brilliant idea of using the image gradient. Also I noticed that the trainning images of cellpose are a lot more ideal than livecell ones.Since the gradient are nicely defined between inside and outside of cells.However livecell images contain litle gradient infomations in cells instead of a lot of noise in the background area. But it's worth a try anyway!</p>",
      "rawMarkdown": "Thanks for sharing. I just read the paper of the cellpose.Very brilliant idea of using the image gradient. Also I noticed that the trainning images of cellpose are a lot more ideal than livecell ones.Since the gradient are nicely defined between inside and outside of cells.However livecell images contain litle gradient infomations in cells instead of a lot of noise in the background area. But it's worth a try anyway!",
      "votes": 1
    },
    {
      "id": 1613416,
      "postDate": "2021-12-10T00:05:34.540Z",
      "content": "<p>Another great post from (one of the) father of detectron2 (in this competition). Thank you for all the great works.</p>",
      "rawMarkdown": "Another great post from (one of the) father of detectron2 (in this competition). Thank you for all the great works.",
      "votes": 2
    },
    {
      "id": 1611334,
      "postDate": "2021-12-07T21:47:52.420Z",
      "content": "<p>I've written training notebook for Cellpose, and it works. However, I encountered a strange problem - during inference, I get only zeros for 3 test images. I'm using built-in function <code>train</code>. Any ideas about what is wrong?</p>",
      "rawMarkdown": "I've written training notebook for Cellpose, and it works. However, I encountered a strange problem - during inference, I get only zeros for 3 test images. I'm using built-in function `train`. Any ideas about what is wrong?",
      "votes": 2,
      "replies": [
        {
          "id": 1612494,
          "postDate": "2021-12-09T03:02:01.917Z",
          "rawMarkdown": "",
          "isDeleted": true
        },
        {
          "id": 1612732,
          "postDate": "2021-12-09T09:04:13.683Z",
          "content": "<p>UPD: It's working when I trained model with <code>cellpose</code>  shell command with 500 epochs (default).</p>",
          "rawMarkdown": "UPD: It's working when I trained model with `cellpose`  shell command with 500 epochs (default)."
        },
        {
          "id": 1613629,
          "postDate": "2021-12-10T06:47:23.203Z",
          "content": "<p>have you ever meet the error when i test the model: ValueError: masks_to_outlines takes 2D or 3D array, not 0D array</p>",
          "rawMarkdown": "have you ever meet the error when i test the model: ValueError: masks_to_outlines takes 2D or 3D array, not 0D array"
        },
        {
          "id": 1613728,
          "postDate": "2021-12-10T08:30:52.797Z",
          "content": "<p>Yes, it means the model can't find masks in training directory. Check if mask files are present in the same folder as training images and have names of \"image_name_masks.tif\".</p>",
          "rawMarkdown": "Yes, it means the model can't find masks in training directory. Check if mask files are present in the same folder as training images and have names of \"image_name_masks.tif\"."
        }
      ]
    },
    {
      "id": 1606475,
      "postDate": "2021-12-05T03:10:12.227Z",
      "content": "<p>Also, here is a notebook by <a href=\"https://www.kaggle.com/andrewscholan\" target=\"_blank\">@andrewscholan</a> on how to load Cellpose offline: <br>\n<a href=\"https://www.kaggle.com/andrewscholan/offline-package-wheeler-public\" target=\"_blank\">https://www.kaggle.com/andrewscholan/offline-package-wheeler-public</a></p>",
      "rawMarkdown": "Also, here is a notebook by @andrewscholan on how to load Cellpose offline: \nhttps://www.kaggle.com/andrewscholan/offline-package-wheeler-public",
      "votes": 2
    },
    {
      "id": 1614286,
      "postDate": "2021-12-10T21:55:49.303Z",
      "content": "<p>Thank you <a href=\"https://www.kaggle.com/slawekbiel\" target=\"_blank\">@slawekbiel</a> for sharing. I am trying to train it locally but I am having this TIFF related error</p>\n<pre><code>File \"/home/.local/lib/python3.8/site-packages/tifffile/tifffile.py\", line 3142, in __init__\n    byteorder = {b'II': '&lt;', b'MM': '&gt;', b'EP': '&lt;'}[header[:2]]\nKeyError: b'\\x89P'\n\nTiffFileError('not a TIFF file')\n</code></pre>\n<p>All the images and masks are converted from png to tiff though, did you face a similar error?</p>\n<h3>UPDATE [SOLVED]:</h3>\n<p>For those who might face the same error, it seems that even if an image is saved with a .tif extension, it might still have a PNG signature and the tifffile can't open it. More about this in <a href=\"https://stackoverflow.com/questions/57315100/how-to-resolve-tifffileerror-not-a-tiff-file-and-byte-problem-with-keyerror-b\" target=\"_blank\">this thread</a>.</p>\n<p>The solution is to create a new folder, read the images with <code>cv2.imread(path)</code>  and resave the images in the new folder with <code>cv2.imwrite(filename, img)</code></p>",
      "rawMarkdown": "Thank you @slawekbiel for sharing. I am trying to train it locally but I am having this TIFF related error\n```\nFile \"/home/.local/lib/python3.8/site-packages/tifffile/tifffile.py\", line 3142, in __init__\n    byteorder = {b'II': '<', b'MM': '>', b'EP': '<'}[header[:2]]\nKeyError: b'\\x89P'\n\nTiffFileError('not a TIFF file')\n```\nAll the images and masks are converted from png to tiff though, did you face a similar error?\n\n### UPDATE [SOLVED]:\nFor those who might face the same error, it seems that even if an image is saved with a .tif extension, it might still have a PNG signature and the tifffile can't open it. More about this in [this thread](https://stackoverflow.com/questions/57315100/how-to-resolve-tifffileerror-not-a-tiff-file-and-byte-problem-with-keyerror-b).\n\nThe solution is to create a new folder, read the images with `cv2.imread(path)`  and resave the images in the new folder with `cv2.imwrite(filename, img)`\n\n"
    },
    {
      "id": 1606481,
      "postDate": "2021-12-05T03:15:29.183Z",
      "content": "<p>Thank you for sharing!<br>\nSorry for my stupid question, this tool is competitive in this competition?</p>",
      "rawMarkdown": "Thank you for sharing!\nSorry for my stupid question, this tool is competitive in this competition?",
      "replies": [
        {
          "id": 1606490,
          "postDate": "2021-12-05T03:22:12.657Z",
          "content": "<p>Sorry I missed your notebook.<br>\nThis is competitive.</p>",
          "rawMarkdown": "Sorry I missed your notebook.\nThis is competitive.",
          "votes": 1
        }
      ]
    },
    {
      "id": 1606769,
      "postDate": "2021-12-05T08:41:50.583Z",
      "content": "<p>Thanks for sharing this one</p>",
      "rawMarkdown": "Thanks for sharing this one",
      "votes": 3
    },
    {
      "id": 1606858,
      "postDate": "2021-12-05T10:39:35.853Z",
      "content": "<p>Thanks for sharing!</p>",
      "rawMarkdown": "Thanks for sharing!",
      "votes": 1
    }
  ],
  "comments": [
    {
      "id": 1606425,
      "author_name": "hengck23",
      "author_url": "",
      "post_date": "2021-12-05T02:11:17.460000",
      "content": "<p>a few tips:</p>\n<ul>\n<li><p>the official cellpose expects some min size of the cell (I think it is about 15). if you enlarge your image (for training and testing or as TTA), results can be better</p></li>\n<li><p>Unet is easier to ensemble</p></li>\n<li><p>if you check your results image posted,  the post processing of cellpose ignore incomplete \"spatial flows\".(check the missing detection). you can improve on that,e.g. after segmenting the easier ones,  you can use another set of threshold, etc. or you can train an iou prediction to decide to keep post processing results. or you can train a post-processing model to convert flow to mask</p></li>\n<li><p>cellpose doesn't extend segmentation to the long thin structure, but that is easily fixed </p></li>\n</ul>",
      "votes": 9,
      "replies": []
    },
    {
      "id": 1612347,
      "author_name": "hengck23",
      "author_url": "",
      "post_date": "2021-12-08T19:27:29.317000",
      "content": "<p><a href=\"https://www.kaggle.com/slawekbiel\" target=\"_blank\">@slawekbiel</a> </p>\n<p>maybe you can try this too:<br>\n<a href=\"https://github.com/ruotianluo/adaptis.pytorch/blob/master/notebooks/test_toy_model.ipynb\" target=\"_blank\">https://github.com/ruotianluo/adaptis.pytorch/blob/master/notebooks/test_toy_model.ipynb</a><br>\n<a href=\"https://github.com/saic-vul/adaptis\" target=\"_blank\">https://github.com/saic-vul/adaptis</a></p>\n<p>it looks promising</p>",
      "votes": 8,
      "replies": [
        {
          "id": 1614647,
          "author_name": "Araik Tamazian",
          "author_url": "",
          "post_date": "2021-12-11T11:09:45.473000",
          "content": "<p>Here's adaptis-pytorch dataset if you need it <a href=\"https://www.kaggle.com/atamazian/adaptis-pytorch\" target=\"_blank\">https://www.kaggle.com/atamazian/adaptis-pytorch</a></p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 1605960,
      "author_name": "Slawek Biel",
      "author_url": "",
      "post_date": "2021-12-04T18:27:05.563000",
      "content": "<p>If you wonder about the strange topic title I was trying to connect the <a href=\"https://www.kaggle.com/c/sartorius-cell-instance-segmentation/discussion/286553\" target=\"_blank\">UNet Strikes Back</a> thread with the Cellpose name and … a <a href=\"www.youtube.com/watch?v=GuJQSAiODqI&amp;t=35s\" target=\"_blank\">Madonna song</a><br>\nSorry ;)</p>",
      "votes": 4,
      "replies": [
        {
          "id": 1611372,
          "author_name": "Hannah B",
          "author_url": "",
          "post_date": "2021-12-07T23:02:57",
          "content": "<p>well Kaggle is nothing without it's witty pop culture banter ;)</p>",
          "votes": 2,
          "replies": []
        }
      ]
    },
    {
      "id": 1614881,
      "author_name": "Vinayak Tiwari",
      "author_url": "",
      "post_date": "2021-12-11T14:35:51.523000",
      "content": "<p>hello <a href=\"https://www.kaggle.com/slawekbiel\" target=\"_blank\">@slawekbiel</a> , it was a great post …. looking forward to more posts like this</p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 1612954,
      "author_name": "Shivam Bansal",
      "author_url": "",
      "post_date": "2021-12-09T13:49:41.857000",
      "content": "<p>Hey <a href=\"https://www.kaggle.com/slawekbiel\" target=\"_blank\">@slawekbiel</a> <br>\nYour notebook is very helpful, Thanks for sharing it. </p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 1610418,
      "author_name": "Lupin",
      "author_url": "",
      "post_date": "2021-12-07T07:48:19.397000",
      "content": "<p>Thanks for sharing. I just read the paper of the cellpose.Very brilliant idea of using the image gradient. Also I noticed that the trainning images of cellpose are a lot more ideal than livecell ones.Since the gradient are nicely defined between inside and outside of cells.However livecell images contain litle gradient infomations in cells instead of a lot of noise in the background area. But it's worth a try anyway!</p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 1613416,
      "author_name": "Woprime",
      "author_url": "",
      "post_date": "2021-12-10T00:05:34.540000",
      "content": "<p>Another great post from (one of the) father of detectron2 (in this competition). Thank you for all the great works.</p>",
      "votes": 2,
      "replies": []
    },
    {
      "id": 1611334,
      "author_name": "Araik Tamazian",
      "author_url": "",
      "post_date": "2021-12-07T21:47:52.420000",
      "content": "<p>I've written training notebook for Cellpose, and it works. However, I encountered a strange problem - during inference, I get only zeros for 3 test images. I'm using built-in function <code>train</code>. Any ideas about what is wrong?</p>",
      "votes": 2,
      "replies": [
        {
          "id": 1612494,
          "author_name": "",
          "author_url": "",
          "post_date": "2021-12-09T03:02:01.917000",
          "content": "",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1612732,
          "author_name": "Araik Tamazian",
          "author_url": "",
          "post_date": "2021-12-09T09:04:13.683000",
          "content": "<p>UPD: It's working when I trained model with <code>cellpose</code>  shell command with 500 epochs (default).</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1613629,
          "author_name": "swing",
          "author_url": "",
          "post_date": "2021-12-10T06:47:23.203000",
          "content": "<p>have you ever meet the error when i test the model: ValueError: masks_to_outlines takes 2D or 3D array, not 0D array</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1613728,
          "author_name": "Araik Tamazian",
          "author_url": "",
          "post_date": "2021-12-10T08:30:52.797000",
          "content": "<p>Yes, it means the model can't find masks in training directory. Check if mask files are present in the same folder as training images and have names of \"image_name_masks.tif\".</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 1606475,
      "author_name": "Kamal Das",
      "author_url": "",
      "post_date": "2021-12-05T03:10:12.227000",
      "content": "<p>Also, here is a notebook by <a href=\"https://www.kaggle.com/andrewscholan\" target=\"_blank\">@andrewscholan</a> on how to load Cellpose offline: <br>\n<a href=\"https://www.kaggle.com/andrewscholan/offline-package-wheeler-public\" target=\"_blank\">https://www.kaggle.com/andrewscholan/offline-package-wheeler-public</a></p>",
      "votes": 2,
      "replies": []
    },
    {
      "id": 1614286,
      "author_name": "Amin",
      "author_url": "",
      "post_date": "2021-12-10T21:55:49.303000",
      "content": "<p>Thank you <a href=\"https://www.kaggle.com/slawekbiel\" target=\"_blank\">@slawekbiel</a> for sharing. I am trying to train it locally but I am having this TIFF related error</p>\n<pre><code>File \"/home/.local/lib/python3.8/site-packages/tifffile/tifffile.py\", line 3142, in __init__\n    byteorder = {b'II': '&lt;', b'MM': '&gt;', b'EP': '&lt;'}[header[:2]]\nKeyError: b'\\x89P'\n\nTiffFileError('not a TIFF file')\n</code></pre>\n<p>All the images and masks are converted from png to tiff though, did you face a similar error?</p>\n<h3>UPDATE [SOLVED]:</h3>\n<p>For those who might face the same error, it seems that even if an image is saved with a .tif extension, it might still have a PNG signature and the tifffile can't open it. More about this in <a href=\"https://stackoverflow.com/questions/57315100/how-to-resolve-tifffileerror-not-a-tiff-file-and-byte-problem-with-keyerror-b\" target=\"_blank\">this thread</a>.</p>\n<p>The solution is to create a new folder, read the images with <code>cv2.imread(path)</code>  and resave the images in the new folder with <code>cv2.imwrite(filename, img)</code></p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1606481,
      "author_name": "John Doe",
      "author_url": "",
      "post_date": "2021-12-05T03:15:29.183000",
      "content": "<p>Thank you for sharing!<br>\nSorry for my stupid question, this tool is competitive in this competition?</p>",
      "votes": 0,
      "replies": [
        {
          "id": 1606490,
          "author_name": "John Doe",
          "author_url": "",
          "post_date": "2021-12-05T03:22:12.657000",
          "content": "<p>Sorry I missed your notebook.<br>\nThis is competitive.</p>",
          "votes": 1,
          "replies": []
        }
      ]
    },
    {
      "id": 1606769,
      "author_name": "KAZI SHAMIM SHAHAREAR ISLAM",
      "author_url": "",
      "post_date": "2021-12-05T08:41:50.583000",
      "content": "<p>Thanks for sharing this one</p>",
      "votes": 3,
      "replies": []
    },
    {
      "id": 1606858,
      "author_name": "Okidokinon",
      "author_url": "",
      "post_date": "2021-12-05T10:39:35.853000",
      "content": "<p>Thanks for sharing!</p>",
      "votes": 1,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1605950": "I tried out the [Cellpose](http://www.cellpose.org/). The model is based on U-Net, however rather than training it directly on bitmask targets they first convert them to \"spatial flows\" representations and train on that. This makes segmentation of dense and touching cells more reliable. See a sample output on the fourth image bellow. \n\nIt works well out of the box (without any custom code in training, nor inference) , and gives a better LB score than the other UNet models I've seen shared so far.\n\nAn example infer notebook here: https://www.kaggle.com/slawekbiel/cellpose-inference-307-lb\n\nThanks to the indispensable @hengck23 for mentioning the library on the forum, which made me check it out.\n\n![](https://raw.githubusercontent.com/slawekslex/random/main/cellpose.png)\n\n*Note: I deliberately did not share model weights, nor detailed training instructions at this point of the competition. The cellpose repo has good documentation and examples, so it doesn't take too much work to get a working model.*",
    "1606425": "a few tips:\n\n- the official cellpose expects some min size of the cell (I think it is about 15). if you enlarge your image (for training and testing or as TTA), results can be better\n\n- Unet is easier to ensemble\n\n- if you check your results image posted,  the post processing of cellpose ignore incomplete \"spatial flows\".(check the missing detection). you can improve on that,e.g. after segmenting the easier ones,  you can use another set of threshold, etc. or you can train an iou prediction to decide to keep post processing results. or you can train a post-processing model to convert flow to mask\n\n- cellpose doesn't extend segmentation to the long thin structure, but that is easily fixed ",
    "1612347": "@slawekbiel \n\nmaybe you can try this too:\nhttps://github.com/ruotianluo/adaptis.pytorch/blob/master/notebooks/test_toy_model.ipynb\nhttps://github.com/saic-vul/adaptis\n\nit looks promising",
    "1605960": "If you wonder about the strange topic title I was trying to connect the [UNet Strikes Back](https://www.kaggle.com/c/sartorius-cell-instance-segmentation/discussion/286553) thread with the Cellpose name and ... a [Madonna song](www.youtube.com/watch?v=GuJQSAiODqI&t=35s)\nSorry ;)",
    "1614881": "hello @slawekbiel , it was a great post .... looking forward to more posts like this",
    "1612954": "Hey @slawekbiel \nYour notebook is very helpful, Thanks for sharing it. ",
    "1610418": "Thanks for sharing. I just read the paper of the cellpose.Very brilliant idea of using the image gradient. Also I noticed that the trainning images of cellpose are a lot more ideal than livecell ones.Since the gradient are nicely defined between inside and outside of cells.However livecell images contain litle gradient infomations in cells instead of a lot of noise in the background area. But it's worth a try anyway!",
    "1613416": "Another great post from (one of the) father of detectron2 (in this competition). Thank you for all the great works.",
    "1611334": "I've written training notebook for Cellpose, and it works. However, I encountered a strange problem - during inference, I get only zeros for 3 test images. I'm using built-in function `train`. Any ideas about what is wrong?",
    "1606475": "Also, here is a notebook by @andrewscholan on how to load Cellpose offline: \nhttps://www.kaggle.com/andrewscholan/offline-package-wheeler-public",
    "1614286": "Thank you @slawekbiel for sharing. I am trying to train it locally but I am having this TIFF related error\n```\nFile \"/home/.local/lib/python3.8/site-packages/tifffile/tifffile.py\", line 3142, in __init__\n    byteorder = {b'II': '<', b'MM': '>', b'EP': '<'}[header[:2]]\nKeyError: b'\\x89P'\n\nTiffFileError('not a TIFF file')\n```\nAll the images and masks are converted from png to tiff though, did you face a similar error?\n\n### UPDATE [SOLVED]:\nFor those who might face the same error, it seems that even if an image is saved with a .tif extension, it might still have a PNG signature and the tifffile can't open it. More about this in [this thread](https://stackoverflow.com/questions/57315100/how-to-resolve-tifffileerror-not-a-tiff-file-and-byte-problem-with-keyerror-b).\n\nThe solution is to create a new folder, read the images with `cv2.imread(path)`  and resave the images in the new folder with `cv2.imwrite(filename, img)`\n\n",
    "1606481": "Thank you for sharing!\nSorry for my stupid question, this tool is competitive in this competition?",
    "1606769": "Thanks for sharing this one",
    "1606858": "Thanks for sharing!"
  }
}