{
  "id": 421679,
  "title": "The best way to try out augmentations?",
  "url": "/competitions/google-research-identify-contrails-reduce-global-warming/discussion/421679",
  "author_name": "delai50",
  "post_date": "2023-07-06T09:51:57.860000",
  "votes": 7,
  "comment_count": 2,
  "views": 0,
  "content": "<p>Maybe this is a dumb question but I have been struggle about the correct way of applying augmentations. For the moment I devised 3 ways (all of them applied at train time and based on Albumentations). Let's take for example A.HorizontalFlip + A.Resize to 384:</p>\n<p>Way 1. Apply both augs to image and mask -&gt; Do the forward pass -&gt; Resize back both image and mask to 256 with torch.nn.interpolation -&gt; Do backward pass. Caveat: When I interpolate back the mask I don't get the same mask as original (I mean, without taking into account the HorizontalFlip).</p>\n<p>Way 2. Apply both augs to image and mask -&gt; Do forward pass -&gt; Do backward pass. Caveat: You are doing the backward pass with masks at 384 size but you will be predicting at 256 size.</p>\n<p>Way 3. Apply augs only to image. Caveat: I don't know how to apply rotations to the mask then.</p>\n<p>Do you know a better way to do this?</p>",
  "messages": [
    {
      "id": 2332987,
      "postDate": "2023-07-06T15:14:55.333Z",
      "content": "<p>You can do rotations with albumentations, therefore you want to rotate images and mask together. Ignore resize and normalization, you want to apply this steps after so you don't change the size of the masks.</p>\n<p>Example:</p>\n<p>data = self.transform(image = image, mask = label)<br>\nimage = data['image']<br>\nlabel = data['mask']</p>\n<p>Then you want to resize and normalize your image after this steps. This can be done using torchvision.transforms.Resize and torchvision.transforms.Normalize. This apis are just an example, the logic is the important thing.</p>",
      "rawMarkdown": "You can do rotations with albumentations, therefore you want to rotate images and mask together. Ignore resize and normalization, you want to apply this steps after so you don't change the size of the masks.\n\nExample:\n\ndata = self.transform(image = image, mask = label)\nimage = data['image']\nlabel = data['mask']\n\nThen you want to resize and normalize your image after this steps. This can be done using torchvision.transforms.Resize and torchvision.transforms.Normalize. This apis are just an example, the logic is the important thing.",
      "votes": 7,
      "replies": [
        {
          "id": 2333095,
          "postDate": "2023-07-06T16:38:32.823Z",
          "content": "<p>That makes sense, thanks!</p>",
          "rawMarkdown": "That makes sense, thanks!",
          "votes": 1
        }
      ]
    },
    {
      "id": 2332595,
      "postDate": "2023-07-06T09:51:57.860Z",
      "content": "<p>Maybe this is a dumb question but I have been struggle about the correct way of applying augmentations. For the moment I devised 3 ways (all of them applied at train time and based on Albumentations). Let's take for example A.HorizontalFlip + A.Resize to 384:</p>\n<p>Way 1. Apply both augs to image and mask -&gt; Do the forward pass -&gt; Resize back both image and mask to 256 with torch.nn.interpolation -&gt; Do backward pass. Caveat: When I interpolate back the mask I don't get the same mask as original (I mean, without taking into account the HorizontalFlip).</p>\n<p>Way 2. Apply both augs to image and mask -&gt; Do forward pass -&gt; Do backward pass. Caveat: You are doing the backward pass with masks at 384 size but you will be predicting at 256 size.</p>\n<p>Way 3. Apply augs only to image. Caveat: I don't know how to apply rotations to the mask then.</p>\n<p>Do you know a better way to do this?</p>",
      "rawMarkdown": "Maybe this is a dumb question but I have been struggle about the correct way of applying augmentations. For the moment I devised 3 ways (all of them applied at train time and based on Albumentations). Let's take for example A.HorizontalFlip + A.Resize to 384:\n\nWay 1. Apply both augs to image and mask -> Do the forward pass -> Resize back both image and mask to 256 with torch.nn.interpolation -> Do backward pass. Caveat: When I interpolate back the mask I don't get the same mask as original (I mean, without taking into account the HorizontalFlip).\n\nWay 2. Apply both augs to image and mask -> Do forward pass -> Do backward pass. Caveat: You are doing the backward pass with masks at 384 size but you will be predicting at 256 size.\n\nWay 3. Apply augs only to image. Caveat: I don't know how to apply rotations to the mask then.\n\nDo you know a better way to do this?",
      "votes": 7
    }
  ],
  "comments": [
    {
      "id": 2332987,
      "author_name": "Martin Kovacevic Buvinic",
      "author_url": "",
      "post_date": "2023-07-06T15:14:55.333000",
      "content": "<p>You can do rotations with albumentations, therefore you want to rotate images and mask together. Ignore resize and normalization, you want to apply this steps after so you don't change the size of the masks.</p>\n<p>Example:</p>\n<p>data = self.transform(image = image, mask = label)<br>\nimage = data['image']<br>\nlabel = data['mask']</p>\n<p>Then you want to resize and normalize your image after this steps. This can be done using torchvision.transforms.Resize and torchvision.transforms.Normalize. This apis are just an example, the logic is the important thing.</p>",
      "votes": 7,
      "replies": [
        {
          "id": 2333095,
          "author_name": "delai50",
          "author_url": "",
          "post_date": "2023-07-06T16:38:32.823000",
          "content": "<p>That makes sense, thanks!</p>",
          "votes": 1,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "2332987": "You can do rotations with albumentations, therefore you want to rotate images and mask together. Ignore resize and normalization, you want to apply this steps after so you don't change the size of the masks.\n\nExample:\n\ndata = self.transform(image = image, mask = label)\nimage = data['image']\nlabel = data['mask']\n\nThen you want to resize and normalize your image after this steps. This can be done using torchvision.transforms.Resize and torchvision.transforms.Normalize. This apis are just an example, the logic is the important thing.",
    "2332595": "Maybe this is a dumb question but I have been struggle about the correct way of applying augmentations. For the moment I devised 3 ways (all of them applied at train time and based on Albumentations). Let's take for example A.HorizontalFlip + A.Resize to 384:\n\nWay 1. Apply both augs to image and mask -> Do the forward pass -> Resize back both image and mask to 256 with torch.nn.interpolation -> Do backward pass. Caveat: When I interpolate back the mask I don't get the same mask as original (I mean, without taking into account the HorizontalFlip).\n\nWay 2. Apply both augs to image and mask -> Do forward pass -> Do backward pass. Caveat: You are doing the backward pass with masks at 384 size but you will be predicting at 256 size.\n\nWay 3. Apply augs only to image. Caveat: I don't know how to apply rotations to the mask then.\n\nDo you know a better way to do this?"
  }
}