DeepLearning

Neural Style Transfer

MathematiciantoDatascientist 2021. 12. 29. 16:54

What is Neural Style Transfer ?

단순하게, Content ( Input Image ) + Style ( 사전학습된 model 의 feature map 특성 ) -> Generated Image

입력값으로 들어갈 Content Image 에 사전학습된 다른 이미지의 model 이 파악한 feature map 특성을 담아 새로운 이미지를 만들어내는 과정.

 

What are Deep ConvNets Learning ? 

 

위의 이미지와 같이 layer 가 깊어질 수록 조금 더 이미지의 디테일한 요소를 감지하고 있는 것을 볼 수 있다.

 

Cost function

Content (C) + Style (S) -> Generated Image (G)

 

J(G) = alpha * J_content (C, G) + beta * J_style(S, G)

 

Implement J(G) need to find the generated image G

1. Initiate G randomly ( same dimension Content image )

2. Use Gradient Descent to minimize J(G) -> G := G - d/dG * J(G)

 

Content cost function

- Say you use hidden layer l to compute content cost.

- Use pre-trained ConvNet (E.g. VGG net)

- Let activation of l -> a[l](C) and a[l](G) 

- If a[l](C) and a[l](G) are similar, both images have similar content

앞선 포스팅의 face recognition 의 similarity function 과 유사하다.

Style cost function

- Using layer l's activation to measure "Style"

- Define style as *correlation between activations across channels

* correlation : Channel 간 corr 은 각 스타일이 동시에 얼마나 자주 일어나는지에 대한 것이다.

Corr( n_channel, m_channel ) 값이 크면 n th channel and m th channel 의 activate 된 특징이 동시에 자주 발생한다.

 

Style matrix (Gram Matrix)

동일 layer 에서 각 channel 간 유사도를 기반으로 연산한 Gram matrix

 

 

# 1D and 3D generalizations of models

 

[코드 구현은 keras 공식 홈페이지에 간결하게 구현되어 있다.]

neural_style_transfer.py
0.01MB