|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": null, |
| 6 | + "metadata": { |
| 7 | + "id": "-ksoUw_9uFDY" |
| 8 | + }, |
| 9 | + "outputs": [], |
| 10 | + "source": [ |
| 11 | + "#@title Setup (Do NOT modify)\n", |
| 12 | + "from google.colab import drive\n", |
| 13 | + "drive.mount('/content/drive')\n", |
| 14 | + "%cd /content/drive/MyDrive/final\n", |
| 15 | + "!pip install openai-clip" |
| 16 | + ] |
| 17 | + }, |
| 18 | + { |
| 19 | + "cell_type": "code", |
| 20 | + "execution_count": null, |
| 21 | + "metadata": { |
| 22 | + "id": "ZSaektzjZbKG" |
| 23 | + }, |
| 24 | + "outputs": [], |
| 25 | + "source": [ |
| 26 | + "#@title Data preprocessing (Train)\n", |
| 27 | + "!python preproc_datasets_celeba_zip_train.py --source=./multimodal_celeba_hq.zip --dest train_data_6cap.zip --emb_dim 512 --transform=center-crop --width=256 --height=256" |
| 28 | + ] |
| 29 | + }, |
| 30 | + { |
| 31 | + "cell_type": "code", |
| 32 | + "execution_count": null, |
| 33 | + "metadata": { |
| 34 | + "id": "Svp2gXHa4UDb" |
| 35 | + }, |
| 36 | + "outputs": [], |
| 37 | + "source": [ |
| 38 | + "#@title Data preprocessing (Test)\n", |
| 39 | + "!python preproc_datasets_celeba_zip_test.py --source=./multimodal_celeba_hq.zip --dest test_data_6cap.zip --emb_dim 512 --transform=center-crop --width=256 --height=256" |
| 40 | + ] |
| 41 | + }, |
| 42 | + { |
| 43 | + "cell_type": "code", |
| 44 | + "execution_count": null, |
| 45 | + "metadata": { |
| 46 | + "cellView": "form", |
| 47 | + "id": "pQY41tvBuJVO" |
| 48 | + }, |
| 49 | + "outputs": [], |
| 50 | + "source": [ |
| 51 | + "#@title Train\n", |
| 52 | + "\n", |
| 53 | + "train_data = \"sample_train.zip\"#@param {\"type\": \"string\"}\n", |
| 54 | + "batch_size = 24 #@param {\"type\": \"integer\"}\n", |
| 55 | + "num_epochs = 10 #@param {\"type\": \"integer\"}\n", |
| 56 | + "learning_rate = 0.0002 #@param {\"type\": \"number\"}\n", |
| 57 | + "report_interval = 50 #@param {\"type\": \"integer\"}\n", |
| 58 | + "noise_dim = 100 #@param {\"type\": \"integer\"}\n", |
| 59 | + "projection_dim = 128 #@param {\"type\": \"integer\"}\n", |
| 60 | + "clip_embedding_dim = 512 #@param {\"type\": \"integer\"}\n", |
| 61 | + "checkpoint_path = \"model_exp1\" #@param {\"type\": \"string\"}\n", |
| 62 | + "result_path = \"images_exp1\" #@param {\"type\": \"string\"}\n", |
| 63 | + "use_uncond_loss = True #@param {\"type\": \"boolean\"}\n", |
| 64 | + "use_contrastive_loss = True #@param {\"type\": \"boolean\"}\n", |
| 65 | + "num_stage = 3 #@param {\"type\": \"integer\"}\n", |
| 66 | + "resume_checkpoint_path = \"None\" #@param {\"type\": \"string\"}\n", |
| 67 | + "resume_epoch = -1 #@param {\"type\": \"integer\"}\n", |
| 68 | + "\n", |
| 69 | + "test_cmd = f'''python main.py \\\n", |
| 70 | + " --train_data \"{train_data}\" \\\n", |
| 71 | + " --batch_size {batch_size} \\\n", |
| 72 | + " --num_epochs {num_epochs} \\\n", |
| 73 | + " --learning_rate {learning_rate} \\\n", |
| 74 | + " --report_interval {report_interval} \\\n", |
| 75 | + " --noise_dim {noise_dim} \\\n", |
| 76 | + " --projection_dim {projection_dim} \\\n", |
| 77 | + " --clip_embedding_dim {clip_embedding_dim} \\\n", |
| 78 | + " --checkpoint_path \"{checkpoint_path}\" \\\n", |
| 79 | + " --result_path \"{result_path}\" \\\n", |
| 80 | + " --num_stage {num_stage} \\\n", |
| 81 | + " --resume_epoch {resume_epoch} \\\n", |
| 82 | + " '''\n", |
| 83 | + "if use_uncond_loss:\n", |
| 84 | + " test_cmd += \"--use_uncond_loss \"\n", |
| 85 | + "if use_contrastive_loss:\n", |
| 86 | + " test_cmd += \"--use_contrastive_loss \"\n", |
| 87 | + "if resume_checkpoint_path != \"None\":\n", |
| 88 | + " test_cmd += f'''--resume_checkpoint_path \"{resume_checkpoint_path}\"'''\n", |
| 89 | + "\n", |
| 90 | + "with open('./train_script.sh', 'w') as file:\n", |
| 91 | + " file.write(test_cmd)\n", |
| 92 | + "\n", |
| 93 | + "!bash train_script.sh" |
| 94 | + ] |
| 95 | + }, |
| 96 | + { |
| 97 | + "cell_type": "code", |
| 98 | + "execution_count": null, |
| 99 | + "metadata": { |
| 100 | + "cellView": "form", |
| 101 | + "id": "S7ueWJp1t-Zi" |
| 102 | + }, |
| 103 | + "outputs": [], |
| 104 | + "source": [ |
| 105 | + "#@title Test (Generate image)\n", |
| 106 | + "\n", |
| 107 | + "prompt = \"The woman is young and has blond hair, and arched eyebrows.\"#@param {\"type\": \"string\"}\n", |
| 108 | + "load_epoch = 10 #@param {\"type\": \"integer\"}\n", |
| 109 | + "checkpoint_path = \"model_exp1\" #@param {\"type\": \"string\"}\n", |
| 110 | + "\n", |
| 111 | + "test_cmd = f'''python generate_image.py \\\n", |
| 112 | + " --prompt \"{prompt}\" \\\n", |
| 113 | + " --load_epoch {load_epoch} \\\n", |
| 114 | + " --checkpoint_path \"{checkpoint_path}\"\n", |
| 115 | + " '''\n", |
| 116 | + "\n", |
| 117 | + "with open('./test_script.sh', 'w') as file:\n", |
| 118 | + " file.write(test_cmd)\n", |
| 119 | + "\n", |
| 120 | + "!bash test_script.sh\n", |
| 121 | + "\n", |
| 122 | + "\n", |
| 123 | + "from IPython.display import Image\n", |
| 124 | + "import os\n", |
| 125 | + "img_64 = Image(os.path.join(\"result_64.png\"))\n", |
| 126 | + "display(img_64)\n", |
| 127 | + "img_128 = Image(os.path.join(\"result_128.png\"))\n", |
| 128 | + "display(img_128)\n", |
| 129 | + "img_256 = Image(os.path.join(\"result_256.png\"))\n", |
| 130 | + "display(img_256)" |
| 131 | + ] |
| 132 | + }, |
| 133 | + { |
| 134 | + "cell_type": "code", |
| 135 | + "execution_count": null, |
| 136 | + "metadata": { |
| 137 | + "id": "tH5gJKdVyUuu" |
| 138 | + }, |
| 139 | + "outputs": [], |
| 140 | + "source": [] |
| 141 | + } |
| 142 | + ], |
| 143 | + "metadata": { |
| 144 | + "accelerator": "GPU", |
| 145 | + "colab": { |
| 146 | + "gpuType": "T4", |
| 147 | + "machine_shape": "hm", |
| 148 | + "provenance": [] |
| 149 | + }, |
| 150 | + "kernelspec": { |
| 151 | + "display_name": "Python 3", |
| 152 | + "name": "python3" |
| 153 | + }, |
| 154 | + "language_info": { |
| 155 | + "name": "python" |
| 156 | + } |
| 157 | + }, |
| 158 | + "nbformat": 4, |
| 159 | + "nbformat_minor": 0 |
| 160 | +} |
0 commit comments