본문 바로가기

Paper Review/Generative Model

[Paper Review] StyleSpace Analysis : Disentangled Controls for StyleGAN Image Generation (CVPR'21 Oral)

TL;DR: StyleSpace is more appropriate for manipulation, beacuse of disentanglement and completeness.

본 논문에서는 StyleGAN2의 Style Space에 대해 분석하며 기존의 Z, W, W+ space보다 더 disentangle 한 space임을 보이고, 따라서 해당 space의 channel을 manipulation 하는 것이 disentangled image manipulation에 적합하다고 주장합니다. 이러한 disentanglement와 completeness를 가진 style space상의 style vector의 특정 channel이 특정 attribute에 대응되기에 특정 attribute에 대응되는 style channel을 찾을 수 있고, 해당 channel에서 manipulation 함으로써 특정 attribute만 변경할 수 있습니다. 저자들은 locally active 한 정보와 specific target category 정보에 해당하는 style channel을 detection 하는 방법을 제시하고 이렇게 찾아진 채널에 변화를 가함으로써 특정 특성만 변화시키는 image manipulation이 가능하도록 합니다.

1. Disentanglement of Style Space

1.1. Style Space란?

Style Space란, StyleGAN에서 mapping network를 거쳐 나온 intermediate latent space W를 learned affine trasnformation을 거쳐서 나온 channel-wise style vector들의 space를 의미합니다.  StyleGAN2에서 이러한 style vector의 하나의 채널을 하나의 style parameter로 생각하고 하나의 style parameter는 feature map의 variance를 컨트롤합니다. 즉, 특정 attribute 혹은 style에 해당하는 parameter라는 것입니다. 다음과 같이 StyleGAN2에서 style vector가 generator의 각 modulation과정과 trgb block에서 사용되는 것을 확인할 수 있습니다.

이때 w space를 사용한다면  w1과 w2 혹은 s1과 s2는 동일하지만, 만약 w+ space를 사용한다면, w1과 w2는 다릅니다. S space와 W space W+ space를 비교하자면, Stylegan이 18 layer를 사용하고 latent vector w의 length가 512라는 가정하에 14 레이어 이후부터는 반씩 latent vector의 length를 줄여나가, 만약 w space를 사용한다면 해당 모델의 total latent dimension은 512이고 w+ space를 사용한다면 18 layer이니 18x512 = 9216입니다. 마지막으로 S space를 사용한다면 앞서 언급한 dimension decreasing때문에 modulation layer에 해당하는 6048 dimension, trgb block에 해당하는 3040 dimension으로 총 9088 dimension을 가지게 됩니다.

저자들은 W,W+,S space 중에 어떤 것이 가장 disentangled representation을 가진 space인지 확인하기 위해서 DCI라는 Metric을 사용합니다. 이렇게 DCI metric을 통해 각 Space를 비교해보면 Style Space가 얼마나 disentangled 하고 completeness 한 좋은 space인지를 확인할 수 있습니다.

1.2. DCI ( Disentanglement, Completeness, Informativeness )

DCI는 Disentanglement, Completeness, Informativeness를 측정하는 메트릭입니다. DCI를 통해 measure하기 위해서는 사전학습된 attribute에 대한 binary classifier들을 준비하고 각각의 latnet vector에 대해서 w, w+, s vector를 얻고, 각 방법을 통해 생성된 fake image를 classifier를 통과해서 나온 logit값들로 이루어진 attribute vector를 얻어, latent vector(w, w+, s)와 attribute vector의 pair로 latent vector가 주어졌을 때 attribute vector를 regression 할 수 있는 regressor를 학습시킵니다. regressor를 활용하면 특정 latent vector를 변경해가면서 attribute vector의 변화를 확인할 수 있고 이를 통해 disentanglement, completeness, informativeness를 확인할 수 있게 됩니다.
( Cian Eastwood and Christopher KI Williams. A framework for the quantitative evaluation of disentangled representations, 2018. In Proc. ICLR, volume 5, page 8, 2018.)

1.3. Disentanglement, Completeness

좀 더 구체적으로 DCI에서 정의하는 Disentanglement와 Completeness에 대해서 알아보겠습니다. Disentanglement는 latent vector의 특정 dimension이 대게 하나의 attribute를 capture하고 있을 때를 의미합니다. 즉, 하단의 이미지와 같이 특정 latent dimension에서 변경이 다양한 factor에 영향을 주는 것은 entangled 하다는 것입니다. Completeness의 경우 각각의 attribute가 하나의 latent dimension에 의해 control 되는 정도를 measure 하는 것으로 특정 attribute 혹은 factor of variation이 여러 개의 latent dimension에 의해 contorl 될 경우 completeness가 낮다고 합니다. 

2. Detecting Style Channels

이렇게 DCI측면에서 좋은 Style Space를 활용해 manipulation을 하기 위해서 저자들은 특정 visual attribute를 컨트롤하는 특정 style channel을 찾아 해당 style channel에서 변화를 통해 원하는 attribute만 manipulation된 image를 얻고자 합니다. 그렇다면 어떻게 특정 attribute에 해당하는 style channel을 찾을 수 있을까요?

사람들이 원하는 manipulation에 적합한 attribute는 annoation을 통한 방법과 semantic region을 통한 방법으로 주어질 수 있습니다. 즉, '립스틱'이라는 annotation을 통해 정보를 주거나, '머리'에 해당하는 semantic mask와 같은 region에 대한 정보를 줌으로써 manipulation 하고자 합니다. 저자들은 이러한 특정 attribute에 해당하는 manipulation을 위해 두 가지 방법으로 해당 attribute에 대응되는 style channel을 detection 합니다.

2.1. Detecting Locally-active style channel

앞서 살펴봤듯 Style Space는 disentangled 합니다. 따라서 각각의 latent dimension이 오직 하나의 attribute에만 영향을 줄 수 있습니다. 이러한 가설을 테스트하기 위해 저자들은 각각의 style channel에 대해서 gradient map을 추출합니다. 이렇게 추출된 gradient map들은 특정 semantic area와 큰 overlapping이 있음을 확인할 수 있습니다. 이를 통해 특정 style channel이 특정 localize semantic attribute에 대응된다는 것을 확인할 수 있게 됩니다. 이에 따라 하단의 이미지와 같이 mouth, hair와 같은 local region attribute에 해당하는 style channel을 찾을 수 있게 되는 것입니다.

이렇게 locally active 함을 활용해 localized attribute에 해당하는 style channel을 detection 할 수 있습니다. 이는 다른 attribute들에 영향을 주지 않으면서 특정 localized attribute만 manipulation을 할 수 있도록 해 줍니다. 따라서 배게의 존재혹은 모발의 풍성함같은 특징을 다른 attribute에 영향을 주지 않으면서 locally active한 부분에 대해서만 manipulation을 가능하게 해줍니다.

위 과정을 더 구체적으로 살펴보면 특정 style channel에 대한 gradient map이 많은 이미지들에 대해서 semantic region과 충분히 큰 overlap을 가지고 있을 경우에 이 style channel을 특정 attribute에 영향을 주는 channel로 식별하게 됩니다. 즉, 다양한 이미지들에 대해서 segmentation model을 통해 얻은 semantic mask와 특정 style channel에 대해서 얻은 gradient map 간의 overlap을 구하고 이를 모든 category들에 대해서 수행해서 가장 큰 overlap값을 가지는 category를 해당 style channel의 attribute가 대다수의 이미지들에 대해서 동일할 때 해당 attribute에 대응되는 style channel로 판단하게 됩니다.

t라는 caategory specific treshold를 통해 gradient map을 얻게 됩니다.
computational cost를 줄이기 위해 gradient map과 semantic mask의 경우 low resolution으로 사용하게 됩니다.

이렇게 detecting 한 channel의 값을 modifyig 함으로써 얻은 localized manipulation의 결과들을 확인해보면 다음과 같습니다. 각각의 channel이 오직 sinlge attribute를 control 하고 있습니다. 마지막 행을 보면 'ear region'에 해당하는 4개의 channel이 각각 귀의 존재나 귀의 모양등을 control하고 있음을 확인할 수 있습니다.

대부분의 deteced channel들은 middle layers에 많이 퍼져다는 점을 저자들은 인사이트로 제시합니다. ( 주로 6-12 근방의 채널들이 많이 detection된 것을 확인할 수 있습니다. )

2.2. Detecting Attribute-specific style channel

또한 style space는 매우 completeness 하기에 특정 attribute control을 위해서 전체 latent vecotr를 바꿀 필요 없이 하나 혹은 적은 수의 latent dimension만 변화시켜주면 됩니다. 이러한 가설을 확인하기 위해서 저자들은 특정 attribute에 대해서 동일한 특징을 가지고 있는 적은 양의 examplar 혹은 positive image들과 많은 양의 population images를 활용합니다. 하단의 이미지에서 attribute는 '모자의 유무'가 되겠습니다.

각 이미지 set들을 latent code로 바꿔주고, 해당 style vector들의 각 채널별로 비교를 해서, examplar set의 특정 채널과 population images의 특정 채널 사이의 차이가 가장 뚜렷한 채널을 attribute-specific channel로 판단하게 됩니다. 즉, examplar set의 분포가 가지는 특정 attribute에 대한 특징이 일반적인 대개의 이미지들의 분포와 구별될수록 해당 채널이 해당 attrribute를 의미한다고 할 수 있는 것입니다.

이러한 차이를 확인하기 위해 저자들은 signal2 noise ratio을 사용합니다. 우선, population mean, std를 활용해 특정style vector에 대해 population으로부터의 normalized difference를 정의하고, examplar set의 style vector들에 대해서 normalized differecne를 구한 뒤에 해당 style vector의 각 채널에 대해서 population에서 얼마나 벗어나있는지를 판단하기 위해서 normalized differecne들의 mean과 std를 구하게 되면 해당 mean은 평균적으로 population으로부터 examplar set image들이 벗어난 정도를 의미하고, std는 평균적으로 얼마나 골고루 퍼져있는지를 의미하게 됩니다. examplar set은 특정 attribute에 해당하는 이미지들을 모은 것이므로 mean값은 높고, std값은 낮게 됩니다. 즉, signal2noise ratio인 세타값이 클수록 해당 style channel이 examplar set에 해다 하는 attribute라고 판단하는 것입니다.
( 논문 Section 5에 자세히 설명되어 있음 )

이렇게 detecting 한 channel들은 다음과 같고, 저자들은 일부 attribute들은 completeness 하지만, 일부 attribute들은 오로지 하나의 channel에 의해 컨트롤되지 않고 있다는 것도 확인합니다. ( 26개 중 16개는 completeness ) 저자들이 제시한 이러한 detecting 방법은 positive example iamges가 매우 적더라도 가능하다는 점에서 유용하며 실험 결과 examplar set의 크기가 클수록 detection accuracy가 좋아졌다고 합니다. 또한, 앞서 확인했던 locally active channels를 먼저 찾아서 해당 channels 내에서 찾도록 제한할수록 accuracy가 좋아진다고 합니다. 즉, Attribute를 더 구체적으로 구분해 특정 Regioanl Attribute를 찾고 해당 공간 내에서 specific attribute를 찾을 시에 더 정확한 attribute에 대한 style channel detection이 가능해진다는 것입니다.

3. Disentangled attribute manipulation

이렇게 disentangled와 completeness를 가지고 있는 style space를 활용하기에 특정 attribute에 해당되는 style channel을 찾을 수 있었습니다. 그럼 특정 attribute에 해당하는 channel의 value를 변화시킴으로써 해당 attribute만 변화된 image를 얻을 수 있게 됩니다. 다음과 같이 기존의 SOTA disentangled manipulation방법들과 비교해봤을 때 훨씬 나은 결과를 보여주는 것을 확인할 수 있습니다. 이때 저자들은 특정 attribute에 해당되는 pretrained 된 classifier의 output logit값만큼 manipulation direction으로 변화시켜주게 됩니다. ( output logit = step size )

4. manipulation of Real Images

이렇게 Image Manipulation의 궁극적인 목표는 real image를 manipulation 하는 것입니다. 따라서, Real Image를 받아 우선 우리가 원하는 Style Space로 inversion을 시켜 latent code를 뽑아준 후에 앞서 논문에서 주장하던 방법들에 기반해 특정 attribute를 변화시켜주는 mainpulation 과정을 통해 Real Image Manipulation을 하게 됩니다. 

저자들은 당시 기저에 깔려있던 latent optimization 기반의 inversion을 먼저 시도합니다. 이때 Style Space로 Inversion 하는 것의 장점을 강조하는데, Style Space로 Inversion 할 경우 input image에 대한 reconstruction을 잘한다. 즉, S, W+, W 순서대로 reconstruction 및 gan inversion에 훨씬 좋은 latent space라고 주장합니다.

하지만, style space가 가지는 flexibility는 latent code가 생성된 이미지 manifold상에 놓여있지 않도록 만들게 됩니다. 이에 따라 real image manipulation을 시도할 때 오히려 unnatural artifact가 발생하게 됩니다. 저자들은 manipulation naturalness는 W, W+, S 순으로 좋다고 주장합니다.

이러한 인사이트들에 기반해 저자들은 reconstruction accuracy와 artifact-free manipulation 간의 적절한 타협을 위해서 S space에 대해서 학습한 encoder 기반의 inversion method와 latent optimization을 모두 활용하는 하이브리드 한 방식을 사용했습니다. encoder를 통해 적절한 latent code optimization을 위한 starting point를 얻게 되고, 이를 적은 iteration의 latent optimization을 적용하는 방식은, encoder기반의 방식에서 생기는 compression artifact를 latent optimization과정을 통해 제거해줌으로써 artifact-free manipulation을 가능하게 하면서도 reconstruction accuracy가 높은 inversion까지 가능하도록 합니다. 저자들은 encoder가 real image를 generated image manifold위로 임베딩하는 것을 학습하고, few optimization을 통해서 embedding을 fine tunning 시키기 때문에 가능한 것이라고 추측하고 있습니다. ( 이전 방식은 manifold위에 있지도 않은 상태에서 latent optimization을 했기에 artifact가 강하게 생겼던 것으로 생각해볼 수 있을 것 같습니다. )