{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import shutil\n",
    "from tqdm import tqdm\n",
    "from pathlib import Path\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "generated_dataset_path = Path('generated_ffhq_smile/images')\n",
    "new_dataset_path = Path('ffhq_smile_pix2pixHD')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "train_A_path = new_dataset_path / 'train_A'\n",
    "train_B_path = new_dataset_path / 'train_B'\n",
    "train_C_path = new_dataset_path / 'train_C'\n",
    "\n",
    "train_A_path.mkdir(parents=True, exist_ok=True)\n",
    "train_B_path.mkdir(parents=True, exist_ok=True)\n",
    "train_C_path.mkdir(parents=True, exist_ok=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "all_paths = list(generated_dataset_path.iterdir())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "source_paths = [p for p in all_paths if 'tr' not in str(p)]\n",
    "neg_paths = [p for p in all_paths if 'tr' in str(p) and '-' in str(p)]\n",
    "pos_paths = [p for p in all_paths if 'tr' in str(p) and '-' not in str(p)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "len(source_paths), len(neg_paths), len(pos_paths)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i, (source, neg, pos) in tqdm(enumerate(zip(sorted(source_paths, key=lambda x: x.name.split('.')[0] + '_'),\n",
    "                                                sorted(neg_paths), sorted(pos_paths)))):\n",
    "    shutil.copy(source, train_A_path / f'{i}.png')\n",
    "    shutil.copy(pos, train_B_path / f'{i}.png')\n",
    "    shutil.copy(neg, train_C_path / f'{i}.png')"
   ]
  }
 ],
 "metadata": {
  "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.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
