{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","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":30822,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:08:24.528442Z","iopub.execute_input":"2024-12-21T09:08:24.528689Z","iopub.status.idle":"2024-12-21T09:08:30.201577Z","shell.execute_reply.started":"2024-12-21T09:08:24.528666Z","shell.execute_reply":"2024-12-21T09:08:30.200374Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\nimport glob\nfrom PIL import Image\nimport zipfile\n\n# Clone repository CycleGAN dan Pix2Pix\n!git clone https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix\n%cd pytorch-CycleGAN-and-pix2pix\n\n# Unduh model style Monet untuk CycleGAN\n!bash ./scripts/download_cyclegan_model.sh style_monet\n\n# Install dependencies yang diperlukan\n!pip install -r requirements.txt\n!pip install Pillow\n\n# Direktori untuk menyimpan gambar yang sudah diproses\noutput_directory = '/kaggle/working/preprocessed_images'\nos.makedirs(output_directory, exist_ok=True)\n\n# Direktori sumber dan ukuran target gambar\nsource_directory = '/kaggle/input/gan-getting-started/photo_jpg'\nresize_to = (256, 256)\n\n# Resize dan konversi gambar\nfor image_path in glob.glob(os.path.join(source_directory, '*')):\n    with Image.open(image_path) as img:\n        img_resized = img.resize(resize_to).convert('RGB')\n        img_resized.save(os.path.join(output_directory, os.path.basename(image_path)))\n\nprint(f\"Jumlah gambar yang diproses: {len(os.listdir(output_directory))}\")\n\n# Jalankan model untuk menghasilkan gambar dengan gaya Monet\n!python test.py --dataroot /kaggle/working/preprocessed_images --name style_monet_pretrained --model test --no_dropout --gpu_ids -1 --num_test 7035\n\n# Kompres hasil ke file ZIP\nwith zipfile.ZipFile('/kaggle/working/images.zip', 'w') as zip_file:\n    generated_images_dir = './results/style_monet_pretrained/test_latest/images'\n    total_images = 0\n\n    for fake_image_path in glob.glob(os.path.join(generated_images_dir, '*_fake.png')):\n        with Image.open(fake_image_path) as fake_img:\n            fake_img_jpeg = fake_image_path.replace('.png', '.jpg')\n            fake_img.convert('RGB').save(fake_img_jpeg, 'JPEG')\n            \n            zip_file.write(fake_img_jpeg, os.path.basename(fake_img_jpeg))\n            total_images += 1\n\n    print(f\"Total gambar yang dimasukkan ke ZIP: {total_images}\")\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-21T09:08:36.405589Z","iopub.execute_input":"2024-12-21T09:08:36.405919Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}