{
  "id": 163856,
  "title": "Progressive Augmentations with Pytorch?",
  "url": "/competitions/siim-isic-melanoma-classification/discussion/163856",
  "author_name": "",
  "post_date": "2020-07-03T17:26:29.961323900Z",
  "votes": null,
  "comment_count": 1,
  "views": 0,
  "content": "<p>Hey everyone! I was wondering if its possible to increase the probability of an augmentation during training? </p>\n\n<p>I found a way to change augmentations during training on the pytorch forums:\n```\nclass MyData(Dataset):\n    def <strong>init</strong>(self):\n        self.images = [TF.to_pil_image(x) for x in torch.ByteTensor(10, 3, 48, 48)]\n        self.set_stage(0) # initial stage</p>\n\n<pre><code>def __getitem__(self, index):\n    image = self.images[index]\n\n    # Just apply your transformations here\n    image = self.crop(image)\n    x = TF.to_tensor(image)\n    return x\n\ndef set_stage(self, stage):\n    if stage == 0:\n        print('Using (32, 32) crops')\n        self.crop = transforms.RandomCrop((32, 32))\n    elif stage == 1:\n        print('Using (28, 28) crops')\n        self.crop = transforms.RandomCrop((28, 28))\n\ndef __len__(self):\n    return len(self.images)\n</code></pre>\n\n<p>loader.dataset.set_stage(1)\n```</p>\n\n<p>However is there a better way than have many stages of training? Thanks! :</p>",
  "messages": [
    {
      "id": "914225",
      "postDate": "07/03/2020 17:26:29",
      "content": "<p>Hey everyone! I was wondering if its possible to increase the probability of an augmentation during training? </p>\n\n<p>I found a way to change augmentations during training on the pytorch forums:\n```\nclass MyData(Dataset):\n    def <strong>init</strong>(self):\n        self.images = [TF.to_pil_image(x) for x in torch.ByteTensor(10, 3, 48, 48)]\n        self.set_stage(0) # initial stage</p>\n\n<pre><code>def __getitem__(self, index):\n    image = self.images[index]\n\n    # Just apply your transformations here\n    image = self.crop(image)\n    x = TF.to_tensor(image)\n    return x\n\ndef set_stage(self, stage):\n    if stage == 0:\n        print('Using (32, 32) crops')\n        self.crop = transforms.RandomCrop((32, 32))\n    elif stage == 1:\n        print('Using (28, 28) crops')\n        self.crop = transforms.RandomCrop((28, 28))\n\ndef __len__(self):\n    return len(self.images)\n</code></pre>\n\n<p>loader.dataset.set_stage(1)\n```</p>\n\n<p>However is there a better way than have many stages of training? Thanks! :</p>",
      "rawMarkdown": "Hey everyone! I was wondering if its possible to increase the probability of an augmentation during training? \n\nI found a way to change augmentations during training on the pytorch forums:\n```\nclass MyData(Dataset):\n    def __init__(self):\n        self.images = [TF.to_pil_image(x) for x in torch.ByteTensor(10, 3, 48, 48)]\n        self.set_stage(0) # initial stage\n        \n    def __getitem__(self, index):\n        image = self.images[index]\n        \n        # Just apply your transformations here\n        image = self.crop(image)\n        x = TF.to_tensor(image)\n        return x\n        \n    def set_stage(self, stage):\n        if stage == 0:\n            print('Using (32, 32) crops')\n            self.crop = transforms.RandomCrop((32, 32))\n        elif stage == 1:\n            print('Using (28, 28) crops')\n            self.crop = transforms.RandomCrop((28, 28))\n        \n    def __len__(self):\n        return len(self.images)\n\n\nloader.dataset.set_stage(1)\n```\n\nHowever is there a better way than have many stages of training? Thanks! :",
      "votes": null
    },
    {
      "id": "915474",
      "postDate": "07/04/2020 19:11:48",
      "content": "<p>I don't really understand the question, you implement Dataset yourself, so you have access to the code which does the augmentaton, what's the issue?</p>",
      "rawMarkdown": "I don't really understand the question, you implement Dataset yourself, so you have access to the code which does the augmentaton, what's the issue?",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 915474,
      "author_name": "jacekpoplawski",
      "author_url": "",
      "post_date": "07/04/2020 19:11:48",
      "content": "<p>I don't really understand the question, you implement Dataset yourself, so you have access to the code which does the augmentaton, what's the issue?</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "914225": "Hey everyone! I was wondering if its possible to increase the probability of an augmentation during training? \n\nI found a way to change augmentations during training on the pytorch forums:\n```\nclass MyData(Dataset):\n    def __init__(self):\n        self.images = [TF.to_pil_image(x) for x in torch.ByteTensor(10, 3, 48, 48)]\n        self.set_stage(0) # initial stage\n        \n    def __getitem__(self, index):\n        image = self.images[index]\n        \n        # Just apply your transformations here\n        image = self.crop(image)\n        x = TF.to_tensor(image)\n        return x\n        \n    def set_stage(self, stage):\n        if stage == 0:\n            print('Using (32, 32) crops')\n            self.crop = transforms.RandomCrop((32, 32))\n        elif stage == 1:\n            print('Using (28, 28) crops')\n            self.crop = transforms.RandomCrop((28, 28))\n        \n    def __len__(self):\n        return len(self.images)\n\n\nloader.dataset.set_stage(1)\n```\n\nHowever is there a better way than have many stages of training? Thanks! :",
    "915474": "I don't really understand the question, you implement Dataset yourself, so you have access to the code which does the augmentaton, what's the issue?"
  },
  "source": "meta"
}