2021.10.07 - [Hi/Artificial_Intelligence] - Neural Style Transfer
Neural Style Transfer
What is NST? Style transfer๋, ๋ ์์(content image & style image)์ด ์ฃผ์ด์ก์ ๋ ๊ทธ ์ด๋ฏธ์ง์ ์ฃผ๋ ํํ๋ content image์ ์ ์ฌํ๊ฒ ์ ์งํ๋ฉด์ ์คํ์ผ๋ง ์ฐ๋ฆฌ๊ฐ ์ํ๋ style image์ ์ ์ฌํ๊ฒ ๋ฐ๊พธ๋ ๊ฒ..
forbetterdays.tistory.com
๊ธฐ์กด์ NST ๋ชจ๋ธ ๊ณต๋ถ์์ ํ๋จ๊ณ ๋ ๊น๊ฒ ํ์ฌ ํ๋ก์ ํธ์ ์ฌ์ฉํ์์ต๋๋ค.
What is NST (Neural Style Transfer)?
- Style transfer๋, ๋ ์์(content image & style image)์ด ์ฃผ์ด์ก์ ๋, ๊ทธ ์ด๋ฏธ์ง์ ์ฃผ๋ ํํ๋ content image์ ์ ์ฌํ๊ฒ ์ ์งํ๋ฉด์ ์คํ์ผ๋ง ์ฌ์ฉ์๊ฐ ์ํ๋ style image์ ์ ์ฌํ๊ฒ ๋ฐ๊พธ๋ ๊ฒ์ ๋งํฉ๋๋ค.
- Style Transfer, image-to-image translation, ๋๋ texture transfer ๋ฑ์ผ๋ก ๋ถ๋ฆฌ๋ ์ด ๋ฌธ์ ๋ ํ ์ด๋ฏธ์ง P๋ฅผ ๋ค๋ฅธ ์ด๋ฏธ์ง A์ ์คํ์ผ์ ๊ฐ์ง๋ ์๋ก์ด ์ด๋ฏธ์ง X๋ฅผ ์์ฑํ๋ ๋ฐฉ์์.
NST์ ๋ฐฉ์
์ฌ๊ธฐ์ Pretraining๋ ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ๊ฐ๊ฐ์ Input ์ด๋ฏธ์ง์ ํน์ง๋งต์ ๋ฝ์ ์ด๋ฅผ ๊ธฐ๋กํ์ฌ ๋์ต๋๋ค.
๊ฐ๊ฐ์ ๋น์จ์ ๋ฐ๋ผ content์ style ์ด๋ฏธ์ง์ feature map์ ๋ฎ์๊ฐ๋๋ก output ์ด๋ฏธ์ง์ ํฝ์ ์ ์ต์ ํํ์ฌ ๋ง๋ค์ด์ง๊ฒ ๋ฉ๋๋ค.

1. ์๋ก์ด Style Image ์ ์ ๋ชจ๋ธ + ํํ ๊ฐ์ด ๋ง๋๋ Style Transfer ๋ชจ๋ธ

