File size: 2,339 Bytes
ec1cb04 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from PIL import Image"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"def copy(src, dest):\n",
" for sub in os.listdir(src):\n",
" for file in os.listdir(os.path.join(src, sub)):\n",
" image = Image.open(os.path.join(src, sub, file))\n",
"\n",
" # resize image, min(height, width) = 512\n",
" if image.size[0] < image.size[1]:\n",
" image = image.resize((512, int(512 * image.size[1] / image.size[0])))\n",
" else:\n",
" image = image.resize((int(512 * image.size[0] / image.size[1]), 512))\n",
"\n",
" image.save(os.path.join(dest, file))\n",
"\n",
"datasets = '/home/qninh/Downloads/rgb_anon'\n",
"\n",
"# build cyclegan dataset\n",
"for type in ['fog', 'rain', 'snow', 'night']:\n",
" path = os.path.join(datasets, type)\n",
"\n",
" os.makedirs(f'./datasets/{type}/trainA', exist_ok=True)\n",
" os.makedirs(f'./datasets/{type}/trainB', exist_ok=True)\n",
" os.makedirs(f'./datasets/{type}/testA', exist_ok=True)\n",
" os.makedirs(f'./datasets/{type}/testB', exist_ok=True)\n",
"\n",
" copy(os.path.join(path, \"train_ref\"), f\"./datasets/{type}/trainA\")\n",
" copy(os.path.join(path, \"test_ref\"), f\"./datasets/{type}/trainA\")\n",
"\n",
" copy(os.path.join(path, \"train\"), f\"./datasets/{type}/trainB\")\n",
" copy(os.path.join(path, \"test\"), f\"./datasets/{type}/testB\")\n",
"\n",
" copy(os.path.join(path, \"val_ref\"), f\"./datasets/{type}/testA\")\n",
" copy(os.path.join(path, \"val\"), f\"./datasets/{type}/testB\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"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.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|