Skip to content

Latest commit

ย 

History

History
70 lines (55 loc) ยท 3.38 KB

facebookresearch_pytorch-gan-zoo_pgan.md

File metadata and controls

70 lines (55 loc) ยท 3.38 KB
layout background-class body-class title summary category image author tags github-link github-id featured_image_1 featured_image_2 accelerator order demo-model-link
hub_detail
hub-background
hub
Progressive Growing of GANs (PGAN)
High-quality image generation of fashion, celebrity faces
researchers
pganlogo.png
FAIR HDGAN
vision
generative
facebookresearch/pytorch_GAN_zoo
pgan_mix.jpg
pgan_celebaHQ.jpg
cuda-optional
10
import torch
use_gpu = True if torch.cuda.is_available() else False

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

๋ชจ๋ธ์˜ ์ž…๋ ฅ์€ (N, 512) ํฌ๊ธฐ์˜ ๋…ธ์ด์ฆˆ(noise) ๋ฒกํ„ฐ์ž…๋‹ˆ๋‹ค. N์€ ์ƒ์„ฑํ•˜๊ณ ์ž ํ•˜๋Š” ์ด๋ฏธ์ง€์˜ ๊ฐœ์ˆ˜๋ฅผ ๋œปํ•ฉ๋‹ˆ๋‹ค. ์ด ๋…ธ์ด์ฆˆ ๋ฒกํ„ฐ๋“ค์€ ํ•จ์ˆ˜ .buildNoiseData๋ฅผ ํ†ตํ•˜์—ฌ ์ƒ์„ฑ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ๋ชจ๋ธ์€ ๋…ธ์ด์ฆˆ ๋ฒกํ„ฐ๋ฅผ ๋ฐ›์•„์„œ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•˜๋Š” .test ํ•จ์ˆ˜๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

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

# 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()

์™ผ์ชฝ๊ณผ ๋น„์Šทํ•œ ์ด๋ฏธ์ง€๋ฅผ ๊ฒฐ๊ณผ๋ฌผ๋กœ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋งŒ์•ฝ ์ž์‹ ๋งŒ์˜ Progressive GAN ์ด๋‚˜ ๋‹ค๋ฅธ GAN ๋ชจ๋ธ๋“ค์„ ์ง์ ‘ ํ•™์Šตํ•ด ๋ณด๊ณ  ์‹ถ๋‹ค๋ฉด PyTorch GAN Zoo๋ฅผ ์ฐธ๊ณ ํ•ด ๋ณด์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

๋ชจ๋ธ ์„ค๋ช…

์ปดํ“จํ„ฐ ๋น„์ „(Computer Vision)๋ถ„์•ผ์—์„œ ์ƒ์„ฑ ๋ชจ๋ธ์€ ์ฃผ์–ด์ง„ ์ž…๋ ฅ๊ฐ’์œผ๋กœ ๋ถ€ํ„ฐ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•ด ๋‚ด๋„๋ก ํ•™์Šต๋œ ์‹ ๊ฒฝ๋ง์ž…๋‹ˆ๋‹ค. ํ˜„์žฌ ๋‹ค๋ฃจ๋Š” ๋ชจ๋ธ์€ ์ƒ์„ฑ ๋ชจ๋ธ์˜ ํŠน์ •ํ•œ ์ข…๋ฅ˜๋กœ์„œ ๋ฌด์ž‘์œ„์˜ ๋ฒกํ„ฐ์—์„œ ์‚ฌ์‹ค์ ์ธ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ฒ•์„ ํ•™์Šตํ•˜๋Š” GAN ๋ชจ๋ธ์ž…๋‹ˆ๋‹ค.

GAN์˜ ์ ์ง„์ ์ธ ์ฆ๊ฐ€(Progressive Growing of GANs)๋Š” Karras์™€ ๊ทธ ์™ธ[1]๊ฐ€ 2017๋…„์— ๋ฐœํ‘œํ•œ ๊ณ ํ•ด์ƒ๋„์˜ ์ด๋ฏธ์ง€ ์ƒ์„ฑ์„ ์œ„ํ•œ ๋ฐฉ๋ฒ•๋ก  ์ž…๋‹ˆ๋‹ค. ์ด๋ฅผ ์œ„ํ•˜์—ฌ ์ƒ์„ฑ ๋ชจ๋ธ์€ ์—ฌ๋Ÿฌ ๋‹จ๊ณ„๋กœ ๋‚˜๋‰˜์–ด์„œ ํ•™์Šต๋ฉ๋‹ˆ๋‹ค. ์ œ์ผ ๋จผ์ € ๋ชจ๋ธ์€ ์•„์ฃผ ๋‚ฎ์€ ํ•ด์ƒ๋„์˜ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•˜๋„๋ก ํ•™์Šต์ด ๋˜๊ณ , ์–ด๋Š์ •๋„ ๋ชจ๋ธ์ด ์ˆ˜๋ ดํ•˜๋ฉด ์ƒˆ๋กœ์šด ๊ณ„์ธต์ด ๋ชจ๋ธ์— ๋”ํ•ด์ง€๊ณ  ์ถœ๋ ฅ ํ•ด์ƒ๋„๋Š” 2๋ฐฐ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค. ์ด ๊ณผ์ •์„ ์›ํ•˜๋Š” ํ•ด์ƒ๋„์— ๋„๋‹ฌ ํ•  ๋•Œ ๊นŒ์ง€ ๋ฐ˜๋ณตํ•ฉ๋‹ˆ๋‹ค.

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

  • ํ˜„์žฌ๋Š” Python3 ์—์„œ๋งŒ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.

์ฐธ๊ณ