- ์ฌ๋ฌ ํ๊ฐ๋ค์ ์ํ ์ด๋ฏธ์ง ๋ฐ์ดํฐ๋ฅผ ๋ฐํ์ผ๋ก, NST ๋ชจ๋ธ์ ์ฌ์ฉํ์ฌ ๋๊ฐ์ง ์ด์์ ํ๊ฐ๋ค์ ํน์ง๊ณผ ์๊ฐ์ ์ด๋ฆฐ ์๋ก์ด ์ด๋ฏธ์ง๋ฅผ ์ ์ํ์๋ค.
- ์
๋ ฅ์ ๋ ์ด๋ฏธ์ง์ ํน์ง๊ณผ ์๊ฐ ๋ฑ ์ ์ ํ๊ฒ ๋ฐ์ฉ ์์ด์ผ ํด์ ์ฌ๋ฌ ์คํ์ ํตํด ๊ฐ์ค์น๋ฅผ ์ฐพ์ ์ ์ํ์๋ค.
- VGG19๋ชจ๋ธ์ ์ฌ์ฉํ์๊ณ ์คํ์ ํตํด Dimensions๊ฐ์ 512์ ๋๋ก ์ค์ ์ ํ๊ฒ ๋์์ ๋, ๊ฐ ๊ฐ์ ์ด๋ฏธ์ง์ ํน์ง์ด ์ ํฉ์ณ์ง๋ค๋ ๊ฒฐ๊ณผ๊ฐ ๋์๋ค.
- ๋ฐ๋ผ์ dimensions์ 512๋ก ์ค์ ํ๊ณ , Content์ Weight๋ฅผ 1e-4, Style์ Weight๋ฅผ 1e-2๋ฅผ ์ฃผ์๋ค. 100๋ฒ์ฉ 10๋ฒ์ ํ์ตํ์ฌ ๊ฒฐ๊ณผ๋ฌผ๋ค์ ์ ์ํ์๋ค.
2. ์ฌ์ฉ์ ์ ํ ์ด๋ฏธ์ง ๋ชจ๋ธ
- VGG19๋ชจ๋ธ์ ์ฌ์ฉํ์๊ณ , Content์ Weight๋ฅผ 2.5e-8๋ก, Style์ Weight๋ฅผ 1e-6์ผ๋ก ์ค์ ์ ํ์๋ค.
- ๊ฐ ๊ฐ์ ์ฌ๋ฌ ๋ฒ์ ์คํ์ ํตํด ์ป๊ฒ ๋ ์์ฐ์ค๋ฌ์ด ํฉ์ฑ์ ์ํ ๊ฐ์ค์น์ด๋ค.
- ์ต๋ํ Content์ ํํ๋ฅผ ์์ง ์๋๋ก, ํํ์ฒ๋ผ ๋ณด์ด์ง ์๋๋ก ๊ฐ๊ฐ์ ๊ฐ์ค์น๋ฅผ ์ค์ ํ์ฌ ์ฌ์ฉ์๊ฐ ์ ํํ Style Image์ ์๊ฐ์ Transfer ํ ์ ์๋๋ก ์ ์ํ์๋ค.
3. ๊ฐ์ฒด ๊ฒ์ถ์ ํตํด ํฉ์ฑ๋ ์ด๋ฏธ์ง์ ์์ฐ์ค๋ฌ์ด ํฉ์ฑ ๋ชจ๋ธ
- ์๋ฒ์ ํต์ ํ๋ ๋ชจ๋ฐ์ผ ์ดํ๋ฆฌ์ผ์ด์
์์๋ ๊ฐ์ฒด ๊ฒ์ถ๊ณผ Style Transfer์ ์ฌ์ฉํ์ฌ ์ฌ์ฉ์์๊ฒ ์ ๋ฌํ๊ธฐ์๋ ๋ง์ ์๊ฐ์ด ์์๋๋ค๋ ํ๋จ์, ๊ฐ์ฅ ๋น ๋ฅด๊ฒ ์คํ์ผ ์ ์ด๋ฅผ ์ํด Tensorflow_Hub์ ์ ์ฌ๋์ด ์๋ Magenta Model์ ์ฌ์ฉํ๊ธฐ๋ก ์ ํํ์๋ค.
- ์ด ๋ชจ๋ธ์์๋ ๋๊ฐ์ง Input ์ด๋ฏธ์ง๋ฅผ ๋ฐ์ผ๋ฉด, ์ ์ฒ๋ฆฌ๋ฅผ ํด์ฃผ์ด, ๋ชจ๋ธ์ ๋ง๋ Tensor ํ์์ผ๋ก ์ด๋ฏธ์ง๋ฅผ preprocessing ํ์๋ค.
- Content์ฌ์ง์ ๊ฐ์ฒด ๊ฒ์ถ์ ํตํด ๋ถ์ฌ์ง ํฉ์ฑ ์ด๋ฏธ์ง์ด๊ณ , Style ์ฌ์ง์ ํฉ์ฑ ์ด์ ์ ์ฌ์ง์ด ๋๋ค.