{
  "id": 369709,
  "title": "Error: image has wrong mode(fast.ai)",
  "url": "/competitions/rsna-breast-cancer-detection/discussion/369709",
  "author_name": "Hemanth S",
  "post_date": "2022-12-01T06:26:33.123000",
  "votes": 0,
  "comment_count": 1,
  "views": 0,
  "content": "<p>I'm facing this \"image has wrong mode\" error while trying to create dataloader using fast.ai. I created datablock using the following code.<br>\n<code>dblock = DataBlock(blocks    = (ImageBlock(PILDicom), CategoryBlock),\n                   get_items = get_dicom_files,\n                   get_y     = label_func,\n                   splitter  = RandomSplitter(),\n                   item_tfms = Resize(224)\n                   )</code><br>\nI tried searching internet and found a solution to use resample=Image.NEAREST and modified my code to following:</p>\n<p><code>dblock = DataBlock(blocks    = (ImageBlock(PILDicom), CategoryBlock),\n                   get_items = get_dicom_files,\n                   get_y     = label_func,\n                   splitter  = RandomSplitter(),\n                   item_tfms = [Resize(size= 224, resamples= (Image.NEAREST,0))]\n                   )</code><br>\nThis resolved the error but my images are not at all useful for training. Does any know a better way to resolve the error?</p>\n<p>Sample Images after resolving the error:</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1956254%2Ff2a34a19c7c6d8e5c45058e1d5fd8fb3%2FScreenshot%20(190).png?generation=1669875974584421&amp;alt=media\" alt=\"\"></p>",
  "messages": [
    {
      "id": 2051007,
      "postDate": "2022-12-01T06:32:59.840Z",
      "content": "<p>Hey <a href=\"https://www.kaggle.com/hemanth012\" target=\"_blank\">@hemanth012</a>! Here is how to fix this: <a href=\"https://forums.fast.ai/t/fastai2-problems-with-medical-images-dicom/76138\" target=\"_blank\">https://forums.fast.ai/t/fastai2-problems-with-medical-images-dicom/76138</a></p>\n<p>Hope this helps! 🙂</p>",
      "rawMarkdown": "Hey @hemanth012! Here is how to fix this: https://forums.fast.ai/t/fastai2-problems-with-medical-images-dicom/76138\n\nHope this helps! 🙂",
      "votes": 1
    },
    {
      "id": 2050998,
      "postDate": "2022-12-01T06:26:33.123Z",
      "content": "<p>I'm facing this \"image has wrong mode\" error while trying to create dataloader using fast.ai. I created datablock using the following code.<br>\n<code>dblock = DataBlock(blocks    = (ImageBlock(PILDicom), CategoryBlock),\n                   get_items = get_dicom_files,\n                   get_y     = label_func,\n                   splitter  = RandomSplitter(),\n                   item_tfms = Resize(224)\n                   )</code><br>\nI tried searching internet and found a solution to use resample=Image.NEAREST and modified my code to following:</p>\n<p><code>dblock = DataBlock(blocks    = (ImageBlock(PILDicom), CategoryBlock),\n                   get_items = get_dicom_files,\n                   get_y     = label_func,\n                   splitter  = RandomSplitter(),\n                   item_tfms = [Resize(size= 224, resamples= (Image.NEAREST,0))]\n                   )</code><br>\nThis resolved the error but my images are not at all useful for training. Does any know a better way to resolve the error?</p>\n<p>Sample Images after resolving the error:</p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1956254%2Ff2a34a19c7c6d8e5c45058e1d5fd8fb3%2FScreenshot%20(190).png?generation=1669875974584421&amp;alt=media\" alt=\"\"></p>",
      "rawMarkdown": "I'm facing this \"image has wrong mode\" error while trying to create dataloader using fast.ai. I created datablock using the following code.\n`dblock = DataBlock(blocks    = (ImageBlock(PILDicom), CategoryBlock),\n                   get_items = get_dicom_files,\n                   get_y     = label_func,\n                   splitter  = RandomSplitter(),\n                   item_tfms = Resize(224)\n                   )`\nI tried searching internet and found a solution to use resample=Image.NEAREST and modified my code to following:\n\n`dblock = DataBlock(blocks    = (ImageBlock(PILDicom), CategoryBlock),\n                   get_items = get_dicom_files,\n                   get_y     = label_func,\n                   splitter  = RandomSplitter(),\n                   item_tfms = [Resize(size= 224, resamples= (Image.NEAREST,0))]\n                   )`\nThis resolved the error but my images are not at all useful for training. Does any know a better way to resolve the error?\n\nSample Images after resolving the error:\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1956254%2Ff2a34a19c7c6d8e5c45058e1d5fd8fb3%2FScreenshot%20(190).png?generation=1669875974584421&alt=media)"
    }
  ],
  "comments": [
    {
      "id": 2051007,
      "author_name": "Radek Osmulski",
      "author_url": "",
      "post_date": "2022-12-01T06:32:59.840000",
      "content": "<p>Hey <a href=\"https://www.kaggle.com/hemanth012\" target=\"_blank\">@hemanth012</a>! Here is how to fix this: <a href=\"https://forums.fast.ai/t/fastai2-problems-with-medical-images-dicom/76138\" target=\"_blank\">https://forums.fast.ai/t/fastai2-problems-with-medical-images-dicom/76138</a></p>\n<p>Hope this helps! 🙂</p>",
      "votes": 1,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "2051007": "Hey @hemanth012! Here is how to fix this: https://forums.fast.ai/t/fastai2-problems-with-medical-images-dicom/76138\n\nHope this helps! 🙂",
    "2050998": "I'm facing this \"image has wrong mode\" error while trying to create dataloader using fast.ai. I created datablock using the following code.\n`dblock = DataBlock(blocks    = (ImageBlock(PILDicom), CategoryBlock),\n                   get_items = get_dicom_files,\n                   get_y     = label_func,\n                   splitter  = RandomSplitter(),\n                   item_tfms = Resize(224)\n                   )`\nI tried searching internet and found a solution to use resample=Image.NEAREST and modified my code to following:\n\n`dblock = DataBlock(blocks    = (ImageBlock(PILDicom), CategoryBlock),\n                   get_items = get_dicom_files,\n                   get_y     = label_func,\n                   splitter  = RandomSplitter(),\n                   item_tfms = [Resize(size= 224, resamples= (Image.NEAREST,0))]\n                   )`\nThis resolved the error but my images are not at all useful for training. Does any know a better way to resolve the error?\n\nSample Images after resolving the error:\n\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1956254%2Ff2a34a19c7c6d8e5c45058e1d5fd8fb3%2FScreenshot%20(190).png?generation=1669875974584421&alt=media)"
  }
}