{
  "id": 215328,
  "title": "CUDA Out of memory when I input a single image. ",
  "url": "/competitions/vinbigdata-chest-xray-abnormalities-detection/discussion/215328",
  "author_name": "Pawan Bhandarkar",
  "post_date": "2021-01-29T13:20:02.838000",
  "votes": 3,
  "comment_count": 1,
  "views": 0,
  "content": "<p>Disclaimer: I am fairly new to PyTorch and this is the first time I try to develop a model from scratch. </p>\n<p>I'm learning a bit about UNET and I tried implementing it from scratch as defined by the network architecture section of <a href=\"https://arxiv.org/abs/1505.04597\" target=\"_blank\">the original paper</a>.</p>\n<p><a href=\"https://www.kaggle.com/pawanbhandarkar/unet-experiments-cuda-out-of-memory\" target=\"_blank\">My code is here</a> and as you can see, it is very simple. I only feed in ONE sample image to check if the output sizes are as expected, but I get the following error: </p>\n<pre><code>RuntimeError: CUDA out of memory. Tried to allocate 1006.00 MiB (GPU 0; 15.90 GiB total capacity; 14.77 GiB already allocated; 339.75 MiB free; 14.81 GiB reserved in total by PyTorch)\n</code></pre>\n<p>I tried to find some solutions online (including previous Kaggle discussions) but most of them say to decrease batch size during training. But I do not understand what \"batch size\" means in the context of my code. My only input is a single tensor of shape  <code>torch.Size([1, 1, 3159, 2954])</code></p>\n<p>Please help!</p>",
  "messages": [
    {
      "id": 1176036,
      "postDate": "2021-01-29T13:20:02.840Z",
      "content": "<p>Disclaimer: I am fairly new to PyTorch and this is the first time I try to develop a model from scratch. </p>\n<p>I'm learning a bit about UNET and I tried implementing it from scratch as defined by the network architecture section of <a href=\"https://arxiv.org/abs/1505.04597\" target=\"_blank\">the original paper</a>.</p>\n<p><a href=\"https://www.kaggle.com/pawanbhandarkar/unet-experiments-cuda-out-of-memory\" target=\"_blank\">My code is here</a> and as you can see, it is very simple. I only feed in ONE sample image to check if the output sizes are as expected, but I get the following error: </p>\n<pre><code>RuntimeError: CUDA out of memory. Tried to allocate 1006.00 MiB (GPU 0; 15.90 GiB total capacity; 14.77 GiB already allocated; 339.75 MiB free; 14.81 GiB reserved in total by PyTorch)\n</code></pre>\n<p>I tried to find some solutions online (including previous Kaggle discussions) but most of them say to decrease batch size during training. But I do not understand what \"batch size\" means in the context of my code. My only input is a single tensor of shape  <code>torch.Size([1, 1, 3159, 2954])</code></p>\n<p>Please help!</p>",
      "rawMarkdown": "Disclaimer: I am fairly new to PyTorch and this is the first time I try to develop a model from scratch. \n\nI'm learning a bit about UNET and I tried implementing it from scratch as defined by the network architecture section of [the original paper](https://arxiv.org/abs/1505.04597).\n\n[My code is here](https://www.kaggle.com/pawanbhandarkar/unet-experiments-cuda-out-of-memory) and as you can see, it is very simple. I only feed in ONE sample image to check if the output sizes are as expected, but I get the following error: \n\n```\nRuntimeError: CUDA out of memory. Tried to allocate 1006.00 MiB (GPU 0; 15.90 GiB total capacity; 14.77 GiB already allocated; 339.75 MiB free; 14.81 GiB reserved in total by PyTorch)\n```\n\nI tried to find some solutions online (including previous Kaggle discussions) but most of them say to decrease batch size during training. But I do not understand what \"batch size\" means in the context of my code. My only input is a single tensor of shape  `torch.Size([1, 1, 3159, 2954])`\n\nPlease help!\n",
      "votes": 3
    },
    {
      "id": 1177786,
      "postDate": "2021-01-30T13:55:14.030Z",
      "content": "<p>Also quite a beginner here, but using DataLoader should be more efficient in terms of memory usage. Also the resolution of your image is quite high, downsampling should help. Good luck!</p>",
      "rawMarkdown": "Also quite a beginner here, but using DataLoader should be more efficient in terms of memory usage. Also the resolution of your image is quite high, downsampling should help. Good luck!"
    }
  ],
  "comments": [
    {
      "id": 1177786,
      "author_name": "Hannes Öhler",
      "author_url": "",
      "post_date": "2021-01-30T13:55:14.030000",
      "content": "<p>Also quite a beginner here, but using DataLoader should be more efficient in terms of memory usage. Also the resolution of your image is quite high, downsampling should help. Good luck!</p>",
      "votes": 0,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1176036": "Disclaimer: I am fairly new to PyTorch and this is the first time I try to develop a model from scratch. \n\nI'm learning a bit about UNET and I tried implementing it from scratch as defined by the network architecture section of [the original paper](https://arxiv.org/abs/1505.04597).\n\n[My code is here](https://www.kaggle.com/pawanbhandarkar/unet-experiments-cuda-out-of-memory) and as you can see, it is very simple. I only feed in ONE sample image to check if the output sizes are as expected, but I get the following error: \n\n```\nRuntimeError: CUDA out of memory. Tried to allocate 1006.00 MiB (GPU 0; 15.90 GiB total capacity; 14.77 GiB already allocated; 339.75 MiB free; 14.81 GiB reserved in total by PyTorch)\n```\n\nI tried to find some solutions online (including previous Kaggle discussions) but most of them say to decrease batch size during training. But I do not understand what \"batch size\" means in the context of my code. My only input is a single tensor of shape  `torch.Size([1, 1, 3159, 2954])`\n\nPlease help!\n",
    "1177786": "Also quite a beginner here, but using DataLoader should be more efficient in terms of memory usage. Also the resolution of your image is quite high, downsampling should help. Good luck!"
  }
}