{
  "id": 16275,
  "title": "Python Script to sort images",
  "url": "/competitions/noaa-right-whale-recognition/discussion/16275",
  "author_name": "",
  "post_date": "2015-09-01T21:36:25.927Z",
  "votes": 15,
  "comment_count": 7,
  "views": 4240,
  "content": "<p>This script creates folders for each of the 447 whales, and moves the <em>training</em> images into the corresponding folder. The test images stay put.</p>\n\n<p>This makes it easier if you want to manually crop images (and avoid touching the test images), check out images of the same whale, etc.</p>\n\n<p>...</p>\n\n<pre><code>import os\nimport pandas as pd\n\ntrain = pd.read_csv('train.csv', index_col='Image')\n\nwhaleIDs = list(train['whaleID'].unique())\n\nfor w in whaleIDs:\n  os.makedirs('./imgs/'+w)\n\nfor image in train.index:\n  folder = train.loc[image, 'whaleID']\n  old = './imgs/{}'.format(image)\n  new = './imgs/{}/{}'.format(folder, image)\n  try:\n    os.rename(old, new)\n  except:\n    print('{} - {}'.format(image,folder))\n</code></pre>",
  "messages": [
    {
      "id": "91274",
      "postDate": "09/01/2015 21:36:25",
      "content": "<p>This script creates folders for each of the 447 whales, and moves the <em>training</em> images into the corresponding folder. The test images stay put.</p>\n\n<p>This makes it easier if you want to manually crop images (and avoid touching the test images), check out images of the same whale, etc.</p>\n\n<p>...</p>\n\n<pre><code>import os\nimport pandas as pd\n\ntrain = pd.read_csv('train.csv', index_col='Image')\n\nwhaleIDs = list(train['whaleID'].unique())\n\nfor w in whaleIDs:\n  os.makedirs('./imgs/'+w)\n\nfor image in train.index:\n  folder = train.loc[image, 'whaleID']\n  old = './imgs/{}'.format(image)\n  new = './imgs/{}/{}'.format(folder, image)\n  try:\n    os.rename(old, new)\n  except:\n    print('{} - {}'.format(image,folder))\n</code></pre>",
      "rawMarkdown": "This script creates folders for each of the 447 whales, and moves the *training* images into the corresponding folder. The test images stay put.\r\n\r\nThis makes it easier if you want to manually crop images (and avoid touching the test images), check out images of the same whale, etc.\r\n\r\n...\r\n\r\n\r\n    import os\r\n    import pandas as pd\r\n    \r\n    train = pd.read_csv('train.csv', index_col='Image')\r\n    \r\n    whaleIDs = list(train['whaleID'].unique())\r\n    \r\n    for w in whaleIDs:\r\n      os.makedirs('./imgs/'+w)\r\n      \r\n    for image in train.index:\r\n      folder = train.loc[image, 'whaleID']\r\n      old = './imgs/{}'.format(image)\r\n      new = './imgs/{}/{}'.format(folder, image)\r\n      try:\r\n        os.rename(old, new)\r\n      except:\r\n        print('{} - {}'.format(image,folder))",
      "votes": null
    },
    {
      "id": "91561",
      "postDate": "09/04/2015 08:50:11",
      "content": "<p>And the same for those who like  R - Only difference ( it doesnt move the image - creates a copy in another folder called train)</p>\n\n<hr>\n\n<pre><code>setwd (&quot;E:\\\\Kaggle\\\\whale\\\\data&quot;)\n\ninputFile &lt;-  read.csv(&quot;train.csv&quot;,header=T)\nfor(i in 1:nrow(inputFile)) { \n   filePathFrom &lt;- paste(&quot;.\\\\imgs\\\\&quot;,inputFile[i,1],sep=&quot;&quot;)\n   filePathTo &lt;- paste(&quot;.\\\\train\\\\&quot;,inputFile[i,1],sep=&quot;&quot;)  \n   cat(&quot; file exist= &quot;,file.exists(filePathFrom),&quot; &quot;,filePathFrom)\n   success&lt;-file.copy(from = filePathFrom,  to = filePathTo)\n   cat (&quot; Copied = &quot;, success, &quot;\\n&quot;)\n</code></pre>\n\n<p>}</p>\n\n<hr>\n\n<p>Or to create individual directories for each whale - </p>\n\n<pre><code>setwd (&quot;E:\\\\Kaggle\\\\whale\\\\data&quot;)\ninputFile &lt;-  read.csv(&quot;train.csv&quot;,header=T)\n for(i in 1:nrow(inputFile)){\n    filePathFrom &lt;- paste(&quot;.\\\\imgs\\\\&quot;,inputFile[i,1],sep=&quot;&quot;)  \n    DirPathTo &lt;- paste(&quot;.\\\\train\\\\&quot;,inputFile[i,2],sep=&quot;&quot;)  \n    if(!file.exists(DirPathTo)){\n        a&lt;-dir.create(DirPathTo)\n     } \n     filePathTo &lt;- paste(DirPathTo,&quot;\\\\&quot;,inputFile[i,1],sep=&quot;&quot;)  \n     success&lt;-file.copy(from = filePathFrom,  to = filePathTo)\n     cat (&quot;Copied &quot;,filePathTo,&quot; = &quot;, success, &quot;\\n&quot;)\n</code></pre>\n\n<p>}</p>",
      "rawMarkdown": "And the same for those who like  R - Only difference ( it doesnt move the image - creates a copy in another folder called train)\r\n\r\n------------------------------\r\n    setwd (\"E:\\\\Kaggle\\\\whale\\\\data\")\r\n\r\n    inputFile <-  read.csv(\"train.csv\",header=T)\r\n    for(i in 1:nrow(inputFile)) { \r\n       filePathFrom <- paste(\".\\\\imgs\\\\\",inputFile[i,1],sep=\"\")\r\n       filePathTo <- paste(\".\\\\train\\\\\",inputFile[i,1],sep=\"\")  \r\n       cat(\" file exist= \",file.exists(filePathFrom),\" \",filePathFrom)\r\n       success<-file.copy(from = filePathFrom,  to = filePathTo)\r\n       cat (\" Copied = \", success, \"\\n\")\r\n}\r\n\r\n------------------------------\r\n\r\nOr to create individual directories for each whale - \r\n\r\n    setwd (\"E:\\\\Kaggle\\\\whale\\\\data\")\r\n    inputFile <-  read.csv(\"train.csv\",header=T)\r\n     for(i in 1:nrow(inputFile)){\r\n        filePathFrom <- paste(\".\\\\imgs\\\\\",inputFile[i,1],sep=\"\")  \r\n        DirPathTo <- paste(\".\\\\train\\\\\",inputFile[i,2],sep=\"\")  \r\n        if(!file.exists(DirPathTo)){\r\n            a<-dir.create(DirPathTo)\r\n         } \r\n         filePathTo <- paste(DirPathTo,\"\\\\\",inputFile[i,1],sep=\"\")  \r\n         success<-file.copy(from = filePathFrom,  to = filePathTo)\r\n         cat (\"Copied \",filePathTo,\" = \", success, \"\\n\")\r\n}",
      "votes": null
    },
    {
      "id": "91584",
      "postDate": "09/04/2015 15:43:42",
      "content": "<p>I don't use Matlab, so I wrote a script to make it easy to generate positive and negative images for a Cascade classifier. This uses OpenCV (cv2) and Tkinter. </p>\n\n<p>For each image loaded click on any two diagonal corners of the rectangle you'd like to form to crop an image around the desired 'positive' portion of the photo. This will be saved in your 'positive' directory. Four 'negative' images will be saved in your 'negative' directory, corresponding to the 4 rectangular areas that can be cut out of the original photo without including the 'positive' region. This script pairs with user Inversion's image-sorting script above.</p>",
      "rawMarkdown": "I don't use Matlab, so I wrote a script to make it easy to generate positive and negative images for a Cascade classifier. This uses OpenCV (cv2) and Tkinter. \r\n\r\nFor each image loaded click on any two diagonal corners of the rectangle you'd like to form to crop an image around the desired 'positive' portion of the photo. This will be saved in your 'positive' directory. Four 'negative' images will be saved in your 'negative' directory, corresponding to the 4 rectangular areas that can be cut out of the original photo without including the 'positive' region. This script pairs with user Inversion's image-sorting script above.",
      "votes": null
    },
    {
      "id": "91592",
      "postDate": "09/04/2015 16:41:26",
      "content": "<p>Does there exists good algorithms for automatically cropping of whales ? </p>",
      "rawMarkdown": "Does there exists good algorithms for automatically cropping of whales ?",
      "votes": null
    },
    {
      "id": "92674",
      "postDate": "09/15/2015 11:33:32",
      "content": "<p>@CauchyKun: Really great script, thanks for sharing!</p>\n\n<p>I've never made an object detector before. Does it matter when forming positive and negative training regions that they are similar in shape and size? I haven't thought yet how my classifier is going to work, but I could imagine it matters...</p>",
      "rawMarkdown": "CauchyKun: Really great script, thanks for sharing!\r\n\r\nI've never made an object detector before. Does it matter when forming positive and negative training regions that they are similar in shape and size? I haven't thought yet how my classifier is going to work, but I could imagine it matters...",
      "votes": null
    },
    {
      "id": "92930",
      "postDate": "09/18/2015 21:00:06",
      "content": "<p>Python is overkill ;-)\nHere is two lines in  Bash  for the same thing:</p>\n\n<pre><code># create directories structure\ntail -n +2 train.csv | cut -d, -f2 | uniq | while read whale; do mkdir -p train/$whale; done\n# copy files\ntail -n +2 train.csv | cut -d, --fields=1-2 --output-delimiter=' ' | while read image whale; do cp imgs/$image train/$whale/$image; done\n</code></pre>\n\n<p>Run in directory with <strong><em>train.csv</em></strong> and <strong><em>imgs</em></strong>.</p>",
      "rawMarkdown": "Python is overkill ;-)\r\nHere is two lines in  Bash  for the same thing:\r\n\r\n    # create directories structure\r\n    tail -n +2 train.csv | cut -d, -f2 | uniq | while read whale; do mkdir -p train/$whale; done\r\n# copy files\r\ntail -n +2 train.csv | cut -d, --fields=1-2 --output-delimiter=' ' | while read image whale; do cp imgs/$image train/$whale/$image; done\r\n\r\nRun in directory with ***train.csv*** and ***imgs***.",
      "votes": null
    },
    {
      "id": "92933",
      "postDate": "09/18/2015 21:12:13",
      "content": "<p>[quote=Rasim Akhunzyanov;92930]</p>\n\n<p>Python is overkill ;-)\nHere is two lines in  Bash  for the same thing:</p>\n\n<pre><code># create directories structure\ntail -n +2 train.csv | cut -d, -f2 | uniq | while read whale; do mkdir -p train/$whale; done\n# copy files\ntail -n +2 train.csv | cut -d, --fields=1-2 --output-delimiter=' ' | while read image whale; do cp imgs/$image train/$whale/$image; done\n</code></pre>\n\n<p>Run in directory with <strong><em>train.csv</em></strong> and <strong><em>imgs</em></strong>.</p>\n\n<p>[/quote]</p>\n\n<p>Showoff.  :-)</p>\n\n<p>Anyway, I could've done it in one line of python had I, too, used semi-colons.  ;-)</p>",
      "rawMarkdown": "[quote=Rasim Akhunzyanov;92930]\r\n\r\nPython is overkill ;-)\r\nHere is two lines in  Bash  for the same thing:\r\n\r\n    # create directories structure\r\n    tail -n +2 train.csv | cut -d, -f2 | uniq | while read whale; do mkdir -p train/$whale; done\r\n# copy files\r\ntail -n +2 train.csv | cut -d, --fields=1-2 --output-delimiter=' ' | while read image whale; do cp imgs/$image train/$whale/$image; done\r\n\r\nRun in directory with ***train.csv*** and ***imgs***.\r\n\r\n[/quote]\r\n\r\nShowoff.  :-)\r\n\r\nAnyway, I could've done it in one line of python had I, too, used semi-colons.  ;-)",
      "votes": null
    },
    {
      "id": "93130",
      "postDate": "09/21/2015 21:37:32",
      "content": "<p>[quote=Rasim Akhunzyanov;92930]</p>\n\n<p>Python is overkill ;-)\nHere is two lines in  Bash  for the same thing:</p>\n\n<pre><code># create directories structure\ntail -n +2 train.csv | cut -d, -f2 | uniq | while read whale; do mkdir -p train/$whale; done\n# copy files\ntail -n +2 train.csv | cut -d, --fields=1-2 --output-delimiter=' ' | while read image whale; do cp imgs/$image train/$whale/$image; done\n</code></pre>\n\n<p>Run in directory with <strong><em>train.csv</em></strong> and <strong><em>imgs</em></strong>.</p>\n\n<p>[/quote]</p>\n\n<p>To make it OSX compatible, replace the second command with:</p>\n\n<pre><code># copy files\ntail -n +2 train.csv | tr ',' ' ' | while read image whale; do cp imgs/$image train/$whale/$image; done\n</code></pre>",
      "rawMarkdown": "[quote=Rasim Akhunzyanov;92930]\r\n\r\nPython is overkill ;-)\r\nHere is two lines in  Bash  for the same thing:\r\n\r\n    # create directories structure\r\n    tail -n +2 train.csv | cut -d, -f2 | uniq | while read whale; do mkdir -p train/$whale; done\r\n# copy files\r\ntail -n +2 train.csv | cut -d, --fields=1-2 --output-delimiter=' ' | while read image whale; do cp imgs/$image train/$whale/$image; done\r\n\r\nRun in directory with ***train.csv*** and ***imgs***.\r\n\r\n[/quote]\r\n\r\nTo make it OSX compatible, replace the second command with:\r\n\r\n    # copy files\r\n    tail -n +2 train.csv | tr ',' ' ' | while read image whale; do cp imgs/$image train/$whale/$image; done",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 91561,
      "author_name": "tomtillo",
      "author_url": "",
      "post_date": "09/04/2015 08:50:11",
      "content": "<p>And the same for those who like  R - Only difference ( it doesnt move the image - creates a copy in another folder called train)</p>\n\n<hr>\n\n<pre><code>setwd (&quot;E:\\\\Kaggle\\\\whale\\\\data&quot;)\n\ninputFile &lt;-  read.csv(&quot;train.csv&quot;,header=T)\nfor(i in 1:nrow(inputFile)) { \n   filePathFrom &lt;- paste(&quot;.\\\\imgs\\\\&quot;,inputFile[i,1],sep=&quot;&quot;)\n   filePathTo &lt;- paste(&quot;.\\\\train\\\\&quot;,inputFile[i,1],sep=&quot;&quot;)  \n   cat(&quot; file exist= &quot;,file.exists(filePathFrom),&quot; &quot;,filePathFrom)\n   success&lt;-file.copy(from = filePathFrom,  to = filePathTo)\n   cat (&quot; Copied = &quot;, success, &quot;\\n&quot;)\n</code></pre>\n\n<p>}</p>\n\n<hr>\n\n<p>Or to create individual directories for each whale - </p>\n\n<pre><code>setwd (&quot;E:\\\\Kaggle\\\\whale\\\\data&quot;)\ninputFile &lt;-  read.csv(&quot;train.csv&quot;,header=T)\n for(i in 1:nrow(inputFile)){\n    filePathFrom &lt;- paste(&quot;.\\\\imgs\\\\&quot;,inputFile[i,1],sep=&quot;&quot;)  \n    DirPathTo &lt;- paste(&quot;.\\\\train\\\\&quot;,inputFile[i,2],sep=&quot;&quot;)  \n    if(!file.exists(DirPathTo)){\n        a&lt;-dir.create(DirPathTo)\n     } \n     filePathTo &lt;- paste(DirPathTo,&quot;\\\\&quot;,inputFile[i,1],sep=&quot;&quot;)  \n     success&lt;-file.copy(from = filePathFrom,  to = filePathTo)\n     cat (&quot;Copied &quot;,filePathTo,&quot; = &quot;, success, &quot;\\n&quot;)\n</code></pre>\n\n<p>}</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 91584,
      "author_name": "cauchykun",
      "author_url": "",
      "post_date": "09/04/2015 15:43:42",
      "content": "<p>I don't use Matlab, so I wrote a script to make it easy to generate positive and negative images for a Cascade classifier. This uses OpenCV (cv2) and Tkinter. </p>\n\n<p>For each image loaded click on any two diagonal corners of the rectangle you'd like to form to crop an image around the desired 'positive' portion of the photo. This will be saved in your 'positive' directory. Four 'negative' images will be saved in your 'negative' directory, corresponding to the 4 rectangular areas that can be cut out of the original photo without including the 'positive' region. This script pairs with user Inversion's image-sorting script above.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 91592,
      "author_name": "usixuz",
      "author_url": "",
      "post_date": "09/04/2015 16:41:26",
      "content": "<p>Does there exists good algorithms for automatically cropping of whales ? </p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 92674,
      "author_name": "devonbrackbill",
      "author_url": "",
      "post_date": "09/15/2015 11:33:32",
      "content": "<p>@CauchyKun: Really great script, thanks for sharing!</p>\n\n<p>I've never made an object detector before. Does it matter when forming positive and negative training regions that they are similar in shape and size? I haven't thought yet how my classifier is going to work, but I could imagine it matters...</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 92930,
      "author_name": "rasimakhunzyanov",
      "author_url": "",
      "post_date": "09/18/2015 21:00:06",
      "content": "<p>Python is overkill ;-)\nHere is two lines in  Bash  for the same thing:</p>\n\n<pre><code># create directories structure\ntail -n +2 train.csv | cut -d, -f2 | uniq | while read whale; do mkdir -p train/$whale; done\n# copy files\ntail -n +2 train.csv | cut -d, --fields=1-2 --output-delimiter=' ' | while read image whale; do cp imgs/$image train/$whale/$image; done\n</code></pre>\n\n<p>Run in directory with <strong><em>train.csv</em></strong> and <strong><em>imgs</em></strong>.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 92933,
      "author_name": "inversion",
      "author_url": "",
      "post_date": "09/18/2015 21:12:13",
      "content": "<p>[quote=Rasim Akhunzyanov;92930]</p>\n\n<p>Python is overkill ;-)\nHere is two lines in  Bash  for the same thing:</p>\n\n<pre><code># create directories structure\ntail -n +2 train.csv | cut -d, -f2 | uniq | while read whale; do mkdir -p train/$whale; done\n# copy files\ntail -n +2 train.csv | cut -d, --fields=1-2 --output-delimiter=' ' | while read image whale; do cp imgs/$image train/$whale/$image; done\n</code></pre>\n\n<p>Run in directory with <strong><em>train.csv</em></strong> and <strong><em>imgs</em></strong>.</p>\n\n<p>[/quote]</p>\n\n<p>Showoff.  :-)</p>\n\n<p>Anyway, I could've done it in one line of python had I, too, used semi-colons.  ;-)</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 93130,
      "author_name": "isabelmoreno",
      "author_url": "",
      "post_date": "09/21/2015 21:37:32",
      "content": "<p>[quote=Rasim Akhunzyanov;92930]</p>\n\n<p>Python is overkill ;-)\nHere is two lines in  Bash  for the same thing:</p>\n\n<pre><code># create directories structure\ntail -n +2 train.csv | cut -d, -f2 | uniq | while read whale; do mkdir -p train/$whale; done\n# copy files\ntail -n +2 train.csv | cut -d, --fields=1-2 --output-delimiter=' ' | while read image whale; do cp imgs/$image train/$whale/$image; done\n</code></pre>\n\n<p>Run in directory with <strong><em>train.csv</em></strong> and <strong><em>imgs</em></strong>.</p>\n\n<p>[/quote]</p>\n\n<p>To make it OSX compatible, replace the second command with:</p>\n\n<pre><code># copy files\ntail -n +2 train.csv | tr ',' ' ' | while read image whale; do cp imgs/$image train/$whale/$image; done\n</code></pre>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "91274": "This script creates folders for each of the 447 whales, and moves the *training* images into the corresponding folder. The test images stay put.\r\n\r\nThis makes it easier if you want to manually crop images (and avoid touching the test images), check out images of the same whale, etc.\r\n\r\n...\r\n\r\n\r\n    import os\r\n    import pandas as pd\r\n    \r\n    train = pd.read_csv('train.csv', index_col='Image')\r\n    \r\n    whaleIDs = list(train['whaleID'].unique())\r\n    \r\n    for w in whaleIDs:\r\n      os.makedirs('./imgs/'+w)\r\n      \r\n    for image in train.index:\r\n      folder = train.loc[image, 'whaleID']\r\n      old = './imgs/{}'.format(image)\r\n      new = './imgs/{}/{}'.format(folder, image)\r\n      try:\r\n        os.rename(old, new)\r\n      except:\r\n        print('{} - {}'.format(image,folder))",
    "91561": "And the same for those who like  R - Only difference ( it doesnt move the image - creates a copy in another folder called train)\r\n\r\n------------------------------\r\n    setwd (\"E:\\\\Kaggle\\\\whale\\\\data\")\r\n\r\n    inputFile <-  read.csv(\"train.csv\",header=T)\r\n    for(i in 1:nrow(inputFile)) { \r\n       filePathFrom <- paste(\".\\\\imgs\\\\\",inputFile[i,1],sep=\"\")\r\n       filePathTo <- paste(\".\\\\train\\\\\",inputFile[i,1],sep=\"\")  \r\n       cat(\" file exist= \",file.exists(filePathFrom),\" \",filePathFrom)\r\n       success<-file.copy(from = filePathFrom,  to = filePathTo)\r\n       cat (\" Copied = \", success, \"\\n\")\r\n}\r\n\r\n------------------------------\r\n\r\nOr to create individual directories for each whale - \r\n\r\n    setwd (\"E:\\\\Kaggle\\\\whale\\\\data\")\r\n    inputFile <-  read.csv(\"train.csv\",header=T)\r\n     for(i in 1:nrow(inputFile)){\r\n        filePathFrom <- paste(\".\\\\imgs\\\\\",inputFile[i,1],sep=\"\")  \r\n        DirPathTo <- paste(\".\\\\train\\\\\",inputFile[i,2],sep=\"\")  \r\n        if(!file.exists(DirPathTo)){\r\n            a<-dir.create(DirPathTo)\r\n         } \r\n         filePathTo <- paste(DirPathTo,\"\\\\\",inputFile[i,1],sep=\"\")  \r\n         success<-file.copy(from = filePathFrom,  to = filePathTo)\r\n         cat (\"Copied \",filePathTo,\" = \", success, \"\\n\")\r\n}",
    "91584": "I don't use Matlab, so I wrote a script to make it easy to generate positive and negative images for a Cascade classifier. This uses OpenCV (cv2) and Tkinter. \r\n\r\nFor each image loaded click on any two diagonal corners of the rectangle you'd like to form to crop an image around the desired 'positive' portion of the photo. This will be saved in your 'positive' directory. Four 'negative' images will be saved in your 'negative' directory, corresponding to the 4 rectangular areas that can be cut out of the original photo without including the 'positive' region. This script pairs with user Inversion's image-sorting script above.",
    "91592": "Does there exists good algorithms for automatically cropping of whales ?",
    "92674": "CauchyKun: Really great script, thanks for sharing!\r\n\r\nI've never made an object detector before. Does it matter when forming positive and negative training regions that they are similar in shape and size? I haven't thought yet how my classifier is going to work, but I could imagine it matters...",
    "92930": "Python is overkill ;-)\r\nHere is two lines in  Bash  for the same thing:\r\n\r\n    # create directories structure\r\n    tail -n +2 train.csv | cut -d, -f2 | uniq | while read whale; do mkdir -p train/$whale; done\r\n# copy files\r\ntail -n +2 train.csv | cut -d, --fields=1-2 --output-delimiter=' ' | while read image whale; do cp imgs/$image train/$whale/$image; done\r\n\r\nRun in directory with ***train.csv*** and ***imgs***.",
    "92933": "[quote=Rasim Akhunzyanov;92930]\r\n\r\nPython is overkill ;-)\r\nHere is two lines in  Bash  for the same thing:\r\n\r\n    # create directories structure\r\n    tail -n +2 train.csv | cut -d, -f2 | uniq | while read whale; do mkdir -p train/$whale; done\r\n# copy files\r\ntail -n +2 train.csv | cut -d, --fields=1-2 --output-delimiter=' ' | while read image whale; do cp imgs/$image train/$whale/$image; done\r\n\r\nRun in directory with ***train.csv*** and ***imgs***.\r\n\r\n[/quote]\r\n\r\nShowoff.  :-)\r\n\r\nAnyway, I could've done it in one line of python had I, too, used semi-colons.  ;-)",
    "93130": "[quote=Rasim Akhunzyanov;92930]\r\n\r\nPython is overkill ;-)\r\nHere is two lines in  Bash  for the same thing:\r\n\r\n    # create directories structure\r\n    tail -n +2 train.csv | cut -d, -f2 | uniq | while read whale; do mkdir -p train/$whale; done\r\n# copy files\r\ntail -n +2 train.csv | cut -d, --fields=1-2 --output-delimiter=' ' | while read image whale; do cp imgs/$image train/$whale/$image; done\r\n\r\nRun in directory with ***train.csv*** and ***imgs***.\r\n\r\n[/quote]\r\n\r\nTo make it OSX compatible, replace the second command with:\r\n\r\n    # copy files\r\n    tail -n +2 train.csv | tr ',' ' ' | while read image whale; do cp imgs/$image train/$whale/$image; done"
  },
  "source": "meta"
}