{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":21755,"databundleVersionId":1475600,"sourceType":"competition"}],"dockerImageVersionId":30787,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nimport glob\nfrom PIL import Image\nimport zipfile\n\n!git clone https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix\n%cd pytorch-CycleGAN-and-pix2pix\n\n!bash ./scripts/download_cyclegan_model.sh style_monet\n\n!pip install -r requirements.txt\n!pip install Pillow\n\npreprocessed_dir = '/kaggle/working/preprocessed_images'\nos.makedirs(preprocessed_dir, exist_ok=True)\n\nsource_dir = '/kaggle/input/gan-getting-started/photo_jpg'\ntarget_size = (256, 256)\n\nfor img_path in glob.glob(os.path.join(source_dir, '*')):\n    img = Image.open(img_path).resize(target_size).convert('RGB')\n    img.save(os.path.join(preprocessed_dir, os.path.basename(img_path)))\n\nprint(f\"Number of preprocessed images: {len(os.listdir(preprocessed_dir))}\")","metadata":{"execution":{"iopub.status.busy":"2024-11-19T11:18:55.274874Z","iopub.execute_input":"2024-11-19T11:18:55.275237Z","iopub.status.idle":"2024-11-19T11:20:14.879097Z","shell.execute_reply.started":"2024-11-19T11:18:55.275197Z","shell.execute_reply":"2024-11-19T11:20:14.877708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!python test.py --dataroot /kaggle/working/preprocessed_images --name style_monet_pretrained --model test --no_dropout --gpu_ids -1 --num_test 7035","metadata":{"execution":{"iopub.status.busy":"2024-11-19T11:20:14.881295Z","iopub.execute_input":"2024-11-19T11:20:14.881654Z","iopub.status.idle":"2024-11-19T13:21:54.937374Z","shell.execute_reply.started":"2024-11-19T11:20:14.881618Z","shell.execute_reply":"2024-11-19T13:21:54.936181Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"with zipfile.ZipFile('/kaggle/working/images.zip', 'w') as zipf:\n    generated_dir = './results/style_monet_pretrained/test_latest/images'\n\n    count = 0\n    for img_path in glob.glob(os.path.join(generated_dir, '*_fake.png')):\n        # Convert PNG to JPEG and write to the zip file\n        img = Image.open(img_path).convert('RGB')\n        img_jpeg_path = img_path.replace('.png', '.jpg')\n        img.save(img_jpeg_path, 'JPEG')\n        \n        zipf.write(img_jpeg_path, os.path.basename(img_jpeg_path))\n        count += 1\n\n    print(f\"Total images added to zip: {count}\")","metadata":{"execution":{"iopub.status.busy":"2024-11-19T13:53:35.456066Z","iopub.execute_input":"2024-11-19T13:53:35.456685Z","iopub.status.idle":"2024-11-19T13:54:04.603802Z","shell.execute_reply.started":"2024-11-19T13:53:35.456642Z","shell.execute_reply":"2024-11-19T13:54:04.602621Z"},"trusted":true},"execution_count":null,"outputs":[]}]}