{
  "id": 148696,
  "title": "Validation strategies - kRegionsOut",
  "url": "/competitions/global-wheat-detection/discussion/148696",
  "author_name": "Fayzur",
  "post_date": "2020-05-05T09:53:12.385000",
  "votes": 6,
  "comment_count": 2,
  "views": 0,
  "content": "<p>As <a href=\"/stavness\">@stavness</a> mentioned in the <a href=\"https://www.kaggle.com/c/global-wheat-detection/discussion/148592\">welcome post</a>, the test images are from different regions than training images:\n&gt; blind test set of images from different world regions than in the training set</p>\n\n<p>We find images from 7 different regions in training dataset.</p>\n\n<p>&gt; 'arvalis_1', 'arvalis_2', 'arvalis_3', 'ethz_1', 'inrae_1', 'rres_1', 'usask_1'</p>\n\n<p>Thus, <strong>kRegionsOut</strong> validation strategies in training is useful to tackle test images from other regions.</p>\n\n<p><strong>code snippet:</strong>\n&gt; df = pd.read_csv('../input/global-wheat-detection/train.csv')\n&gt; df.head()\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F836513%2F370f7027f953a5885b223bd99e2301ae%2Ffold1.png?generation=1588684624055121&amp;alt=media\" alt=\"\"></p>\n\n<p>Now mapping source to fold\n&gt; mapping = {'arvalis_1': 0, 'arvalis_2': 1, 'arvalis_3': 2, 'ethz_1': 3, 'inrae_1': 4, 'rres_1': 5, 'usask_1': 6}</p>\n\n<p>&gt; df['folds'] = df.replace({'source': mapping}).source.values\ndf.head()\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F836513%2Ff11da5880bb0a508df3524527163de91%2Ffold2.png?generation=1588684899683123&amp;alt=media\" alt=\"\"></p>\n\n<p>Number of unique images by source\n&gt; df.groupby('source')['image_id'].nunique()\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F836513%2Fcebe9252982e7e8483287cf97ab27a82%2Ffold8.png?generation=1588685722012651&amp;alt=media\" alt=\"\"></p>\n\n<p>Number of unique images by fold\n&gt; df.groupby('folds')['image_id'].nunique()\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F836513%2F4843ece74f13e080cd314344577ec04a%2Ffold7.png?generation=1588685706332999&amp;alt=media\" alt=\"\"></p>\n\n<p>To get 'arvalis_1' region in validation set and all other regions in training:</p>\n\n<blockquote>\n  <p>train_ids = df.loc[df.folds.values!=0,'image_id'].unique().tolist()\n  valid_ids = df.loc[df.folds.values==0,'image_id'].unique().tolist()</p>\n  \n  <p>train_df = df[df['image_id'].isin(train_ids)]</p>\n  \n  <p>valid_df = df[df['image_id'].isin(valid_ids)]</p>\n</blockquote>",
  "messages": [
    {
      "id": 834102,
      "postDate": "2020-05-05T09:53:12.387Z",
      "content": "<p>As <a href=\"/stavness\">@stavness</a> mentioned in the <a href=\"https://www.kaggle.com/c/global-wheat-detection/discussion/148592\">welcome post</a>, the test images are from different regions than training images:\n&gt; blind test set of images from different world regions than in the training set</p>\n\n<p>We find images from 7 different regions in training dataset.</p>\n\n<p>&gt; 'arvalis_1', 'arvalis_2', 'arvalis_3', 'ethz_1', 'inrae_1', 'rres_1', 'usask_1'</p>\n\n<p>Thus, <strong>kRegionsOut</strong> validation strategies in training is useful to tackle test images from other regions.</p>\n\n<p><strong>code snippet:</strong>\n&gt; df = pd.read_csv('../input/global-wheat-detection/train.csv')\n&gt; df.head()\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F836513%2F370f7027f953a5885b223bd99e2301ae%2Ffold1.png?generation=1588684624055121&amp;alt=media\" alt=\"\"></p>\n\n<p>Now mapping source to fold\n&gt; mapping = {'arvalis_1': 0, 'arvalis_2': 1, 'arvalis_3': 2, 'ethz_1': 3, 'inrae_1': 4, 'rres_1': 5, 'usask_1': 6}</p>\n\n<p>&gt; df['folds'] = df.replace({'source': mapping}).source.values\ndf.head()\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F836513%2Ff11da5880bb0a508df3524527163de91%2Ffold2.png?generation=1588684899683123&amp;alt=media\" alt=\"\"></p>\n\n<p>Number of unique images by source\n&gt; df.groupby('source')['image_id'].nunique()\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F836513%2Fcebe9252982e7e8483287cf97ab27a82%2Ffold8.png?generation=1588685722012651&amp;alt=media\" alt=\"\"></p>\n\n<p>Number of unique images by fold\n&gt; df.groupby('folds')['image_id'].nunique()\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F836513%2F4843ece74f13e080cd314344577ec04a%2Ffold7.png?generation=1588685706332999&amp;alt=media\" alt=\"\"></p>\n\n<p>To get 'arvalis_1' region in validation set and all other regions in training:</p>\n\n<blockquote>\n  <p>train_ids = df.loc[df.folds.values!=0,'image_id'].unique().tolist()\n  valid_ids = df.loc[df.folds.values==0,'image_id'].unique().tolist()</p>\n  \n  <p>train_df = df[df['image_id'].isin(train_ids)]</p>\n  \n  <p>valid_df = df[df['image_id'].isin(valid_ids)]</p>\n</blockquote>",
      "rawMarkdown": "As @stavness mentioned in the [welcome post](https://www.kaggle.com/c/global-wheat-detection/discussion/148592), the test images are from different regions than training images:\n&gt; blind test set of images from different world regions than in the training set\n\nWe find images from 7 different regions in training dataset.\n\n&gt; 'arvalis\\_1', 'arvalis\\_2', 'arvalis\\_3', 'ethz\\_1', 'inrae\\_1', 'rres\\_1', 'usask\\_1'\n\nThus, **kRegionsOut** validation strategies in training is useful to tackle test images from other regions.\n\n**code snippet:**\n&gt; df = pd.read_csv('../input/global-wheat-detection/train.csv')\n&gt; df.head()\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F836513%2F370f7027f953a5885b223bd99e2301ae%2Ffold1.png?generation=1588684624055121&amp;alt=media)\n\nNow mapping source to fold\n&gt; mapping = {'arvalis\\_1': 0, 'arvalis\\_2': 1, 'arvalis\\_3': 2, 'ethz\\_1': 3, 'inrae\\_1': 4, 'rres\\_1': 5, 'usask\\_1': 6}\n\n&gt; df['folds'] = df.replace({'source': mapping}).source.values\ndf.head()\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F836513%2Ff11da5880bb0a508df3524527163de91%2Ffold2.png?generation=1588684899683123&amp;alt=media)\n\nNumber of unique images by source\n&gt; df.groupby('source')['image_id'].nunique()\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F836513%2Fcebe9252982e7e8483287cf97ab27a82%2Ffold8.png?generation=1588685722012651&amp;alt=media)\n\nNumber of unique images by fold\n&gt; df.groupby('folds')['image_id'].nunique()\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F836513%2F4843ece74f13e080cd314344577ec04a%2Ffold7.png?generation=1588685706332999&amp;alt=media)\n\nTo get 'arvalis\\_1' region in validation set and all other regions in training:\n\n&gt; train\\_ids = df.loc[df.folds.values!=0,'image\\_id'].unique().tolist()\n&gt; valid\\_ids = df.loc[df.folds.values==0,'image\\_id'].unique().tolist()\n&gt; \n&gt; train\\_df = df[df['image_id'].isin(train\\_ids)]\n\n&gt; valid\\_df = df[df['image_id'].isin(valid\\_ids)]\n",
      "votes": 6
    },
    {
      "id": 834455,
      "postDate": "2020-05-05T14:48:42.620Z",
      "rawMarkdown": "",
      "votes": 1,
      "isDeleted": true,
      "replies": [
        {
          "id": 834615,
          "postDate": "2020-05-05T16:47:52.227Z",
          "content": "<p>Yes, thank for pointing it. The main difficulty of this challenge is the bias in term of location. However the test images are also taken from nadir, with high resolution RGB images.</p>\n\n<p>Good luck ! </p>",
          "rawMarkdown": "Yes, thank for pointing it. The main difficulty of this challenge is the bias in term of location. However the test images are also taken from nadir, with high resolution RGB images.\n\nGood luck ! ",
          "votes": 2
        }
      ]
    }
  ],
  "comments": [
    {
      "id": 834455,
      "author_name": "",
      "author_url": "",
      "post_date": "2020-05-05T14:48:42.620000",
      "content": "",
      "votes": 1,
      "replies": [
        {
          "id": 834615,
          "author_name": "Etienne David",
          "author_url": "",
          "post_date": "2020-05-05T16:47:52.227000",
          "content": "<p>Yes, thank for pointing it. The main difficulty of this challenge is the bias in term of location. However the test images are also taken from nadir, with high resolution RGB images.</p>\n\n<p>Good luck ! </p>",
          "votes": 2,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "834102": "As @stavness mentioned in the [welcome post](https://www.kaggle.com/c/global-wheat-detection/discussion/148592), the test images are from different regions than training images:\n&gt; blind test set of images from different world regions than in the training set\n\nWe find images from 7 different regions in training dataset.\n\n&gt; 'arvalis\\_1', 'arvalis\\_2', 'arvalis\\_3', 'ethz\\_1', 'inrae\\_1', 'rres\\_1', 'usask\\_1'\n\nThus, **kRegionsOut** validation strategies in training is useful to tackle test images from other regions.\n\n**code snippet:**\n&gt; df = pd.read_csv('../input/global-wheat-detection/train.csv')\n&gt; df.head()\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F836513%2F370f7027f953a5885b223bd99e2301ae%2Ffold1.png?generation=1588684624055121&amp;alt=media)\n\nNow mapping source to fold\n&gt; mapping = {'arvalis\\_1': 0, 'arvalis\\_2': 1, 'arvalis\\_3': 2, 'ethz\\_1': 3, 'inrae\\_1': 4, 'rres\\_1': 5, 'usask\\_1': 6}\n\n&gt; df['folds'] = df.replace({'source': mapping}).source.values\ndf.head()\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F836513%2Ff11da5880bb0a508df3524527163de91%2Ffold2.png?generation=1588684899683123&amp;alt=media)\n\nNumber of unique images by source\n&gt; df.groupby('source')['image_id'].nunique()\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F836513%2Fcebe9252982e7e8483287cf97ab27a82%2Ffold8.png?generation=1588685722012651&amp;alt=media)\n\nNumber of unique images by fold\n&gt; df.groupby('folds')['image_id'].nunique()\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-user-content/o/inbox%2F836513%2F4843ece74f13e080cd314344577ec04a%2Ffold7.png?generation=1588685706332999&amp;alt=media)\n\nTo get 'arvalis\\_1' region in validation set and all other regions in training:\n\n&gt; train\\_ids = df.loc[df.folds.values!=0,'image\\_id'].unique().tolist()\n&gt; valid\\_ids = df.loc[df.folds.values==0,'image\\_id'].unique().tolist()\n&gt; \n&gt; train\\_df = df[df['image_id'].isin(train\\_ids)]\n\n&gt; valid\\_df = df[df['image_id'].isin(valid\\_ids)]\n",
    "834455": ""
  }
}