{
  "id": 428163,
  "title": "Be Careful If You Use TTA for Segmentation Task",
  "url": "/competitions/google-research-identify-contrails-reduce-global-warming/discussion/428163",
  "author_name": "william.wu",
  "post_date": "2023-07-31T11:20:04.637000",
  "votes": 9,
  "comment_count": 5,
  "views": 0,
  "content": "<p>Some augmentation like flipping and rotating alter the image orientation,  thus also changing the orientation of the predictions. </p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3563032%2F300bf5fe48f935c50fc6403dcb1f5664%2Faug.png?generation=1690802059493745&amp;alt=media\" alt=\"HFlip Aug\"></p>\n<p>You need to deaug the prediction of aug Image before ensembling it with the prediction of the original one. In my pipeline, I do it in this way:</p>\n<pre><code>hflip = A.HorizontalFlip(p=)\nvflip = A.VerticalFlip(p=)\naugs = [, hflip, vflip]\nde_augs = [, hflip, vflip]\nall_preds = []\n aug  augs:\n    all_preds.append(predict(model, data_loader, transform=aug)\n i, de_aug  (de_augs):\n    all_preds[i] = transform(all_preds[i], transform=de_aug)\npreds = np.average(all_preds, axis=)\n</code></pre>",
  "messages": [
    {
      "id": 2367158,
      "postDate": "2023-07-31T11:50:19.500Z",
      "content": "<p>just use <a href=\"https://github.com/BloodAxe/pytorch-toolbelt\" target=\"_blank\">https://github.com/BloodAxe/pytorch-toolbelt</a></p>",
      "rawMarkdown": "just use https://github.com/BloodAxe/pytorch-toolbelt",
      "votes": 10,
      "replies": [
        {
          "id": 2367287,
          "postDate": "2023-07-31T13:25:54.417Z",
          "content": "<p>or <a href=\"https://github.com/qubvel/ttach\" target=\"_blank\">https://github.com/qubvel/ttach</a></p>",
          "rawMarkdown": "or https://github.com/qubvel/ttach",
          "votes": 10,
          "replies": [
            {
              "id": 2367319,
              "postDate": "2023-07-31T13:49:45.580Z",
              "content": "<p>Thanks for sharing, it's really helpful</p>",
              "rawMarkdown": "Thanks for sharing, it's really helpful",
              "votes": 1
            },
            {
              "id": 2381620,
              "postDate": "2023-08-09T09:40:03.553Z",
              "content": "<p><a href=\"https://www.kaggle.com/maksimovka\" target=\"_blank\">@maksimovka</a> <a href=\"https://www.kaggle.com/sergiosaharovskiy\" target=\"_blank\">@sergiosaharovskiy</a> Please guide me to use this useful repo on kaggle when internet off?</p>",
              "rawMarkdown": "@maksimovka @sergiosaharovskiy Please guide me to use this useful repo on kaggle when internet off?",
              "votes": 1
            },
            {
              "id": 2381639,
              "postDate": "2023-08-09T09:56:11.357Z",
              "content": "<p>just use a dataset which holds the library code<br>\n<a href=\"https://www.kaggle.com/datasets/sergiosaharovskiy/ttach\" target=\"_blank\">https://www.kaggle.com/datasets/sergiosaharovskiy/ttach</a></p>",
              "rawMarkdown": "just use a dataset which holds the library code\nhttps://www.kaggle.com/datasets/sergiosaharovskiy/ttach",
              "votes": 2
            }
          ]
        }
      ]
    },
    {
      "id": 2367127,
      "postDate": "2023-07-31T11:20:04.637Z",
      "content": "<p>Some augmentation like flipping and rotating alter the image orientation,  thus also changing the orientation of the predictions. </p>\n<p><img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3563032%2F300bf5fe48f935c50fc6403dcb1f5664%2Faug.png?generation=1690802059493745&amp;alt=media\" alt=\"HFlip Aug\"></p>\n<p>You need to deaug the prediction of aug Image before ensembling it with the prediction of the original one. In my pipeline, I do it in this way:</p>\n<pre><code>hflip = A.HorizontalFlip(p=)\nvflip = A.VerticalFlip(p=)\naugs = [, hflip, vflip]\nde_augs = [, hflip, vflip]\nall_preds = []\n aug  augs:\n    all_preds.append(predict(model, data_loader, transform=aug)\n i, de_aug  (de_augs):\n    all_preds[i] = transform(all_preds[i], transform=de_aug)\npreds = np.average(all_preds, axis=)\n</code></pre>",
      "rawMarkdown": "Some augmentation like flipping and rotating alter the image orientation,  thus also changing the orientation of the predictions. \n\n![HFlip Aug](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3563032%2F300bf5fe48f935c50fc6403dcb1f5664%2Faug.png?generation=1690802059493745&alt=media)\n\nYou need to deaug the prediction of aug Image before ensembling it with the prediction of the original one. In my pipeline, I do it in this way:\n```Python\nhflip = A.HorizontalFlip(p=1)\nvflip = A.VerticalFlip(p=1)\naugs = [None, hflip, vflip]\nde_augs = [None, hflip, vflip]\nall_preds = []\nfor aug in augs:\n    all_preds.append(predict(model, data_loader, transform=aug)\nfor i, de_aug in enumerate(de_augs):\n    all_preds[i] = transform(all_preds[i], transform=de_aug)\npreds = np.average(all_preds, axis=0)\n```",
      "votes": 8
    }
  ],
  "comments": [
    {
      "id": 2367158,
      "author_name": "Kostiantyn Maksymov",
      "author_url": "",
      "post_date": "2023-07-31T11:50:19.500000",
      "content": "<p>just use <a href=\"https://github.com/BloodAxe/pytorch-toolbelt\" target=\"_blank\">https://github.com/BloodAxe/pytorch-toolbelt</a></p>",
      "votes": 10,
      "replies": [
        {
          "id": 2367287,
          "author_name": "SSS",
          "author_url": "",
          "post_date": "2023-07-31T13:25:54.417000",
          "content": "<p>or <a href=\"https://github.com/qubvel/ttach\" target=\"_blank\">https://github.com/qubvel/ttach</a></p>",
          "votes": 10,
          "replies": [
            {
              "id": 2367319,
              "author_name": "william.wu",
              "author_url": "",
              "post_date": "2023-07-31T13:49:45.580000",
              "content": "<p>Thanks for sharing, it's really helpful</p>",
              "votes": 1,
              "replies": []
            },
            {
              "id": 2381620,
              "author_name": "Vipin Kumar",
              "author_url": "",
              "post_date": "2023-08-09T09:40:03.553000",
              "content": "<p><a href=\"https://www.kaggle.com/maksimovka\" target=\"_blank\">@maksimovka</a> <a href=\"https://www.kaggle.com/sergiosaharovskiy\" target=\"_blank\">@sergiosaharovskiy</a> Please guide me to use this useful repo on kaggle when internet off?</p>",
              "votes": 1,
              "replies": []
            },
            {
              "id": 2381639,
              "author_name": "iadduk",
              "author_url": "",
              "post_date": "2023-08-09T09:56:11.357000",
              "content": "<p>just use a dataset which holds the library code<br>\n<a href=\"https://www.kaggle.com/datasets/sergiosaharovskiy/ttach\" target=\"_blank\">https://www.kaggle.com/datasets/sergiosaharovskiy/ttach</a></p>",
              "votes": 2,
              "replies": []
            }
          ]
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "2367158": "just use https://github.com/BloodAxe/pytorch-toolbelt",
    "2367127": "Some augmentation like flipping and rotating alter the image orientation,  thus also changing the orientation of the predictions. \n\n![HFlip Aug](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F3563032%2F300bf5fe48f935c50fc6403dcb1f5664%2Faug.png?generation=1690802059493745&alt=media)\n\nYou need to deaug the prediction of aug Image before ensembling it with the prediction of the original one. In my pipeline, I do it in this way:\n```Python\nhflip = A.HorizontalFlip(p=1)\nvflip = A.VerticalFlip(p=1)\naugs = [None, hflip, vflip]\nde_augs = [None, hflip, vflip]\nall_preds = []\nfor aug in augs:\n    all_preds.append(predict(model, data_loader, transform=aug)\nfor i, de_aug in enumerate(de_augs):\n    all_preds[i] = transform(all_preds[i], transform=de_aug)\npreds = np.average(all_preds, axis=0)\n```"
  }
}