{
  "id": 346726,
  "title": "Error memory",
  "url": "/competitions/hubmap-organ-segmentation/discussion/346726",
  "author_name": "",
  "post_date": "2022-08-21T02:09:45.449443300Z",
  "votes": 1,
  "comment_count": 1,
  "views": 0,
  "content": "<p>Hello</p>\n<p>When I run my <a href=\"https://www.kaggle.com/code/maximofn/hubmap-submission/notebook?scriptVersionId=103805616\" target=\"_blank\">submissionnotebook</a> I get the error \"Your notebook tried to allocate more memory than is available.0\" when I run the function </p>\n<pre><code>def mask2rle(mask):\n    '''\n    mask: numpy array, 1 - mask, 0 - background\n    Returns the length of the run as a string\n    '''\n    pixels = mask.T.flatten()\n    pixels = np.concatenate([[[0], pixels, [0]]])\n    runs = np.where(pixels[1:] != pixels[:-1])[0] + 1\n    executions[1::2] -= executions[::2]\n    return ' '.join(str(x) for x in runs)\n</code></pre>\n<p>Does anyone know why this might be?</p>\n<p>Thanks in advance</p>\n<p>Best regards</p>",
  "messages": [
    {
      "id": "1907704",
      "postDate": "08/21/2022 02:09:45",
      "content": "<p>Hello</p>\n<p>When I run my <a href=\"https://www.kaggle.com/code/maximofn/hubmap-submission/notebook?scriptVersionId=103805616\" target=\"_blank\">submissionnotebook</a> I get the error \"Your notebook tried to allocate more memory than is available.0\" when I run the function </p>\n<pre><code>def mask2rle(mask):\n    '''\n    mask: numpy array, 1 - mask, 0 - background\n    Returns the length of the run as a string\n    '''\n    pixels = mask.T.flatten()\n    pixels = np.concatenate([[[0], pixels, [0]]])\n    runs = np.where(pixels[1:] != pixels[:-1])[0] + 1\n    executions[1::2] -= executions[::2]\n    return ' '.join(str(x) for x in runs)\n</code></pre>\n<p>Does anyone know why this might be?</p>\n<p>Thanks in advance</p>\n<p>Best regards</p>",
      "rawMarkdown": "Hello\n\nWhen I run my [submissionnotebook](https://www.kaggle.com/code/maximofn/hubmap-submission/notebook?scriptVersionId=103805616) I get the error \"Your notebook tried to allocate more memory than is available.0\" when I run the function \n\n```python\ndef mask2rle(mask):\n    '''\n    mask: numpy array, 1 - mask, 0 - background\n    Returns the length of the run as a string\n    '''\n    pixels = mask.T.flatten()\n    pixels = np.concatenate([[[0], pixels, [0]]])\n    runs = np.where(pixels[1:] != pixels[:-1])[0] + 1\n    executions[1::2] -= executions[::2]\n    return ' '.join(str(x) for x in runs)\n```\n\nDoes anyone know why this might be?\n\nThanks in advance\n\nBest regards",
      "votes": null
    },
    {
      "id": "1909157",
      "postDate": "08/22/2022 11:35:14",
      "content": "<p>I've figured out what it is, in case anyone else gets it.</p>\n<p>My model returns the mask in one hot encodding format, that is, it returns a size tensor [batch size, 2, w, h]. I converted that tensor to Numpy and calculated the rle with the function I put. As it was such a big matrix, it gave the error</p>\n<p>Now, when I get the model mask, I change the size to [batch size, 1, w, h], convert it to Numpy, calculate the rle and I don't have any more problems.</p>",
      "rawMarkdown": "I've figured out what it is, in case anyone else gets it.\n\nMy model returns the mask in one hot encodding format, that is, it returns a size tensor [batch size, 2, w, h]. I converted that tensor to Numpy and calculated the rle with the function I put. As it was such a big matrix, it gave the error\n\nNow, when I get the model mask, I change the size to [batch size, 1, w, h], convert it to Numpy, calculate the rle and I don't have any more problems.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1909157,
      "author_name": "maximofn",
      "author_url": "",
      "post_date": "08/22/2022 11:35:14",
      "content": "<p>I've figured out what it is, in case anyone else gets it.</p>\n<p>My model returns the mask in one hot encodding format, that is, it returns a size tensor [batch size, 2, w, h]. I converted that tensor to Numpy and calculated the rle with the function I put. As it was such a big matrix, it gave the error</p>\n<p>Now, when I get the model mask, I change the size to [batch size, 1, w, h], convert it to Numpy, calculate the rle and I don't have any more problems.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1907704": "Hello\n\nWhen I run my [submissionnotebook](https://www.kaggle.com/code/maximofn/hubmap-submission/notebook?scriptVersionId=103805616) I get the error \"Your notebook tried to allocate more memory than is available.0\" when I run the function \n\n```python\ndef mask2rle(mask):\n    '''\n    mask: numpy array, 1 - mask, 0 - background\n    Returns the length of the run as a string\n    '''\n    pixels = mask.T.flatten()\n    pixels = np.concatenate([[[0], pixels, [0]]])\n    runs = np.where(pixels[1:] != pixels[:-1])[0] + 1\n    executions[1::2] -= executions[::2]\n    return ' '.join(str(x) for x in runs)\n```\n\nDoes anyone know why this might be?\n\nThanks in advance\n\nBest regards",
    "1909157": "I've figured out what it is, in case anyone else gets it.\n\nMy model returns the mask in one hot encodding format, that is, it returns a size tensor [batch size, 2, w, h]. I converted that tensor to Numpy and calculated the rle with the function I put. As it was such a big matrix, it gave the error\n\nNow, when I get the model mask, I change the size to [batch size, 1, w, h], convert it to Numpy, calculate the rle and I don't have any more problems."
  },
  "source": "meta"
}