Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
justinpinkney committed Apr 28, 2020
0 parents commit 95d62d3
Show file tree
Hide file tree
Showing 34 changed files with 431 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
models/
venv/
__pycache__/
.vscode/
16 changes: 16 additions & 0 deletions Dockerfile
@@ -0,0 +1,16 @@
FROM tensorflow/tensorflow:1.15.0-gpu-py3-jupyter

RUN pip install scipy==1.3.3
RUN pip install requests==2.22.0
RUN pip install Pillow==6.2.1

RUN apt-get update --fix-missing && apt-get install -y git wget
RUN mkdir /working
VOLUME /working

RUN mkdir /code
WORKDIR /code
RUN git clone https://github.com/NVlabs/stylegan2.git
WORKDIR /code/stylegan2

CMD /bin/bash
205 changes: 205 additions & 0 deletions README.md
@@ -0,0 +1,205 @@
# Awesome Pretrained StyleGAN2

A collection of pre-trained [StyleGAN2](https://github.com/NVlabs/stylegan2) models trained on different datasets at different resolution.

_See [this repo](https://github.com/justinpinkney/awesome-pretrained-stylegan) for pretrained models for StyleGAN 1_


[![](images/thumbs/car%20(config-e).jpg)](#car-(config-e))
[![](images/thumbs/car%20(config-f).jpg)](#car-(config-f))
[![](images/thumbs/cat.jpg)](#cat)
[![](images/thumbs/church.jpg)](#church)
[![](images/thumbs/FFHQ%20(config-e).jpg)](#FFHQ-(config-e))
[![](images/thumbs/FFHQ%20(config-f).jpg)](#FFHQ-(config-f))
[![](images/thumbs/horse.jpg)](#horse)
[![](images/thumbs/Imagenet.jpg)](#Imagenet)
[![](images/thumbs/WikiArt.jpg)](#WikiArt)
[![](images/thumbs/Anime%20portraits.jpg)](#Anime-portraits)
[![](images/thumbs/microscope%20images.jpg)](#microscope-images)
[![](images/thumbs/wildlife.jpg)](#wildlife)
[![](images/thumbs/modern%20art.jpg)](#modern-art)

If you have a publically accessible model which you know of, or would like to share please see the [contributing](#contributing) section. _Hint: the simplest way to submit a model is to fill in this [form](https://forms.gle/PE1iiTa5tNTdBFYN9)._

### Table of Contents

- Models

- [car (config-e)](#car-(config-e))
- [car (config-f)](#car-(config-f))
- [cat](#cat)
- [church](#church)
- [FFHQ (config-e)](#FFHQ-(config-e))
- [FFHQ (config-f)](#FFHQ-(config-f))
- [horse](#horse)
- [Imagenet](#Imagenet)
- [WikiArt](#WikiArt)
- [Anime portraits](#Anime-portraits)
- [microscope images](#microscope-images)
- [wildlife](#wildlife)
- [modern art](#modern-art)
- [Contributing](#contributing)


## car (config-e)

![](images/car%20(config-e).jpg)
- Dataset: LSUN Cat
- Resolution: 512x384
- Author: [NVIDIA]()
- [Download link](http://d36zk2xti64re0.cloudfront.net/stylegan2/networks/stylegan2-car-config-e.pkl)
- StyleGAN2 implementation: https://github.com/NVlabs/stylegan2
- Licence: Nvidia Source Code License-NCNvidia Source Code License-NC
- [Source](https://github.com/NVlabs/stylegan2)


## car (config-f)

![](images/car%20(config-f).jpg)
- Dataset: LSUN Cat
- Resolution: 512x384
- Author: [NVIDIA]()
- [Download link](http://d36zk2xti64re0.cloudfront.net/stylegan2/networks/stylegan2-car-config-f.pkl)
- StyleGAN2 implementation: https://github.com/NVlabs/stylegan2
- Licence: Nvidia Source Code License-NC
- [Source](https://github.com/NVlabs/stylegan2)


## cat

![](images/cat.jpg)
- Dataset: LSUN Cat
- Resolution: 256x256
- Author: [NVIDIA]()
- [Download link](http://d36zk2xti64re0.cloudfront.net/stylegan2/networks/stylegan2-cat-config-f.pkl)
- StyleGAN2 implementation: https://github.com/NVlabs/stylegan2
- Licence: Nvidia Source Code License-NC
- [Source](https://github.com/NVlabs/stylegan2)


## church

![](images/church.jpg)
- Dataset: LSUN Church
- Resolution: 256x256
- Author: [NVIDIA]()
- [Download link](http://d36zk2xti64re0.cloudfront.net/stylegan2/networks/stylegan2-church-config-f.pkl)
- StyleGAN2 implementation: https://github.com/NVlabs/stylegan2
- Licence: Nvidia Source Code License-NC
- [Source](https://github.com/NVlabs/stylegan2)


## FFHQ (config-e)

![](images/FFHQ%20(config-e).jpg)
- Dataset: FFHQ
- Resolution: 1024x1024
- Author: [NVIDIA]()
- [Download link](http://d36zk2xti64re0.cloudfront.net/stylegan2/networks/stylegan2-ffhq-config-e.pkl)
- StyleGAN2 implementation: https://github.com/NVlabs/stylegan2
- Licence: Nvidia Source Code License-NC
- [Source](https://github.com/NVlabs/stylegan2)


## FFHQ (config-f)

![](images/FFHQ%20(config-f).jpg)
- Dataset: FFHQ
- Resolution: 1024x1024
- Author: [NVIDIA]()
- [Download link](http://d36zk2xti64re0.cloudfront.net/stylegan2/networks/stylegan2-ffhq-config-f.pkl)
- StyleGAN2 implementation: https://github.com/NVlabs/stylegan2
- Licence: Nvidia Source Code License-NC
- [Source](https://github.com/NVlabs/stylegan2)


## horse

![](images/horse.jpg)
- Dataset: LSUN Horse
- Resolution: 256x256
- Author: [NVIDIA]()
- [Download link](http://d36zk2xti64re0.cloudfront.net/stylegan2/networks/stylegan2-horse-config-f.pkl)
- StyleGAN2 implementation: https://github.com/NVlabs/stylegan2
- Licence: Nvidia Source Code License-NC
- [Source](https://github.com/NVlabs/stylegan2)


## Imagenet

![](images/Imagenet.jpg)
- Dataset: Image net
- Resolution: 512x512
- Author: [Shawn Presser]()
- [Download link](https://battle.shawwn.com/sdc/stylegan2-imagenet-512/model.ckpt-533504.pkl)
- StyleGAN2 implementation: Unknown- Notes: Trained using TPUs
- Licence: Unknown
- [Source](https://twitter.com/theshawwn/status/1244081581347598341)


## WikiArt

![](images/WikiArt.jpg)
- Dataset: WikiArt
- Resolution: Unknown
- Author: [Peter Baylies](https://twitter.com/pbaylies)
- [Download link](https://archive.org/download/wikiart-stylegan2-conditional-model/network-snapshot-012052.pkl)
- StyleGAN2 implementation: https://github.com/pbaylies/stylegan2- Notes: Conditional
- Licence: Unknown
- [Source]()


## Anime portraits

![](images/Anime%20portraits.jpg)
- Dataset: Danboru
- Resolution: 512x512
- Author: [Aaron Gokaslan](https://skylion007.github.io/)
- [Download link](https://mega.nz/#!PeIi2ayb!xoRtjTXyXuvgDxSsSMn-cOh-Zux9493zqdxwVMaAzp4)
- StyleGAN2 implementation: Unknown
- Licence: Unknown
- [Source](https://www.gwern.net/Faces#stylegan-2)


## microscope images

![](images/microscope%20images.jpg)
- Dataset: Unknown
- Resolution: 1024x1024
- Author: [Michael Friesen](https://twitter.com/MichaelFriese10)
- [Download link](https://mega.nz/#!PbgzWTZT!JbVpqgMU7AOg-sQUoG1BDepuwKtgAsLgjd4YwlTXlpc)
- StyleGAN2 implementation: Unknown
- Licence: Unknown
- [Source](https://twitter.com/MichaelFriese10/status/1230906267960401920?s=20)


## wildlife

![](images/wildlife.jpg)
- Dataset: Unknown
- Resolution: Unknown
- Author: [Michael Friesen](https://twitter.com/MichaelFriese10)
- [Download link](https://mega.nz/#!rewlECYI!YxVxdCKoeauEbiPKt92otVVHZBOiI-KkZMr0cvKHBdg)
- StyleGAN2 implementation: Unknown
- Licence: Unknown
- [Source](https://twitter.com/MichaelFriese10/status/1215364932088123392?s=20)


## modern art

![](images/modern%20art.jpg)
- Dataset: Unknown
- Resolution: Unknown
- Author: [Michael Friesen](https://twitter.com/MichaelFriese10)
- [Download link](https://mega.nz/#!TCgSVCTa!ZmcV381soxyqiQyHO4p60F5ogoHcaO1PqDF9ZuiHVQw)
- StyleGAN2 implementation: Unknown
- Licence: Unknown
- [Source](https://twitter.com/MichaelFriese10/status/1213697331427545088?s=20)



## Contributing

__TLDR: You can either edit the [models.csv](models.csv) file or fill out this [form](https://forms.gle/PE1iiTa5tNTdBFYN9).__

This readme is automatically generated using Jinja, please do not try and edit it directly. Information about the models is stored in `models.csv` please add your model to this file. Preview images are generated automatically and the process is used to test the link so please only edit the csv file.
121 changes: 121 additions & 0 deletions generate_images.py
@@ -0,0 +1,121 @@
# iterate over lines in csv
# download pickle
# setup docker image
# run container to generate 9 images
# Compile images into montage

import csv
import os
filename = 'models.csv'
import traceback
import requests
import gdown
from mega import Mega
from pathlib import Path
import lzma
import subprocess
from PIL import Image
import shutil

images_dir = Path('images')
models_dir = Path('models')

for directory in (images_dir, models_dir):
directory.mkdir(exist_ok=True)

def run_network(pkl_path, output_dir, clean_up=False):
working_dir = '/working'
image_name = 'awesome-stylegan2'
seeds = '0-8'
if clean_up:
cmd = ['rm', '-rf', working_dir + '/' + str(output_dir),]
else:
cmd = ['python', 'run_generator.py',
'generate-images',
'--network', working_dir + '/' + str(pkl_path),
'--seeds', seeds,
'--result-dir', working_dir + '/' + str(output_dir),
]

base =['docker',
'run',
'-t',
'--rm',
'--net', 'host',
'--gpus', 'all',
'-v', '/home/justin/code/awesome-pretrained-stylegan2:/working',
image_name,
]
base.extend(cmd)
subprocess.run(base)


def download(url, dest_path):
print(f'Downloading {dest_path} model')

if dest_path.exists():
print(f'{dest_path} already exists, skipping download')
pkl_file = list(dest_path.glob('*'))[0]
return pkl_file

dest_path.mkdir()
if 'drive.google.com' in url:
downloaded_file = gdown.download(url, output=dest_path)
elif 'mega.nz' in url:
mega = Mega()
m = mega.login()
downloaded_file = m.download_url(url, dest_path=str(dest_path))
else:
r = requests.get(url)
downloaded_file = 'downloaded.pkl'
with open(downloaded_file, 'wb') as f:
f.write(r.content)

downloaded_file = Path(downloaded_file)

if downloaded_file.suffix == ".xz":
print(f'Downloaded file {downloaded_file} is .xz')
pkl_file = dest_path/downloaded_file.stem
with lzma.open(downloaded_file, 'rb') as in_file:
with open(pkl_file, 'wb') as out:
out.write(in_file.read())
else:
pkl_file = dest_path/downloaded_file.name
downloaded_file.replace(pkl_file)

return pkl_file

def draw_figure(results_dir, filename, rows=3, out_size=256):

canvas = Image.new('RGB', (out_size * rows, out_size*rows), 'white')
images = Path(results_dir).rglob('*.png')
for col in range(rows):
for row in range(rows):
image = Image.open(next(images))
image = image.resize((out_size, out_size), Image.ANTIALIAS)
canvas.paste(image, (out_size*col, out_size*row))

canvas.save(filename)

if __name__ == "__main__":

temp_outputs = Path('temp_outputs')

with open(filename) as csvfile:
reader = csv.DictReader(csvfile)
for model in reader:
image_name = images_dir/(model["name"] + '.jpg')
model_location = models_dir/model["name"]

if os.path.exists(image_name):
print(f'{image_name} already exists.')
continue

pickle_location = download(model['download_url'], model_location)

#temp_outputs.mkdir()
run_network(pickle_location, temp_outputs)
draw_figure(temp_outputs, image_name)
run_network(pickle_location, temp_outputs, clean_up=True)
#shutil.rmtree(temp_outputs)

Binary file added images/Anime portraits.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/FFHQ (config-e).jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/FFHQ (config-f).jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Imagenet.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/WikiArt.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/car (config-e).jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/car (config-f).jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/cat.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/church.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/horse.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/microscope images.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/modern art.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/thumbs/Anime portraits.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/thumbs/FFHQ (config-e).jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/thumbs/FFHQ (config-f).jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/thumbs/Imagenet.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/thumbs/WikiArt.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/thumbs/car (config-e).jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/thumbs/car (config-f).jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/thumbs/cat.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/thumbs/church.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/thumbs/horse.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/thumbs/microscope images.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/thumbs/modern art.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/thumbs/wildlife.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/wildlife.jpg
30 changes: 30 additions & 0 deletions make_readme.py
@@ -0,0 +1,30 @@
import csv
import jinja2
from PIL import Image
import os

def make_thumbnail(filename):
image_name = f"images/{filename}.jpg"
if not os.path.exists(image_name):
return
im = Image.open(image_name)
thumb = im.crop((0,0,256,256))
thumb = thumb.resize((128,128))
thumb.save(f"images/thumbs/{filename}.jpg")

model_file = "models.csv"
output_file = "README.md"
env = jinja2.Environment(loader=jinja2.FileSystemLoader('.'))
template = env.get_template('template.md')

with open(model_file) as csvfile:
reader = csv.DictReader(csvfile)
models = list(reader)

for model in models:
make_thumbnail(model["name"])

content = template.render(models = models)

with open(output_file, "w") as readme:
readme.write(content)
14 changes: 14 additions & 0 deletions models.csv
@@ -0,0 +1,14 @@
name,download_url,author,author_url,dataset,source_url,resolution,config,license,implementation,Notes
car (config-e),http://d36zk2xti64re0.cloudfront.net/stylegan2/networks/stylegan2-car-config-e.pkl,NVIDIA,,LSUN Cat,https://github.com/NVlabs/stylegan2,512x384,e,Nvidia Source Code License-NCNvidia Source Code License-NC,https://github.com/NVlabs/stylegan2,
car (config-f),http://d36zk2xti64re0.cloudfront.net/stylegan2/networks/stylegan2-car-config-f.pkl,NVIDIA,,LSUN Cat,https://github.com/NVlabs/stylegan2,512x384,f,Nvidia Source Code License-NC,https://github.com/NVlabs/stylegan2,
cat,http://d36zk2xti64re0.cloudfront.net/stylegan2/networks/stylegan2-cat-config-f.pkl,NVIDIA,,LSUN Cat,https://github.com/NVlabs/stylegan2,256x256,f,Nvidia Source Code License-NC,https://github.com/NVlabs/stylegan2,
church,http://d36zk2xti64re0.cloudfront.net/stylegan2/networks/stylegan2-church-config-f.pkl,NVIDIA,,LSUN Church,https://github.com/NVlabs/stylegan2,256x256,f,Nvidia Source Code License-NC,https://github.com/NVlabs/stylegan2,
FFHQ (config-e),http://d36zk2xti64re0.cloudfront.net/stylegan2/networks/stylegan2-ffhq-config-e.pkl,NVIDIA,,FFHQ,https://github.com/NVlabs/stylegan2,1024x1024,e,Nvidia Source Code License-NC,https://github.com/NVlabs/stylegan2,
FFHQ (config-f),http://d36zk2xti64re0.cloudfront.net/stylegan2/networks/stylegan2-ffhq-config-f.pkl,NVIDIA,,FFHQ,https://github.com/NVlabs/stylegan2,1024x1024,f,Nvidia Source Code License-NC,https://github.com/NVlabs/stylegan2,
horse,http://d36zk2xti64re0.cloudfront.net/stylegan2/networks/stylegan2-horse-config-f.pkl,NVIDIA,,LSUN Horse,https://github.com/NVlabs/stylegan2,256x256,f,Nvidia Source Code License-NC,https://github.com/NVlabs/stylegan2,
Imagenet,https://battle.shawwn.com/sdc/stylegan2-imagenet-512/model.ckpt-533504.pkl,Shawn Presser,,Image net,https://twitter.com/theshawwn/status/1244081581347598341,512x512,Unknown,Unknown,Unknown,Trained using TPUs
WikiArt,https://archive.org/download/wikiart-stylegan2-conditional-model/network-snapshot-012052.pkl,Peter Baylies,https://twitter.com/pbaylies,WikiArt,,Unknown,Unknown,Unknown,https://github.com/pbaylies/stylegan2,Conditional
Anime portraits,https://mega.nz/#!PeIi2ayb!xoRtjTXyXuvgDxSsSMn-cOh-Zux9493zqdxwVMaAzp4,Aaron Gokaslan,https://skylion007.github.io/,Danboru,https://www.gwern.net/Faces#stylegan-2,512x512,f,Unknown,Unknown,
microscope images,https://mega.nz/#!PbgzWTZT!JbVpqgMU7AOg-sQUoG1BDepuwKtgAsLgjd4YwlTXlpc,Michael Friesen,https://twitter.com/MichaelFriese10,Unknown,https://twitter.com/MichaelFriese10/status/1230906267960401920?s=20,1024x1024,Unknown,Unknown,Unknown,
wildlife,https://mega.nz/#!rewlECYI!YxVxdCKoeauEbiPKt92otVVHZBOiI-KkZMr0cvKHBdg,Michael Friesen,https://twitter.com/MichaelFriese10,Unknown,https://twitter.com/MichaelFriese10/status/1215364932088123392?s=20,Unknown,Unknown,Unknown,Unknown,
modern art,https://mega.nz/#!TCgSVCTa!ZmcV381soxyqiQyHO4p60F5ogoHcaO1PqDF9ZuiHVQw,Michael Friesen,https://twitter.com/MichaelFriese10,Unknown,https://twitter.com/MichaelFriese10/status/1213697331427545088?s=20,Unknown,Unknown,Unknown,Unknown,

0 comments on commit 95d62d3

Please sign in to comment.