Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ESGD-M optimizer #18

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions StyleGAN3+CLIP.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/ouhenio/StyleGAN3-CLIP-notebooks/blob/save-images-with-custom-name/StyleGAN3%2BCLIP.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
"<a href=\"https://colab.research.google.com/github/ouhenio/StyleGAN3-CLIP-notebooks/blob/add-esgd-m-optimizer-option/StyleGAN3%2BCLIP.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
Expand Down Expand Up @@ -102,12 +102,14 @@
"#!pip install --upgrade https://download.pytorch.org/whl/nightly/cu111/torch-1.11.0.dev20211012%2Bcu111-cp37-cp37m-linux_x86_64.whl https://download.pytorch.org/whl/nightly/cu111/torchvision-0.12.0.dev20211012%2Bcu111-cp37-cp37m-linux_x86_64.whl\n",
"!git clone https://github.com/NVlabs/stylegan3\n",
"!git clone https://github.com/openai/CLIP\n",
"!git clone https://github.com/crowsonkb/esgd.git\n",
"!pip install -e ./CLIP\n",
"!pip install einops ninja\n",
"\n",
"import sys\n",
"sys.path.append('./CLIP')\n",
"sys.path.append('./stylegan3')\n",
"sys.path.append('./esgd')\n",
"\n",
"import io\n",
"import os, time, glob\n",
Expand All @@ -123,6 +125,7 @@
"import clip\n",
"import unicodedata\n",
"import re\n",
"from esgd import ESGD\n",
"from tqdm.notebook import tqdm\n",
"from torchvision.transforms import Compose, Resize, ToTensor, Normalize\n",
"from IPython.display import display\n",
Expand Down Expand Up @@ -369,8 +372,7 @@
{
"cell_type": "code",
"metadata": {
"id": "QXoRP4SHzJ6i",
"cellView": "form"
"id": "QXoRP4SHzJ6i"
},
"source": [
"#@markdown #**Run the model** 🚀\n",
Expand Down Expand Up @@ -408,15 +410,16 @@
"\n",
" # Sampling loop\n",
" q_ema = q\n",
" opt = torch.optim.AdamW([q], lr=0.03, betas=(0.0,0.999))\n",
" opt = ESGD([q], lr=1, betas=(0.9, 0.999), v=0.9)\n",
" # opt = torch.optim.AdamW([q], lr=0.03, betas=(0.0,0.999))\n",
" loop = tqdm(range(steps))\n",
" for i in loop:\n",
" opt.zero_grad()\n",
" w = q * w_stds\n",
" image = G.synthesis(w + G.mapping.w_avg, noise_mode='const')\n",
" embed = embed_image(image.add(1).div(2))\n",
" loss = prompts_dist_loss(embed, targets, spherical_dist_loss).mean()\n",
" loss.backward()\n",
" loss.backward(create_graph=opt.should_create_graph())\n",
" opt.step()\n",
" loop.set_postfix(loss=loss.item(), q_magnitude=q.std().item())\n",
"\n",
Expand Down