{
  "id": 229451,
  "title": "HPA masks not detected",
  "url": "/competitions/hpa-single-cell-image-classification/discussion/229451",
  "author_name": "glopezzz",
  "post_date": "2021-03-30T08:36:32.258000",
  "votes": 1,
  "comment_count": 2,
  "views": 0,
  "content": "<p>Hi everyone.</p>\n<p>I'm having this issue with HPA <code>label_cell()</code> function, as it sometimes doesn't detect any cells.</p>\n<p>The code looks like this:</p>\n<pre><code>batch_size = 24\n\nfor i in tq.tqdm(range(0, data_size, batch_size), position=0, leave=True):\n\n    start = i\n    end = min(len(data_df), start + batch_size)\n    _, _, blue_batch, rgb_batch = load_images(data_df[start:end])\n    nuc_segmentations = segmentator.pred_nuclei(blue_batch)\n    cell_segmentations = segmentator.pred_cells(rgb_batch, precombined=True)\n    j=0\n    for data_id, nuc_seg, cell_seg in zip(data_df.ID.to_list()[start:end], nuc_segmentations, cell_segmentations):\n        _, image_mask = utils.label_cell(nuc_seg, cell_seg)\n        numbers = list(np.unique(image_mask)[1:])\n        if len(numbers) == 0:\n            print('Undetected Cells')\n</code></pre>\n<p>Where image_mask returns the masks that represent each cell in the image with integers where 0 is an empty space. Sometimes I only get a 0…</p>\n<p>Has this happened to you guys? <br>\nIs there any reason to why this happens?<br>\nIs there any solution?</p>\n<p>I'm actually gonna leave the <code>load_images()</code> function here in case u want to look at it:</p>\n<pre><code>def load_images(df : pd.DataFrame, root='../input/hpa-single-cell-image-classification/test/'):\n    blue = []\n    rgb = []\n    blue_scaled = []\n    rgb_scaled = []\n    for i, row in df.iterrows():\n        r = os.path.join(root, f'{row.ID}_red.png')\n        y = os.path.join(root, f'{row.ID}_yellow.png')\n        b = os.path.join(root, f'{row.ID}_blue.png')\n        r = cv2.imread(r, 0)\n        y = cv2.imread(y, 0)\n        b = cv2.imread(b, 0)\n        blue_image = cv2.resize(b, (512, 512))\n        rgb_image = cv2.resize(np.stack((r, y, b), axis=2), (512, 512))\n        blue.append(blue_image)\n        blue_scaled.append(blue_image/255.)\n        rgb.append(rgb_image)\n        rgb_scaled.append(rgb_image/255.)\n\n    return blue, rgb, blue_scaled, rgb_scaled\n</code></pre>\n<p>Also the notebook is <a href=\"https://www.kaggle.com/glopezzz/faster-classification-and-submission\" target=\"_blank\">Faster classification and submission</a></p>\n<p>I left some plots that show the problem clearly in this git issue, please check it out:<br>\n<a href=\"https://github.com/CellProfiling/HPA-Cell-Segmentation/issues/20\" target=\"_blank\">Mask not working</a></p>\n<p>Thank you in advance :)</p>",
  "messages": [
    {
      "id": 1256786,
      "postDate": "2021-03-30T08:36:32.257Z",
      "content": "<p>Hi everyone.</p>\n<p>I'm having this issue with HPA <code>label_cell()</code> function, as it sometimes doesn't detect any cells.</p>\n<p>The code looks like this:</p>\n<pre><code>batch_size = 24\n\nfor i in tq.tqdm(range(0, data_size, batch_size), position=0, leave=True):\n\n    start = i\n    end = min(len(data_df), start + batch_size)\n    _, _, blue_batch, rgb_batch = load_images(data_df[start:end])\n    nuc_segmentations = segmentator.pred_nuclei(blue_batch)\n    cell_segmentations = segmentator.pred_cells(rgb_batch, precombined=True)\n    j=0\n    for data_id, nuc_seg, cell_seg in zip(data_df.ID.to_list()[start:end], nuc_segmentations, cell_segmentations):\n        _, image_mask = utils.label_cell(nuc_seg, cell_seg)\n        numbers = list(np.unique(image_mask)[1:])\n        if len(numbers) == 0:\n            print('Undetected Cells')\n</code></pre>\n<p>Where image_mask returns the masks that represent each cell in the image with integers where 0 is an empty space. Sometimes I only get a 0…</p>\n<p>Has this happened to you guys? <br>\nIs there any reason to why this happens?<br>\nIs there any solution?</p>\n<p>I'm actually gonna leave the <code>load_images()</code> function here in case u want to look at it:</p>\n<pre><code>def load_images(df : pd.DataFrame, root='../input/hpa-single-cell-image-classification/test/'):\n    blue = []\n    rgb = []\n    blue_scaled = []\n    rgb_scaled = []\n    for i, row in df.iterrows():\n        r = os.path.join(root, f'{row.ID}_red.png')\n        y = os.path.join(root, f'{row.ID}_yellow.png')\n        b = os.path.join(root, f'{row.ID}_blue.png')\n        r = cv2.imread(r, 0)\n        y = cv2.imread(y, 0)\n        b = cv2.imread(b, 0)\n        blue_image = cv2.resize(b, (512, 512))\n        rgb_image = cv2.resize(np.stack((r, y, b), axis=2), (512, 512))\n        blue.append(blue_image)\n        blue_scaled.append(blue_image/255.)\n        rgb.append(rgb_image)\n        rgb_scaled.append(rgb_image/255.)\n\n    return blue, rgb, blue_scaled, rgb_scaled\n</code></pre>\n<p>Also the notebook is <a href=\"https://www.kaggle.com/glopezzz/faster-classification-and-submission\" target=\"_blank\">Faster classification and submission</a></p>\n<p>I left some plots that show the problem clearly in this git issue, please check it out:<br>\n<a href=\"https://github.com/CellProfiling/HPA-Cell-Segmentation/issues/20\" target=\"_blank\">Mask not working</a></p>\n<p>Thank you in advance :)</p>",
      "rawMarkdown": "Hi everyone.\n\nI'm having this issue with HPA `label_cell()` function, as it sometimes doesn't detect any cells.\n\nThe code looks like this:\n\n```\nbatch_size = 24\n\nfor i in tq.tqdm(range(0, data_size, batch_size), position=0, leave=True):\n    \n    start = i\n    end = min(len(data_df), start + batch_size)\n    _, _, blue_batch, rgb_batch = load_images(data_df[start:end])\n    nuc_segmentations = segmentator.pred_nuclei(blue_batch)\n    cell_segmentations = segmentator.pred_cells(rgb_batch, precombined=True)\n    j=0\n    for data_id, nuc_seg, cell_seg in zip(data_df.ID.to_list()[start:end], nuc_segmentations, cell_segmentations):\n        _, image_mask = utils.label_cell(nuc_seg, cell_seg)\n        numbers = list(np.unique(image_mask)[1:])\n        if len(numbers) == 0:\n            print('Undetected Cells')\n```\nWhere image_mask returns the masks that represent each cell in the image with integers where 0 is an empty space. Sometimes I only get a 0...\n\nHas this happened to you guys? \nIs there any reason to why this happens?\nIs there any solution?\n\nI'm actually gonna leave the `load_images()` function here in case u want to look at it:\n\n```\ndef load_images(df : pd.DataFrame, root='../input/hpa-single-cell-image-classification/test/'):\n    blue = []\n    rgb = []\n    blue_scaled = []\n    rgb_scaled = []\n    for i, row in df.iterrows():\n        r = os.path.join(root, f'{row.ID}_red.png')\n        y = os.path.join(root, f'{row.ID}_yellow.png')\n        b = os.path.join(root, f'{row.ID}_blue.png')\n        r = cv2.imread(r, 0)\n        y = cv2.imread(y, 0)\n        b = cv2.imread(b, 0)\n        blue_image = cv2.resize(b, (512, 512))\n        rgb_image = cv2.resize(np.stack((r, y, b), axis=2), (512, 512))\n        blue.append(blue_image)\n        blue_scaled.append(blue_image/255.)\n        rgb.append(rgb_image)\n        rgb_scaled.append(rgb_image/255.)\n        \n    return blue, rgb, blue_scaled, rgb_scaled\n```\n\nAlso the notebook is [Faster classification and submission](https://www.kaggle.com/glopezzz/faster-classification-and-submission)\n\nI left some plots that show the problem clearly in this git issue, please check it out:\n[Mask not working](https://github.com/CellProfiling/HPA-Cell-Segmentation/issues/20)\n\nThank you in advance :)",
      "votes": 1
    },
    {
      "id": 1260699,
      "postDate": "2021-04-02T10:55:11.860Z",
      "content": "<p>Hi this is because HPA Segmenter only works with integer values so you can modify your code like:-</p>\n<p>nuc_segmentations = segmentator.pred_nuclei(blue_batch.astype('int32))<br>\n cell_segmentations = segmentator.pred_cells(rgb_batch.astype('int32'), precombined=True)</p>",
      "rawMarkdown": "Hi this is because HPA Segmenter only works with integer values so you can modify your code like:-\n\n nuc_segmentations = segmentator.pred_nuclei(blue_batch.astype('int32))\n cell_segmentations = segmentator.pred_cells(rgb_batch.astype('int32'), precombined=True)",
      "replies": [
        {
          "id": 1264565,
          "postDate": "2021-04-06T08:54:39.223Z",
          "content": "<p>Hii, that's not the problem… I've had issues using both integers and floats.</p>\n<p>I still don't get what the problem might be.</p>",
          "rawMarkdown": "Hii, that's not the problem... I've had issues using both integers and floats.\n\nI still don't get what the problem might be."
        }
      ]
    }
  ],
  "comments": [
    {
      "id": 1260699,
      "author_name": "Shubham Joshi",
      "author_url": "",
      "post_date": "2021-04-02T10:55:11.860000",
      "content": "<p>Hi this is because HPA Segmenter only works with integer values so you can modify your code like:-</p>\n<p>nuc_segmentations = segmentator.pred_nuclei(blue_batch.astype('int32))<br>\n cell_segmentations = segmentator.pred_cells(rgb_batch.astype('int32'), precombined=True)</p>",
      "votes": 0,
      "replies": [
        {
          "id": 1264565,
          "author_name": "glopezzz",
          "author_url": "",
          "post_date": "2021-04-06T08:54:39.223000",
          "content": "<p>Hii, that's not the problem… I've had issues using both integers and floats.</p>\n<p>I still don't get what the problem might be.</p>",
          "votes": 0,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1256786": "Hi everyone.\n\nI'm having this issue with HPA `label_cell()` function, as it sometimes doesn't detect any cells.\n\nThe code looks like this:\n\n```\nbatch_size = 24\n\nfor i in tq.tqdm(range(0, data_size, batch_size), position=0, leave=True):\n    \n    start = i\n    end = min(len(data_df), start + batch_size)\n    _, _, blue_batch, rgb_batch = load_images(data_df[start:end])\n    nuc_segmentations = segmentator.pred_nuclei(blue_batch)\n    cell_segmentations = segmentator.pred_cells(rgb_batch, precombined=True)\n    j=0\n    for data_id, nuc_seg, cell_seg in zip(data_df.ID.to_list()[start:end], nuc_segmentations, cell_segmentations):\n        _, image_mask = utils.label_cell(nuc_seg, cell_seg)\n        numbers = list(np.unique(image_mask)[1:])\n        if len(numbers) == 0:\n            print('Undetected Cells')\n```\nWhere image_mask returns the masks that represent each cell in the image with integers where 0 is an empty space. Sometimes I only get a 0...\n\nHas this happened to you guys? \nIs there any reason to why this happens?\nIs there any solution?\n\nI'm actually gonna leave the `load_images()` function here in case u want to look at it:\n\n```\ndef load_images(df : pd.DataFrame, root='../input/hpa-single-cell-image-classification/test/'):\n    blue = []\n    rgb = []\n    blue_scaled = []\n    rgb_scaled = []\n    for i, row in df.iterrows():\n        r = os.path.join(root, f'{row.ID}_red.png')\n        y = os.path.join(root, f'{row.ID}_yellow.png')\n        b = os.path.join(root, f'{row.ID}_blue.png')\n        r = cv2.imread(r, 0)\n        y = cv2.imread(y, 0)\n        b = cv2.imread(b, 0)\n        blue_image = cv2.resize(b, (512, 512))\n        rgb_image = cv2.resize(np.stack((r, y, b), axis=2), (512, 512))\n        blue.append(blue_image)\n        blue_scaled.append(blue_image/255.)\n        rgb.append(rgb_image)\n        rgb_scaled.append(rgb_image/255.)\n        \n    return blue, rgb, blue_scaled, rgb_scaled\n```\n\nAlso the notebook is [Faster classification and submission](https://www.kaggle.com/glopezzz/faster-classification-and-submission)\n\nI left some plots that show the problem clearly in this git issue, please check it out:\n[Mask not working](https://github.com/CellProfiling/HPA-Cell-Segmentation/issues/20)\n\nThank you in advance :)",
    "1260699": "Hi this is because HPA Segmenter only works with integer values so you can modify your code like:-\n\n nuc_segmentations = segmentator.pred_nuclei(blue_batch.astype('int32))\n cell_segmentations = segmentator.pred_cells(rgb_batch.astype('int32'), precombined=True)"
  }
}