Skip to content
Snippets Groups Projects
01-Preparation-of-data.ipynb 1.8 MiB
Newer Older
    "    # ---- done\n",
    "    size=os.path.getsize(filename)/(1024*1024)\n",
    "    print('Dataset : {:24s}  shape : {:22s} size : {:6.1f} Mo   (saved)\\n'.format(filename, str(x_train.shape),size))"
Jean-Luc Parouty's avatar
Jean-Luc Parouty committed
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div class='todo'>\n",
    "    Create enhanced datasets and save them will take about 7-8' and using about 9 GB<br>\n",
    "    To perform tests, change the code below to use :\n",
    "    <li> a local folder (./data),\n",
    "    <li>a subset of the dataset, for example 2000 images.\n",
    "</div>"
Jean-Luc Parouty's avatar
Jean-Luc Parouty committed
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
Jean-Luc Parouty's avatar
Jean-Luc Parouty committed
   "metadata": {},
Jean-Luc Parouty's avatar
Jean-Luc Parouty committed
   "source": [
Jean-Luc Parouty's avatar
Jean-Luc Parouty committed
    "%%time\n",
    "\n",
    "# ---- Uncomment to write h5 datasets in the project place\n",
    "#\n",
    "output_dir = dataset_dir\n",
    "\n",
    "# ---- Uncomment to write h5 datasets in a local place (for small tests only !)\n",
    "#\n",
    "# output_dir = './data'\n",
    "# ooo.mkdir(output_dir)\n",
    "\n",
Jean-Luc Parouty's avatar
Jean-Luc Parouty committed
    "for s in [24, 48]:\n",
    "    for m in ['RGB', 'RGB-HE', 'L', 'L-LHE']:\n",
    "        # ---- A nice dataset name\n",
    "        filename = f'{output_dir}/set-{s}x{s}-{m}.h5'\n",
    "        print(\"\\nDataset : \",filename)\n",
Jean-Luc Parouty's avatar
Jean-Luc Parouty committed
    "        # ---- Enhancement\n",
    "        x_train_new = images_enhancement( x_train, width=s, height=s, mode=m )\n",
    "        x_test_new  = images_enhancement( x_test,  width=s, height=s, mode=m )\n",
Jean-Luc Parouty's avatar
Jean-Luc Parouty committed
    "        x_meta_new  = images_enhancement( x_meta,  width=s, height=s, mode='RGB' )\n",
Jean-Luc Parouty's avatar
Jean-Luc Parouty committed
    "        # ---- Save\n",
    "        save_h5_dataset( x_train_new, y_train, x_test_new, y_test, x_meta_new,y_meta, filename)\n",
Jean-Luc Parouty's avatar
Jean-Luc Parouty committed
    "\n",
    "x_train_new,x_test_new=0,0\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div class='todo'>\n",
    "  Adapt the code below to read :\n",
    "  <ul>\n",
    "      <li>the different h5 datasets you saved in ./data,</li>\n",
    "      <li>The h5 datasets available in the Fidle project datasets directory.</li>\n",
    "  </ul>\n",
    " \n",
    "</div>"
   ]
  },
Jean-Luc Parouty's avatar
Jean-Luc Parouty committed
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 7 - Reload data to be sure ;-)"
Jean-Luc Parouty's avatar
Jean-Luc Parouty committed
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
Jean-Luc Parouty's avatar
Jean-Luc Parouty committed
   "metadata": {},
Jean-Luc Parouty's avatar
Jean-Luc Parouty committed
   "source": [
    "%%time\n",
    "\n",
Jean-Luc Parouty's avatar
Jean-Luc Parouty committed
    "dataset='set-48x48-L'\n",
Jean-Luc Parouty's avatar
Jean-Luc Parouty committed
    "samples=range(24)\n",
    "\n",
    "with  h5py.File(f'{output_dir}/{dataset}.h5','r') as f:\n",
    "    x_tmp = f['x_train'][:]\n",
    "    y_tmp = f['y_train'][:]\n",
    "    print(\"dataset loaded from h5 file.\")\n",
Jean-Luc Parouty's avatar
Jean-Luc Parouty committed
    "\n",
    "ooo.plot_images(x_tmp,y_tmp, samples, columns=8, x_size=2, y_size=2, colorbar=False, y_pred=None, cm='binary')\n",
    "x_tmp,y_tmp=0,0"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
Jean-Luc Parouty's avatar
Jean-Luc Parouty committed
    "<img width=\"80px\" src=\"../fidle/img/00-Fidle-logo-01.svg\"></img>"
Jean-Luc Parouty's avatar
Jean-Luc Parouty committed
   ]
  }
 ],
 "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",
Jean-Luc Parouty's avatar
Jean-Luc Parouty committed
   "version": "3.7.6"
Jean-Luc Parouty's avatar
Jean-Luc Parouty committed
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}