{
  "id": 374031,
  "title": "Questions about augmentation",
  "url": "/competitions/rsna-breast-cancer-detection/discussion/374031",
  "author_name": "nicehzj",
  "post_date": "2022-12-24T22:43:31.673000",
  "votes": 5,
  "comment_count": 8,
  "views": 0,
  "content": "<p>I'm trying to do some augmentation on my pictures.<br>\nI read several codes and now I'm totally confused…<br>\nSo, first step is read a png. e.g., image = PIL.Image.read()<br>\nThen what should I do? Normalization? Augmentation?<br>\nIf I use randomcrop, should I resize the processed image at last?<br>\nAlso I found in some codes using image/255, should I use this?<br>\nCan anyone give me a typical procedure list for this?<br>\nThanks so much!</p>",
  "messages": [
    {
      "id": 2075009,
      "postDate": "2022-12-24T22:43:31.673Z",
      "content": "<p>I'm trying to do some augmentation on my pictures.<br>\nI read several codes and now I'm totally confused…<br>\nSo, first step is read a png. e.g., image = PIL.Image.read()<br>\nThen what should I do? Normalization? Augmentation?<br>\nIf I use randomcrop, should I resize the processed image at last?<br>\nAlso I found in some codes using image/255, should I use this?<br>\nCan anyone give me a typical procedure list for this?<br>\nThanks so much!</p>",
      "rawMarkdown": "I'm trying to do some augmentation on my pictures.\nI read several codes and now I'm totally confused...\nSo, first step is read a png. e.g., image = PIL.Image.read()\nThen what should I do? Normalization? Augmentation?\nIf I use randomcrop, should I resize the processed image at last?\nAlso I found in some codes using image/255, should I use this?\nCan anyone give me a typical procedure list for this?\nThanks so much!",
      "votes": 5
    },
    {
      "id": 2079540,
      "postDate": "2022-12-29T12:08:25.800Z",
      "content": "<p>If you use albumentations an training transformation pipeline could look like this (on CPU):</p>\n<pre><code>trans_train = A.Compose(\n    [\n        A.CoarseDropout(max_holes=, p=),\n        A.VerticalFlip(),\n        A.HorizontalFlip(),\n        A.Normalize(mean=(, , ), std=(, , )),\n        ToTensorV2()\n    ]\n)\n</code></pre>\n<p>Please make sure to use the albumentation demo to search for augmentations and try different parameters and test results:<br>\n<a href=\"https://demo.albumentations.ai/\" target=\"_blank\">https://demo.albumentations.ai/</a></p>",
      "rawMarkdown": "If you use albumentations an training transformation pipeline could look like this (on CPU):\n\n```python\ntrans_train = A.Compose(\n    [\n        A.CoarseDropout(max_holes=12, p=0.25),\n        A.VerticalFlip(),\n        A.HorizontalFlip(),\n        A.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)),\n        ToTensorV2()\n    ]\n)\n```\n\nPlease make sure to use the albumentation demo to search for augmentations and try different parameters and test results:\nhttps://demo.albumentations.ai/",
      "votes": 1
    },
    {
      "id": 2075044,
      "postDate": "2022-12-25T00:59:20.703Z",
      "content": "<p>Yes, use image / 255. It scales the image between 0 and 1 because 255 is the highest value of a uint8 image. </p>",
      "rawMarkdown": "Yes, use image / 255. It scales the image between 0 and 1 because 255 is the highest value of a uint8 image. ",
      "votes": 1,
      "replies": [
        {
          "id": 2075068,
          "postDate": "2022-12-25T02:55:54.107Z",
          "content": "<p>Thanks!<br>\nI found that if I use the normalize from albumentations, it will automatically be divided by 255.<br>\nHow about randomcrop? should I resize at last then normalize and totensor?</p>",
          "rawMarkdown": "Thanks!\nI found that if I use the normalize from albumentations, it will automatically be divided by 255.\nHow about randomcrop? should I resize at last then normalize and totensor?",
          "replies": [
            {
              "id": 2075370,
              "postDate": "2022-12-25T10:01:54.990Z",
              "content": "<p>Most people normalise as the final step if they are doing their augmentations on the CPU, because then the augmentations are done on uint8s rather than floats, which is faster (usually). However, for GPU, many people normalize first and do their augmentations in floating point.</p>\n<p>You can randomcrop during training, yes.</p>\n<p>TBH if I was getting used to augmentations for the first time, and using Pytorch, I'd probably use the new Pytorch augmentations API which has support for randaugment and autoaugment.</p>",
              "rawMarkdown": "Most people normalise as the final step if they are doing their augmentations on the CPU, because then the augmentations are done on uint8s rather than floats, which is faster (usually). However, for GPU, many people normalize first and do their augmentations in floating point.\n\nYou can randomcrop during training, yes.\n\nTBH if I was getting used to augmentations for the first time, and using Pytorch, I'd probably use the new Pytorch augmentations API which has support for randaugment and autoaugment.",
              "votes": 3
            },
            {
              "id": 2075429,
              "postDate": "2022-12-25T11:53:49.480Z",
              "content": "<p>Many many thanks!</p>",
              "rawMarkdown": "Many many thanks!"
            }
          ]
        }
      ]
    },
    {
      "id": 2075815,
      "postDate": "2022-12-25T23:16:02.110Z",
      "content": "<p><a href=\"https://www.ncbi.nlm.nih.gov/pmc/articles/PMC9147240/\" target=\"_blank\">https://www.ncbi.nlm.nih.gov/pmc/articles/PMC9147240/</a><br>\nImage Augmentation Techniques for Mammogram Analysis</p>",
      "rawMarkdown": "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC9147240/\nImage Augmentation Techniques for Mammogram Analysis",
      "votes": 2,
      "replies": [
        {
          "id": 2075837,
          "postDate": "2022-12-26T00:15:07.523Z",
          "content": "<p>Thank you so much!!</p>",
          "rawMarkdown": "Thank you so much!!"
        }
      ]
    },
    {
      "id": 2127623,
      "postDate": "2023-02-03T02:06:50.547Z",
      "content": "<p>See also link to my notebook for an alternative library to perform augmentations: <a href=\"https://www.kaggle.com/code/anttiisosalo/solt-based-image-augs-rsna-bc-detection\" target=\"_blank\">https://www.kaggle.com/code/anttiisosalo/solt-based-image-augs-rsna-bc-detection</a></p>",
      "rawMarkdown": "See also link to my notebook for an alternative library to perform augmentations: https://www.kaggle.com/code/anttiisosalo/solt-based-image-augs-rsna-bc-detection"
    }
  ],
  "comments": [
    {
      "id": 2079540,
      "author_name": "Ali Abdin",
      "author_url": "",
      "post_date": "2022-12-29T12:08:25.800000",
      "content": "<p>If you use albumentations an training transformation pipeline could look like this (on CPU):</p>\n<pre><code>trans_train = A.Compose(\n    [\n        A.CoarseDropout(max_holes=, p=),\n        A.VerticalFlip(),\n        A.HorizontalFlip(),\n        A.Normalize(mean=(, , ), std=(, , )),\n        ToTensorV2()\n    ]\n)\n</code></pre>\n<p>Please make sure to use the albumentation demo to search for augmentations and try different parameters and test results:<br>\n<a href=\"https://demo.albumentations.ai/\" target=\"_blank\">https://demo.albumentations.ai/</a></p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 2075044,
      "author_name": "Ivan Aerlic",
      "author_url": "",
      "post_date": "2022-12-25T00:59:20.703000",
      "content": "<p>Yes, use image / 255. It scales the image between 0 and 1 because 255 is the highest value of a uint8 image. </p>",
      "votes": 1,
      "replies": [
        {
          "id": 2075068,
          "author_name": "nicehzj",
          "author_url": "",
          "post_date": "2022-12-25T02:55:54.107000",
          "content": "<p>Thanks!<br>\nI found that if I use the normalize from albumentations, it will automatically be divided by 255.<br>\nHow about randomcrop? should I resize at last then normalize and totensor?</p>",
          "votes": 0,
          "replies": [
            {
              "id": 2075370,
              "author_name": "James Howard",
              "author_url": "",
              "post_date": "2022-12-25T10:01:54.990000",
              "content": "<p>Most people normalise as the final step if they are doing their augmentations on the CPU, because then the augmentations are done on uint8s rather than floats, which is faster (usually). However, for GPU, many people normalize first and do their augmentations in floating point.</p>\n<p>You can randomcrop during training, yes.</p>\n<p>TBH if I was getting used to augmentations for the first time, and using Pytorch, I'd probably use the new Pytorch augmentations API which has support for randaugment and autoaugment.</p>",
              "votes": 3,
              "replies": []
            },
            {
              "id": 2075429,
              "author_name": "nicehzj",
              "author_url": "",
              "post_date": "2022-12-25T11:53:49.480000",
              "content": "<p>Many many thanks!</p>",
              "votes": 0,
              "replies": []
            }
          ]
        }
      ]
    },
    {
      "id": 2075815,
      "author_name": "hengck23",
      "author_url": "",
      "post_date": "2022-12-25T23:16:02.110000",
      "content": "<p><a href=\"https://www.ncbi.nlm.nih.gov/pmc/articles/PMC9147240/\" target=\"_blank\">https://www.ncbi.nlm.nih.gov/pmc/articles/PMC9147240/</a><br>\nImage Augmentation Techniques for Mammogram Analysis</p>",
      "votes": 2,
      "replies": [
        {
          "id": 2075837,
          "author_name": "nicehzj",
          "author_url": "",
          "post_date": "2022-12-26T00:15:07.523000",
          "content": "<p>Thank you so much!!</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 2127623,
      "author_name": "Antti Isosalo",
      "author_url": "",
      "post_date": "2023-02-03T02:06:50.547000",
      "content": "<p>See also link to my notebook for an alternative library to perform augmentations: <a href=\"https://www.kaggle.com/code/anttiisosalo/solt-based-image-augs-rsna-bc-detection\" target=\"_blank\">https://www.kaggle.com/code/anttiisosalo/solt-based-image-augs-rsna-bc-detection</a></p>",
      "votes": 0,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "2075009": "I'm trying to do some augmentation on my pictures.\nI read several codes and now I'm totally confused...\nSo, first step is read a png. e.g., image = PIL.Image.read()\nThen what should I do? Normalization? Augmentation?\nIf I use randomcrop, should I resize the processed image at last?\nAlso I found in some codes using image/255, should I use this?\nCan anyone give me a typical procedure list for this?\nThanks so much!",
    "2079540": "If you use albumentations an training transformation pipeline could look like this (on CPU):\n\n```python\ntrans_train = A.Compose(\n    [\n        A.CoarseDropout(max_holes=12, p=0.25),\n        A.VerticalFlip(),\n        A.HorizontalFlip(),\n        A.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)),\n        ToTensorV2()\n    ]\n)\n```\n\nPlease make sure to use the albumentation demo to search for augmentations and try different parameters and test results:\nhttps://demo.albumentations.ai/",
    "2075044": "Yes, use image / 255. It scales the image between 0 and 1 because 255 is the highest value of a uint8 image. ",
    "2075815": "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC9147240/\nImage Augmentation Techniques for Mammogram Analysis",
    "2127623": "See also link to my notebook for an alternative library to perform augmentations: https://www.kaggle.com/code/anttiisosalo/solt-based-image-augs-rsna-bc-detection"
  }
}