Skip to content

Commit

Permalink
facebookresearch_pytorch-gan-zoo-pgan ๋ฒˆ์—ญ (PyTorchKorea#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
KyubumShin committed Sep 3, 2022
1 parent 7fdca78 commit ecfa8c6
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions facebookresearch_pytorch-gan-zoo_pgan.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,48 +22,48 @@ demo-model-link: https://huggingface.co/spaces/pytorch/PGAN
import torch
use_gpu = True if torch.cuda.is_available() else False

# trained on high-quality celebrity faces "celebA" dataset
# this model outputs 512 x 512 pixel images
# ์ด ๋ชจ๋ธ์€ ์œ ๋ช…์ธ๋“ค์˜ ๊ณ ํ•ด์ƒ๋„ ์–ผ๊ตด ๋ฐ์ดํ„ฐ์…‹ "celebA"๋กœ ํ•™์Šต๋˜์—ˆ์Šต๋‹ˆ๋‹ค
# ์•„๋ž˜ ๋ชจ๋ธ์˜ ์ถœ๋ ฅ์€ 512 x 512 ํ”ฝ์…€์˜ ์ด๋ฏธ์ง€์ž…๋‹ˆ๋‹ค
model = torch.hub.load('facebookresearch/pytorch_GAN_zoo:hub',
'PGAN', model_name='celebAHQ-512',
pretrained=True, useGPU=use_gpu)
# this model outputs 256 x 256 pixel images
# ์•„๋ž˜ ๋ชจ๋ธ์˜ ์ถœ๋ ฅ์€ 256 x 256 ํ”ฝ์…€์˜ ์ด๋ฏธ์ง€์ž…๋‹ˆ๋‹ค
# model = torch.hub.load('facebookresearch/pytorch_GAN_zoo:hub',
# 'PGAN', model_name='celebAHQ-256',
# pretrained=True, useGPU=use_gpu)
```

The input to the model is a noise vector of shape `(N, 512)` where `N` is the number of images to be generated.
It can be constructed using the function `.buildNoiseData`.
The model has a `.test` function that takes in the noise vector and generates images.
๋ชจ๋ธ์˜ ์ž…๋ ฅ๊ฐ’์œผ๋กœ๋Š” `(N, 512)`ํฌ๊ธฐ์˜ ๋…ธ์ด์ฆˆ(noise) ๋ฒกํ„ฐ์ž…๋‹ˆ๋‹ค. `N`์€ ์ƒ์„ฑํ•˜๊ณ ์ž ํ•˜๋Š” ์ด๋ฏธ์ง€์˜ ๊ฐœ์ˆ˜๋ฅผ ๋œปํ•ฉ๋‹ˆ๋‹ค.
์ด ๋…ธ์ด์ฆˆ ๋ฒกํ„ฐ๋“ค์€ ํ•จ์ˆ˜ `.buildNoiseData`๋ฅผ ํ†ตํ•˜์—ฌ ์ƒ์„ฑ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์ด ๋ชจ๋ธ์€ ๋…ธ์ด์ฆˆ ๋ฒกํ„ฐ๋ฅผ ๋ฐ›์•„์„œ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•˜๋Š” `.test` ํ•จ์ˆ˜๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

```python
num_images = 4
noise, _ = model.buildNoiseData(num_images)
with torch.no_grad():
generated_images = model.test(noise)

# let's plot these images using torchvision and matplotlib
# torchvision๊ณผ matplotlib๋ฅผ ์ด์šฉํ•˜์—ฌ ์ƒ์„ฑํ•œ ์ด๋ฏธ์ง€๋“ค์„ ์‹œ๊ฐํ™” ํ•ด๋ด…์‹œ๋‹ค.
import matplotlib.pyplot as plt
import torchvision
grid = torchvision.utils.make_grid(generated_images.clamp(min=-1, max=1), scale_each=True, normalize=True)
plt.imshow(grid.permute(1, 2, 0).cpu().numpy())
# plt.show()
```

You should see an image similar to the one on the left.
์™ผ์ชฝ๊ณผ ๋น„์Šทํ•œ ์ด๋ฏธ์ง€๋ฅผ ๊ฒฐ๊ณผ๋ฌผ๋กœ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

If you want to train your own Progressive GAN and other GANs from scratch, have a look at [PyTorch GAN Zoo](https://github.com/facebookresearch/pytorch_GAN_zoo).
๋งŒ์•ฝ ์ž์‹ ๋งŒ์˜ Progressive GAN ์ด๋‚˜ ๋‹ค๋ฅธ GAN ๋ชจ๋ธ๋“ค์„ ์ง์ ‘ ํ•™์Šตํ•ด ๋ณด๊ณ  ์‹ถ๋‹ค๋ฉด [PyTorch GAN Zoo](https://github.com/facebookresearch/pytorch_GAN_zoo)๋ฅผ ์ฐธ๊ณ ํ•ด ๋ณด์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

### Model Description
### ๋ชจ๋ธ ์„ค๋ช…

In computer vision, generative models are networks trained to create images from a given input. In our case, we consider a specific kind of generative networks: GANs (Generative Adversarial Networks) which learn to map a random vector with a realistic image generation.
์ปดํ“จํ„ฐ ๋น„์ „(Computer Vision)๋ถ„์•ผ์—์„œ ์ƒ์„ฑ ๋ชจ๋ธ์€ ์ฃผ์–ด์ง„ ์ž…๋ ฅ๊ฐ’์œผ๋กœ ๋ถ€ํ„ฐ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•ด ๋‚ด๋„๋ก ํ•™์Šต๋œ ์‹ ๊ฒฝ๋ง์ž…๋‹ˆ๋‹ค. ํ˜„์žฌ ๋‹ค๋ฃจ๋Š” ๋ชจ๋ธ์€ ์ƒ์„ฑ ๋ชจ๋ธ์˜ ํŠน์ •ํ•œ ์ข…๋ฅ˜๋กœ์„œ ๋ฌด์ž‘์œ„์˜ ๋ฒกํ„ฐ์—์„œ ์‚ฌ์‹ค์ ์ธ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ฒ•์„ ํ•™์Šตํ•˜๋Š” GAN ๋ชจ๋ธ์ž…๋‹ˆ๋‹ค.

Progressive Growing of GANs is a method developed by Karras et. al. [1] in 2017 allowing generation of high resolution images. To do so, the generative network is trained slice by slice. At first the model is trained to build very low resolution images, once it converges, new layers are added and the output resolution doubles. The process continues until the desired resolution is reached.
GAN์˜ ์ ์ง„์ ์ธ ์ฆ๊ฐ€(Progressive Growing of GANs)๋Š” Karras์™€ ๊ทธ ์™ธ[1]๊ฐ€ 2017๋…„์— ๋ฐœํ‘œํ•œ ๊ณ ํ•ด์ƒ๋„์˜ ์ด๋ฏธ์ง€ ์ƒ์„ฑ์„ ์œ„ํ•œ ๋ฐฉ๋ฒ•๋ก  ์ž…๋‹ˆ๋‹ค. ์ด๋ฅผ ์œ„ํ•˜์—ฌ ์ƒ์„ฑ ๋ชจ๋ธ์€ ์—ฌ๋Ÿฌ ๋‹จ๊ณ„๋กœ ๋‚˜๋‰˜์–ด์„œ ํ•™์Šต๋ฉ๋‹ˆ๋‹ค. ์ œ์ผ ๋จผ์ € ๋ชจ๋ธ์€ ์•„์ฃผ ๋‚ฎ์€ ํ•ด์ƒ๋„์˜ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•˜๋„๋ก ํ•™์Šต์ด ๋˜๊ณ , ์–ด๋Š์ •๋„ ๋ชจ๋ธ์ด ์ˆ˜๋ ดํ•˜๋ฉด ์ƒˆ๋กœ์šด ๊ณ„์ธต์ด ๋ชจ๋ธ์— ๋”ํ•ด์ง€๊ณ  ์ถœ๋ ฅ ํ•ด์ƒ๋„๋Š” 2๋ฐฐ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค. ์ด ๊ณผ์ •์„ ์›ํ•˜๋Š” ํ•ด์ƒ๋„์— ๋„๋‹ฌ ํ•  ๋•Œ ๊นŒ์ง€ ๋ฐ˜๋ณตํ•ฉ๋‹ˆ๋‹ค.

### Requirements
### ์š”๊ตฌ์‚ฌํ•ญ

- Currently only supports Python 3
- ํ˜„์žฌ๋Š” Python3 ์—์„œ๋งŒ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค

### References

Expand Down

0 comments on commit ecfa8c6

Please sign in to comment.