{
  "id": 348471,
  "title": "Does anyone improve their scores through multi-scale training?",
  "url": "/competitions/hubmap-organ-segmentation/discussion/348471",
  "author_name": "",
  "post_date": "2022-08-28T15:57:07.999026700Z",
  "votes": 4,
  "comment_count": 10,
  "views": 0,
  "content": "<p>I want to know if it's useful to train with different image scales  in different training epoch in Semantic segmentation task. It's a trick in object detection task so…Have anyone done some experiments on this?</p>",
  "messages": [
    {
      "id": "1917293",
      "postDate": "08/28/2022 15:57:08",
      "content": "<p>I want to know if it's useful to train with different image scales  in different training epoch in Semantic segmentation task. It's a trick in object detection task so…Have anyone done some experiments on this?</p>",
      "rawMarkdown": "I want to know if it's useful to train with different image scales  in different training epoch in Semantic segmentation task. It's a trick in object detection task so...Have anyone done some experiments on this?",
      "votes": null
    },
    {
      "id": "1917540",
      "postDate": "08/28/2022 20:27:03",
      "content": "<blockquote>\n  <p>different image scales in different training epoch <br>\n  What exactly are you meaning by it? Sequentially increasing size, like Progressive Learning ?</p>\n</blockquote>",
      "rawMarkdown": "> different image scales in different training epoch \nWhat exactly are you meaning by it? Sequentially increasing size, like Progressive Learning ?",
      "votes": null
    },
    {
      "id": "1917964",
      "postDate": "08/29/2022 07:32:45",
      "content": "<p>During training, one scale is randomly selected every certain iterations. The model trained in this way has strong robustness.</p>",
      "rawMarkdown": "During training, one scale is randomly selected every certain iterations. The model trained in this way has strong robustness.",
      "votes": null
    },
    {
      "id": "1917972",
      "postDate": "08/29/2022 07:38:41",
      "content": "<p>def train_one_epoch(model, optimizer, data_loader, device, epoch,print_freq, accumulate, img_size,grid_min, grid_max, gs,multi_scale=False, warmup=False, scaler=None):<br>\n    if multi_scale:<br>\n        # accumulate=16  batch_size=4<br>\n        if ni % accumulate == 0:  # ni=batch总个数<br>\n            img_size = random.randrange(grid_min, grid_max + 1) * gs  # img_size = 320~736<br>\n        sf = img_size / max(imgs.shape[2:])  # scale factor<br>\n        if sf != 1:<br>\n            # gs: (pixels) grid size<br>\n            ns = [math.ceil(x * sf / gs) * gs for x in imgs.shape[2:]]  # new shape (stretched to 32-multiple)<br>\n            imgs = F.interpolate(imgs, size=ns, mode='bilinear', align_corners=False)<br>\n    …<br>\npred = model(imgs)</p>",
      "rawMarkdown": "def train_one_epoch(model, optimizer, data_loader, device, epoch,print_freq, accumulate, img_size,grid_min, grid_max, gs,multi_scale=False, warmup=False, scaler=None):\n    if multi_scale:\n        # accumulate=16  batch_size=4\n        if ni % accumulate == 0:  # ni=batch总个数\n            img_size = random.randrange(grid_min, grid_max + 1) * gs  # img_size = 320~736\n        sf = img_size / max(imgs.shape[2:])  # scale factor\n        if sf != 1:\n            # gs: (pixels) grid size\n            ns = [math.ceil(x * sf / gs) * gs for x in imgs.shape[2:]]  # new shape (stretched to 32-multiple)\n            imgs = F.interpolate(imgs, size=ns, mode='bilinear', align_corners=False)\n    ...\npred = model(imgs)",
      "votes": null
    },
    {
      "id": "1919926",
      "postDate": "08/30/2022 18:40:41",
      "content": "<p>During training, one scale is randomly selected every certain iterations. It's a trick which is heavily used in object detection task.</p>",
      "rawMarkdown": "During training, one scale is randomly selected every certain iterations. It's a trick which is heavily used in object detection task.",
      "votes": null
    },
    {
      "id": "1919933",
      "postDate": "08/30/2022 18:49:27",
      "content": "<p>Do you have any GitHub code that shows how it is done? Do you keep the batch size fixed at the size sufficient to fit the largest sized image or do you vary baptch size as well?</p>",
      "rawMarkdown": "Do you have any GitHub code that shows how it is done? Do you keep the batch size fixed at the size sufficient to fit the largest sized image or do you vary baptch size as well?",
      "votes": null
    },
    {
      "id": "1920364",
      "postDate": "08/31/2022 05:32:59",
      "content": "<p>Batch size is fixed. Scale is sampled randomly from a pool of predefined scales. </p>",
      "rawMarkdown": "Batch size is fixed. Scale is sampled randomly from a pool of predefined scales.",
      "votes": null
    },
    {
      "id": "1920419",
      "postDate": "08/31/2022 06:42:52",
      "content": "<p>\"Batch size is fixed. Scale is sampled randomly from a pool of predefined scales.\"<br>\nBingo! It's easy to implement, but I don't know if it's helpful to my segmentation model. And in object detection task, someone have found it's harmful to model which is not large enough. </p>",
      "rawMarkdown": "\"Batch size is fixed. Scale is sampled randomly from a pool of predefined scales.\"\nBingo! It's easy to implement, but I don't know if it's helpful to my segmentation model. And in object detection task, someone have found it's harmful to model which is not large enough.",
      "votes": null
    },
    {
      "id": "1920983",
      "postDate": "08/31/2022 14:11:21",
      "content": "<p>Isn't it normal to train a model like this with RandomResizedCrop() anyway, which inherently does this? For example, if you supply a RRC crop range of (0.25, 1.0) you will get a uniform distribution of scales across 1x and 4x?</p>\n<p>I don't see any reason to specify explicit scales, beyond this method, therefore?</p>",
      "rawMarkdown": "Isn't it normal to train a model like this with RandomResizedCrop() anyway, which inherently does this? For example, if you supply a RRC crop range of (0.25, 1.0) you will get a uniform distribution of scales across 1x and 4x?\n\nI don't see any reason to specify explicit scales, beyond this method, therefore?",
      "votes": null
    },
    {
      "id": "1921173",
      "postDate": "08/31/2022 16:16:58",
      "content": "<p>Well, it seems  muti-scale training is a little different from RandomResizedCrop.</p>",
      "rawMarkdown": "Well, it seems  muti-scale training is a little different from RandomResizedCrop.",
      "votes": null
    },
    {
      "id": "1921181",
      "postDate": "08/31/2022 16:20:09",
      "content": "<p>I can often see both of them are used for training. </p>",
      "rawMarkdown": "I can often see both of them are used for training.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1917540,
      "author_name": "vad13irt",
      "author_url": "",
      "post_date": "08/28/2022 20:27:03",
      "content": "<blockquote>\n  <p>different image scales in different training epoch <br>\n  What exactly are you meaning by it? Sequentially increasing size, like Progressive Learning ?</p>\n</blockquote>",
      "votes": null,
      "replies": [
        {
          "id": 1919926,
          "author_name": "chinartist",
          "author_url": "",
          "post_date": "08/30/2022 18:40:41",
          "content": "<p>During training, one scale is randomly selected every certain iterations. It's a trick which is heavily used in object detection task.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1919933,
          "author_name": "sakvaua",
          "author_url": "",
          "post_date": "08/30/2022 18:49:27",
          "content": "<p>Do you have any GitHub code that shows how it is done? Do you keep the batch size fixed at the size sufficient to fit the largest sized image or do you vary baptch size as well?</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1920364,
          "author_name": "gunesevitan",
          "author_url": "",
          "post_date": "08/31/2022 05:32:59",
          "content": "<p>Batch size is fixed. Scale is sampled randomly from a pool of predefined scales. </p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1920419,
          "author_name": "chinartist",
          "author_url": "",
          "post_date": "08/31/2022 06:42:52",
          "content": "<p>\"Batch size is fixed. Scale is sampled randomly from a pool of predefined scales.\"<br>\nBingo! It's easy to implement, but I don't know if it's helpful to my segmentation model. And in object detection task, someone have found it's harmful to model which is not large enough. </p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1917964,
      "author_name": "mzimingxu",
      "author_url": "",
      "post_date": "08/29/2022 07:32:45",
      "content": "<p>During training, one scale is randomly selected every certain iterations. The model trained in this way has strong robustness.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1917972,
      "author_name": "mzimingxu",
      "author_url": "",
      "post_date": "08/29/2022 07:38:41",
      "content": "<p>def train_one_epoch(model, optimizer, data_loader, device, epoch,print_freq, accumulate, img_size,grid_min, grid_max, gs,multi_scale=False, warmup=False, scaler=None):<br>\n    if multi_scale:<br>\n        # accumulate=16  batch_size=4<br>\n        if ni % accumulate == 0:  # ni=batch总个数<br>\n            img_size = random.randrange(grid_min, grid_max + 1) * gs  # img_size = 320~736<br>\n        sf = img_size / max(imgs.shape[2:])  # scale factor<br>\n        if sf != 1:<br>\n            # gs: (pixels) grid size<br>\n            ns = [math.ceil(x * sf / gs) * gs for x in imgs.shape[2:]]  # new shape (stretched to 32-multiple)<br>\n            imgs = F.interpolate(imgs, size=ns, mode='bilinear', align_corners=False)<br>\n    …<br>\npred = model(imgs)</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1920983,
      "author_name": "jamesphoward",
      "author_url": "",
      "post_date": "08/31/2022 14:11:21",
      "content": "<p>Isn't it normal to train a model like this with RandomResizedCrop() anyway, which inherently does this? For example, if you supply a RRC crop range of (0.25, 1.0) you will get a uniform distribution of scales across 1x and 4x?</p>\n<p>I don't see any reason to specify explicit scales, beyond this method, therefore?</p>",
      "votes": null,
      "replies": [
        {
          "id": 1921173,
          "author_name": "chinartist",
          "author_url": "",
          "post_date": "08/31/2022 16:16:58",
          "content": "<p>Well, it seems  muti-scale training is a little different from RandomResizedCrop.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1921181,
          "author_name": "chinartist",
          "author_url": "",
          "post_date": "08/31/2022 16:20:09",
          "content": "<p>I can often see both of them are used for training. </p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1917293": "I want to know if it's useful to train with different image scales  in different training epoch in Semantic segmentation task. It's a trick in object detection task so...Have anyone done some experiments on this?",
    "1917540": "> different image scales in different training epoch \nWhat exactly are you meaning by it? Sequentially increasing size, like Progressive Learning ?",
    "1917964": "During training, one scale is randomly selected every certain iterations. The model trained in this way has strong robustness.",
    "1917972": "def train_one_epoch(model, optimizer, data_loader, device, epoch,print_freq, accumulate, img_size,grid_min, grid_max, gs,multi_scale=False, warmup=False, scaler=None):\n    if multi_scale:\n        # accumulate=16  batch_size=4\n        if ni % accumulate == 0:  # ni=batch总个数\n            img_size = random.randrange(grid_min, grid_max + 1) * gs  # img_size = 320~736\n        sf = img_size / max(imgs.shape[2:])  # scale factor\n        if sf != 1:\n            # gs: (pixels) grid size\n            ns = [math.ceil(x * sf / gs) * gs for x in imgs.shape[2:]]  # new shape (stretched to 32-multiple)\n            imgs = F.interpolate(imgs, size=ns, mode='bilinear', align_corners=False)\n    ...\npred = model(imgs)",
    "1919926": "During training, one scale is randomly selected every certain iterations. It's a trick which is heavily used in object detection task.",
    "1919933": "Do you have any GitHub code that shows how it is done? Do you keep the batch size fixed at the size sufficient to fit the largest sized image or do you vary baptch size as well?",
    "1920364": "Batch size is fixed. Scale is sampled randomly from a pool of predefined scales.",
    "1920419": "\"Batch size is fixed. Scale is sampled randomly from a pool of predefined scales.\"\nBingo! It's easy to implement, but I don't know if it's helpful to my segmentation model. And in object detection task, someone have found it's harmful to model which is not large enough.",
    "1920983": "Isn't it normal to train a model like this with RandomResizedCrop() anyway, which inherently does this? For example, if you supply a RRC crop range of (0.25, 1.0) you will get a uniform distribution of scales across 1x and 4x?\n\nI don't see any reason to specify explicit scales, beyond this method, therefore?",
    "1921173": "Well, it seems  muti-scale training is a little different from RandomResizedCrop.",
    "1921181": "I can often see both of them are used for training."
  },
  "source": "meta"
}