{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "_cell_guid": "5a3e3197-6d86-c10c-d6b6-fb23be8a8858"
      },
      "source": [
        "Code to move incorrect labeled images. If you downloaded or torrented the additional files before the kaggle fixed the labels, you can run this piece of code to clean up. Just download the `fixed_labels.csv` and `removed_files.csv` files and set the `ADDITIONAL_DIR` variable to match your environment."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "_cell_guid": "9b3afe9e-9914-cd7e-b3cf-536ebbec2c8d"
      },
      "outputs": [],
      "source": [
        "import os\n",
        "import shutil\n",
        "\n",
        "FIXED_LABELS = \"fixed_labels.csv\"\n",
        "REMOVE_LABELS = \"removed_files.csv\"\n",
        "ADDITIONAL_DIR = \"./additional/\"\n",
        "\n",
        "os.mkdir( ADDITIONAL_DIR + \"remove\" )\n",
        "for csvfile in [FIXED_LABELS, REMOVE_LABELS]:\n",
        "    with open(csvfile) as f:\n",
        "        lines = f.readlines()[1:]\n",
        "        for line in lines:\n",
        "            filename, old_label, new_label = (x.strip() for x in line.split(','))\n",
        "            try:\n",
        "                shutil.move( ADDITIONAL_DIR + old_label + '/' + filename,\n",
        "                             ADDITIONAL_DIR + new_label + '/' + filename)\n",
        "                print(\"moved '{}' to '{}'\".format(filename, new_label))\n",
        "            except:\n",
        "                print(\"Cannot move '{}' to '{}'\".format(filename, new_label))\n",
        "                continue"
      ]
    }
  ],
  "metadata": {
    "_change_revision": 0,
    "_is_fork": false,
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.6.0"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}