{
  "id": 164850,
  "title": "Faster Weighted Boxes Ensembling",
  "url": "/competitions/global-wheat-detection/discussion/164850",
  "author_name": "",
  "post_date": "2020-07-07T18:35:35.978610700Z",
  "votes": 4,
  "comment_count": 1,
  "views": 0,
  "content": "<p>For anyone who has been having their ensemble models running for a long time on submission, potentially running out of notebook/kaggle gpu time, a couple of tips below.</p>\n\n<ol>\n<li><p>Keep upping batch numbers, I could get a batch size of 10 on the P100 kaggle GPU for an effdet D5 model with an image size of 768x768.</p></li>\n<li><p>Depending on how you've written your ensembling, running through all the images for each model first and then running the weighted box fusion is about 4 times quicker for me than running for all the image swapping models at the end of each batch. At low image counts the difference wasn't much, but over the test set it's a lot. Obvious of course, but some code which might help you below, thanks to <a href=\"https://www.kaggle.com/shonenkov\">Alex</a> for the starting <a href=\"https://www.kaggle.com/shonenkov/inference-efficientdet\">notebook</a>.</p></li>\n</ol>\n\n<p>```\nDATA_ROOT_PATH = '../input/global-wheat-detection/test'\nimage_ids_all = [path.split('/')[-1][:-4] for path in glob(f'{DATA_ROOT_PATH}/*.jpg')]\nprint(image_ids_all)</p>\n\n<p>models = ['your model 1',\n        'your model 2',\n        'your model 3',\n        'your model 4']</p>\n\n<p>results = []\npredictions = []</p>\n\n<p>for chkpnt in models:\n    net = load_net(chkpnt)\n    outputs = []</p>\n\n<pre><code>for images, image_ids in data_loader:\n    outloop = make_predictions(images)\n    outputs.extend(outloop)\n\npredictions.append(outputs)\n</code></pre>\n\n<p>for i, image_ids in enumerate(image_ids_all):\n    boxes, scores, labels = run_wbf(predictions, image_index=i)\n```</p>",
  "messages": [
    {
      "id": "919165",
      "postDate": "07/07/2020 18:35:35",
      "content": "<p>For anyone who has been having their ensemble models running for a long time on submission, potentially running out of notebook/kaggle gpu time, a couple of tips below.</p>\n\n<ol>\n<li><p>Keep upping batch numbers, I could get a batch size of 10 on the P100 kaggle GPU for an effdet D5 model with an image size of 768x768.</p></li>\n<li><p>Depending on how you've written your ensembling, running through all the images for each model first and then running the weighted box fusion is about 4 times quicker for me than running for all the image swapping models at the end of each batch. At low image counts the difference wasn't much, but over the test set it's a lot. Obvious of course, but some code which might help you below, thanks to <a href=\"https://www.kaggle.com/shonenkov\">Alex</a> for the starting <a href=\"https://www.kaggle.com/shonenkov/inference-efficientdet\">notebook</a>.</p></li>\n</ol>\n\n<p>```\nDATA_ROOT_PATH = '../input/global-wheat-detection/test'\nimage_ids_all = [path.split('/')[-1][:-4] for path in glob(f'{DATA_ROOT_PATH}/*.jpg')]\nprint(image_ids_all)</p>\n\n<p>models = ['your model 1',\n        'your model 2',\n        'your model 3',\n        'your model 4']</p>\n\n<p>results = []\npredictions = []</p>\n\n<p>for chkpnt in models:\n    net = load_net(chkpnt)\n    outputs = []</p>\n\n<pre><code>for images, image_ids in data_loader:\n    outloop = make_predictions(images)\n    outputs.extend(outloop)\n\npredictions.append(outputs)\n</code></pre>\n\n<p>for i, image_ids in enumerate(image_ids_all):\n    boxes, scores, labels = run_wbf(predictions, image_index=i)\n```</p>",
      "rawMarkdown": "For anyone who has been having their ensemble models running for a long time on submission, potentially running out of notebook/kaggle gpu time, a couple of tips below.\n\n1. Keep upping batch numbers, I could get a batch size of 10 on the P100 kaggle GPU for an effdet D5 model with an image size of 768x768.\n\n2. Depending on how you've written your ensembling, running through all the images for each model first and then running the weighted box fusion is about 4 times quicker for me than running for all the image swapping models at the end of each batch. At low image counts the difference wasn't much, but over the test set it's a lot. Obvious of course, but some code which might help you below, thanks to [Alex](https://www.kaggle.com/shonenkov) for the starting [notebook](https://www.kaggle.com/shonenkov/inference-efficientdet).\n\n\n```\nDATA_ROOT_PATH = '../input/global-wheat-detection/test'\nimage_ids_all = [path.split('/')[-1][:-4] for path in glob(f'{DATA_ROOT_PATH}/*.jpg')]\nprint(image_ids_all)\n\nmodels = ['your model 1',\n        'your model 2',\n        'your model 3',\n        'your model 4']\n\nresults = []\npredictions = []\n\nfor chkpnt in models:\n    net = load_net(chkpnt)\n    outputs = []\n\n    for images, image_ids in data_loader:\n        outloop = make_predictions(images)\n        outputs.extend(outloop)\n\n    predictions.append(outputs)\n    \nfor i, image_ids in enumerate(image_ids_all):\n    boxes, scores, labels = run_wbf(predictions, image_index=i)\n```",
      "votes": null
    },
    {
      "id": "920226",
      "postDate": "07/08/2020 12:56:12",
      "content": "<p>so good</p>",
      "rawMarkdown": "so good",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 920226,
      "author_name": "leila73",
      "author_url": "",
      "post_date": "07/08/2020 12:56:12",
      "content": "<p>so good</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "919165": "For anyone who has been having their ensemble models running for a long time on submission, potentially running out of notebook/kaggle gpu time, a couple of tips below.\n\n1. Keep upping batch numbers, I could get a batch size of 10 on the P100 kaggle GPU for an effdet D5 model with an image size of 768x768.\n\n2. Depending on how you've written your ensembling, running through all the images for each model first and then running the weighted box fusion is about 4 times quicker for me than running for all the image swapping models at the end of each batch. At low image counts the difference wasn't much, but over the test set it's a lot. Obvious of course, but some code which might help you below, thanks to [Alex](https://www.kaggle.com/shonenkov) for the starting [notebook](https://www.kaggle.com/shonenkov/inference-efficientdet).\n\n\n```\nDATA_ROOT_PATH = '../input/global-wheat-detection/test'\nimage_ids_all = [path.split('/')[-1][:-4] for path in glob(f'{DATA_ROOT_PATH}/*.jpg')]\nprint(image_ids_all)\n\nmodels = ['your model 1',\n        'your model 2',\n        'your model 3',\n        'your model 4']\n\nresults = []\npredictions = []\n\nfor chkpnt in models:\n    net = load_net(chkpnt)\n    outputs = []\n\n    for images, image_ids in data_loader:\n        outloop = make_predictions(images)\n        outputs.extend(outloop)\n\n    predictions.append(outputs)\n    \nfor i, image_ids in enumerate(image_ids_all):\n    boxes, scores, labels = run_wbf(predictions, image_index=i)\n```",
    "920226": "so good"
  },
  "source": "meta"
}