고도를 기다리며

[논문] T2M-GPT: Generating Human Motion from Textual Descriptions with Discrete Representations 본문

공부한것/대학원

[논문] T2M-GPT: Generating Human Motion from Textual Descriptions with Discrete Representations

MING.G 2023. 7. 10. 16:22
본 글은 T2M-GPT: Generating Human Motion from Textual Descriptions with Discrete Representations를 읽고 이해한 내용을 정리하기 위해 적은 글입니다. 
혹, 잘못된 부분이나 수정해야할 부분이 있다면 언제든 댓글로 남겨주세요.

github : https://github.com/Mael-zys/T2M-GPT

 

GitHub - Mael-zys/T2M-GPT: (CVPR 2023) Pytorch implementation of “T2M-GPT: Generating Human Motion from Textual Descriptions w

(CVPR 2023) Pytorch implementation of “T2M-GPT: Generating Human Motion from Textual Descriptions with Discrete Representations” - GitHub - Mael-zys/T2M-GPT: (CVPR 2023) Pytorch implementation of “...

github.com

project page : https://mael-zys.github.io/T2M-GPT/

 

T2M-GPT

Project page for T2M-GPT: Generating Human Motion from Textual Descriptions with Discrete Representations.

mael-zys.github.io

paper : https://arxiv.org/abs/2301.06052

 

T2M-GPT: Generating Human Motion from Textual Descriptions with Discrete Representations

In this work, we investigate a simple and must-known conditional generative framework based on Vector Quantised-Variational AutoEncoder (VQ-VAE) and Generative Pre-trained Transformer (GPT) for human motion generation from textural descriptions. We show th

arxiv.org


Abstract

본 논문에서는 Vector Quantised-Variational AutoEncoder와 GPT(Generative Pre-trained Transformer)를 이용한 text description으로부터 human motion을 생성하는 conditional generative framework를 제안한다. 

  1. CNN 기반의 simple한 VQ-VAE는 고품질의 discrete representation을 제공함
  2. 간단한 corruption 전략을 training 과정에 적용하여 training과 testing의 discrepancy를 완화한 T2M-GPT는 좋은 성능을 보임

 

Introduction

natural language가 조건으로 주어진 motion 생성은 motion과 text가 서로 다른 modality로부터 오기때문에 어려움이 있다. model은 language space부터 motion space까지 정확한 맵핑을 학습하도록 기대된다. 이 목적을 위해, 많은 연구들은 auto-encoder, VAEs를 이용하여 language와 motion에 대한 joint embedding을 학습하는 방법을 제안한다. MoionClip은 motion space를 CLIP space로 정렬한다. ACTOR와 TEMOS는 action-to-motion과 text-to-motion을 위해 transformer 기반의 VAE를 제안한다. 

 

이러한 연구들은 간단한 description에서 좋은 성능을 보이지만 textual description이 길어지고 복잡해지는 경우, 높은 품질의 motion을 생성하는데 한계를 보인다. CVPR 2022의 Generating diverse and natural 3d human motions from text와 TM2T의 경우 이러한 문제를 해결하기 위한 방법을 제안하고 있다. 하지만, 두 논문의 방법 모두 간단지 않고, text-to-moiton을 위해 3가지 단계를 포함한다. 그리고 때때로 motion 생성에 실패하기도 한다.

 

최근 diffuion 기반의 모델들이 image 생성분야에서 주목할만한 결과를 보이고, moiton 생성에서도 MDM, MotionDiffuse가 text-to-motion 생성을 주도하고 있다. 그러나 VQ-VAE와 같은 고전적인 방법과 비교했을 때, diffusion 기반의 접근이 괄목할만한 성능의 향상을 보이고 있지는 않다. 

 

본 연구에서, 저자들은 최근 생성을 위한 discrete representation의 발전에 영감을 받아 text-to-motion을 위한 VQ-VAE와 GPT 기반의 simple하고 classic한 프레임워크를 개발했다. 저자들은 textual description에서 motion을 생성하기 위해 2단계를 제안한다.

  1. standard 1D convolution network를 이용하여 motion sequence를 discrete code indices로 맵핑한다. 
  2. standard GPT-like model은 pre-trained text embedding으로부터 code indices의 sequence를 생성하도록 학습된다. 

이때, VQ-VAE의 naive training의 경우, code collapse라는 문제가 발생한다. 이를 해결할 수 있는 가장 효과적인 방법은 EMA 또는 Code Reset과 같은 방법을 training에 적용하는 것이다. 다음으로, GPT에 있어서 다음 token을 예측하는것은 training과 inference간의 불일치라는 문제점을 야기한다. 때문에 본 논문에서는 training에 간단한 corrupting sequence를 적용하여 이러한 문제를 해결했다. 더욱이, image generation에 있어서 dataset의 크기는 가장 중요한 역할을 하고 있다. 본 논문에서는 실험적으로 이를 증명함으로써, 더 큰 dataset을 사용하는 경우 제안하는 기법의 성능이 더욱 향상될 것이라고 제시하고 있다.

 

기법의 simplicity에도 불구하고, 본 논문에서 제안하는 방법은 높은 품질의 motion sequence 생성하고, 이때 생성된 motion sequence는 어려운 text description과도 잘 부합한다. (실험적으로 다른 모델과 비교했을 때, R-Precesion은 비교할만한 성능을 보였으나, MotionDiffuse에 비해 FID가 매우 떨어지는 모습을 보였다. 이는 추가실험으로 밝혀야 할 부분이다.)

 

본 논문의 contribution을 정리하면 다음과 같다.

  1. 본 논문에서는 textual description으로부터 motion을 생성하는 간단하고 효과적인 방법을 제안한다. 그리고 제안하는 방법은 HumanML3D와 KIT-ML에서 SOTA를 달성했다.
  2. motion generation에서 discrete representation을 incoporate하는 GPT-like model이 여전히 효과적인 방법임을 증명하였다.
  3. quantization strategy와 dataset 크기에 대한 세밀한 분석을 제공한다.

 

Method

본 논문의 목적은 text description과 잘 부합하는 높은 quality의 motion을 생성하는 것이다. 전반적인 프레임워크는 Motion VQ-VAE와 T2M-GPT라는 2모듈로 이루어져 있다. 

Figure 2. Overview of our framework for text-driven motion generation. It includes two modules: Motion VQ-VAE (Figure 2a) and T2M-GPT (Figure 2b). In T2M-GPT, an additional learnable End token is inserted to indicate the stop of the generation. During the inference, we first generate code indexes in an auto-regressive fashion and then obtain the motion using the decoder in Motion VQ-VAE.

Motion VQ-VAE는 motion 데이터와 discrete code sequence의 맵핑을 수행하고, T2M-GPT는 text description을 조건으로 하는 code indices를 생성한다. Motion VQ-VAE의 decoder를 이용하면, code indices로부터 motion을 recover할 수 있다. 

 

1) Motion VQ-VAE

VQ-VAE는 generative model을 위해 model로 하여금 discrete representations을 학습할 수 있도록 한다. motion sequence $X$가 주어졌을 때, autoencoder와 learnable codebook을 통해 motion sequence를 복원할 수 있다. 이때, motion sequence는 $X = [x_1, x_2, ... , x_T]$로 표현될 수 있고, 이때, $x_t \in \mathbb{R}^d$ 이다. 이때 $T$는 frame의 수 이며, $d$는 motion의 차원이다. learnable codebook은 $K$개의 code로 이루어진 $C$로 표현된다. 따라서, 다시 표현하면 $C = \{c_k\}^K_{k=1}$로 표현할 수 있으며, 각각의 $c_k$는 $c_k \in \mathbb{R}^{d_c}$이다. 이때, $d_c$는 code의 차원이다. 

 

VQ-VAE의 구조는 위 Figure2의 (a)와 같고, autoencoder의 encoder와 decoder는 각각 $E$, $D$로 표현된다. latent feature $Z$는 encoder의 output으로 즉, $Z = E(X)$로 나타낼 수 있다. 이때, $Z$는 $Z=[z_1, z_2, ..., z_{T/l}]$로 나타낼 수 있으며, $z_i \in \mathbb{R}^{d_c}$다. 이때, $l$은 encoder $E$의 temporal downsampling rate를 나타낸다. (이후 architecture에서 상세히 다룬다.) 이때, $i$번째 latent feature인 $z_i$는 learnable codebook $C$를 통해 양자화(quantization)되는데, 이는 $C$의 요소 중 가장 유사한 것을 찾기 위함이다. 따라서, 이는 아래와 같이 쓸 수 있다.

$$\hat{z_i} = \arg \min_{c_k \in C} ||z_i - c_k||_2$$

 

Optimization goal. 

VQ-VAE를 최적화 하기 위한 standard optimization goal은 $\mathcal{L}_{vq}$이며, 이는 3가지의 요소를 포함하고 있다. 

  1. Reconstruction loss $\mathcal{L}_{re}$
  2. embedding loss $\mathcal{L}_{embed} = ||Z - sg[\hat{Z}]||_2$
  3. commitment loss $\mathcal{L}_{commit} = \beta ||sg[Z] - \hat{Z}||_2$

$$\mathcal{L}_{vq} = \mathcal{L}_{re} + \mathcal{L}_{embed} + \mathcal{L}_{commit} $$

이때, $\beta$는 commitment loss를 위한 hyper-parameter이며, $sg$는 stop-gradient operator다. 

 

reconstruction에서, L1 smooth loss $\mathcal{L}_1^{smooth}$가 가장 좋은 성능을 보였고 추가적인 velocity의 규제가 generation quality를 증가시켰다. $X_{re}$가 motion sequence $X$의 reconstructed motion이라고 할 때, $X_{re}$는 $X_{re} = D(\hat{Z})$로 표현될 수 있다. $V(X)$가 $X$의 velocity라고 할 때, $V = [v_1, v_2, ..., v_{T-1}]$이며, 이때, $v_i$는 $v_i = x_{i+1}-x_i$이다. 따라서 $\mathcal{L}_{re}$를 다시 정의하면 아래와 같다.

$$\mathcal{L}_{re} = \mathcal{L}_1^{smooth}(X, X_{re}) + \alpha\mathcal{L}_1^{smooth}(V(X), V(X_{re}))$$

이때, $\alpha$는 2개의 loss의 균형을 위한 hyper-parameter다.(본 논문에서는 Appendix에 $\alpha$에 대한 추가 실험에 대한 내용을 제시한다.)

 

Quantization strategy. 

VQ-VAE의 naive training은 codebook collapse라는 문제가 발생하고, 다음 2가지 training 기법이 codebook의 활용도를 증가시키기위해 사용된다. 

  1. EMA(Exponential Moving Average)
  2. CodeReset(codebook reset)

먼저, EMA는 codebook $C$를 smooth하게 변화시킨다. $C^t$가 $t$시점의 codebook이라고 하면, 이는 아래와 같이 구해질 수 있다. 이때 $lambda$는 지수 이동을 위한 상수다. 

$$C^t \leftarrow \lambda C^{t-1} + (1-\lambda)C^t$$

 

다음으로, CodeReset은 training동안 활성화되지 않는 code를 찾고, input data를 따라 이를 다시 할당한다. 

 

Architecture. 

본 논문에서는 1D convolution, residual block, ReLU로 이루어진 간단한 convolutional 구조를 사용한다. 이는 아래와 같다. 

Figure 3. Architecture of the motion VQ-VAE. We use a standard CNN-based architecture with 1D convolution (Conv1D), residual block (ResBlock) and ReLU activation. ‘L’ denotes the number of residual blocks. We use convolution with stride 2 and nearest interpolation for temporal downsampling and upsampling.

 

본 논문에서는 convolution에서 stride 2, 그리고 temporal downsampling과 upsampling을 위해 nearest interpolation을 사용한다. 따라서 앞서 살펴보았던 downsampling rate $l$은 $l = 2^L$로 계산될 수 있으며, 이때, $L$은 residual block의 개수다. 

 

2) T2M-GPT

학습된 motion VQ-VAE를 통해 moton sequence $X = [x_1, x_2, ..., x_T]$는 index들의 sequence인 $S = [s_1, s_2, ..., s_{T/l}, End]$로 맵핑될 수 있다. 이때, $s_i$는 learned codebook의 index로 $s_i \in [1, 2, ... , s_{T/l}]$이다. 이때 $End$ 토큰은 motion의 끝을 표시하기 위해 추가된 것으로 다른 연구들이 motion length를 예측하기 위해 추가적인 모듈을 사용하는것과 다른 점이다. 

 

$S$를 연관된 codebook entry로 projecting함으로써, $\hat{Z}$를 얻을 수 있다. 이때, $\hat{Z} = [\hat{z}_1, \hat{z}_2, ... , \hat{z}_{T/l}]$로 표현될 수 있고, 각각의 $\hat{z}_i = c_{s_i}$이다. $\hat{Z}$는 decoder $D$를 통해 $X_{re}$로 decoding될 수 있다. 

 

따라서, text-to-motion generation은 autoregressive next-index prediction으로 공식화될 수 있다. 즉, 이전의 $i-1$의 index($S_{<i}$)들과 text conditon $c$가 주어졌을 때, 다음 index가 될 수 있는 분포 $p(S_i|c, S_{<i})$를 예측하는 것이다. 이때, 이는 transformer를 이용해 해결할 수 있다. 

 

Optimization goal. 

Full sequence의 likilihood를 $p(S|c)$로 나타내면, $p(S|c) = \prod ^{|S|}_{i=1} p(S_i|c, S_{<i})$이다. 이때, data 분포의 log-likelihood를 최대화할 수 있다.

$$\mathcal{L}_{trans} = \mathbb{E}_{S \sim p(S)}[-log \ p(S|c)]$$

 

본 논문에서는 text embedding $c$를 추출하기 위해 CLIP을 사용하였다. 

 

Casual Self-attention. 

본 논문에서는 casual self-attention을 사용한다. casual self-attention의 출력은 아래와 같이 계산될 수 있다.

$$Attention = Softmax \left( {{QK^T \times mask} \over {\sqrt{d_k}}} \right)$$

이때, $Q$와 $K$는 각각 query 와 key를 나타내며, $Q \in \mathbb{R}^{T \times d_k}$이고 $K \in \mathbb{R}^{T \times d_k}$이다. 그리고 $mask$는 casual mask로, $mask_{i, j} = -\infty \times 1(i>j) + 1(i \leq j)$로, 결국 이는 미래의 feature를 현재의 token을 계산하는데 사용하지 않기 위해 사용한다. 

 

생성시에는 text embedding으로부터 시작하여, index를 autoregressive하게 생성하는데, 이 생성과정은 model이 $End$ 토큰을 생성했을 때 멈추게 된다. 

 

Corrupted sequences for the training-testing discrepancy. 

Training과 testing사이에는 차이가 발생하게 된다. training에서 $i-1$의 정확한 index들이 다음 index를 예측하기 위해 사용된다. 하지만, 생성시에는 condition으로 주어지는 index들이 올바른지에 대한 보장은 없다. 이 문제를 다루기 위해, 본 논문에서는 간단한 data augmentation 전략을 적용한다. 

 

본 논문에서 사용하는 전략은 바로 training 단계에서 $\tau \times 100%$ 만큼의 ground-truth 코드 index를 random한 것으로 교체하는 것이다. $\tau$는 hyper-parameter로 설정되거나 또는 $\tau \in \mathcal{U}[0, 1]$로부터 랜덤하게 샘플링 될 수 있다. 

 

Experiment

본 논문에서는 HumanML3D와 KIT Motion-Language 데이터를 이용하여 실험을 진행하였다. 

Implementation details.

1) Motion VQ-VAE

codebook size : 512 x 512

downsampling rate $l$ : 4

motion sequence $T$ : 64

optimizer : AdamW ($[\beta_1, \beta_2] = [0.9, 0.99]$)

batch size : 256

exponential moving constant $\lambda$ : 0.99

learning rate : 2e-4(First 200K iter), 1e-5(100K)

$\beta$ : 1

$\alpha$ : 0.5

 

2) T2M-GPT

transformer : 18 layers, 1,024 dimensions, 16 heads

Maximum length of Motion : 196

maximum length of the code index sequence : 50

optimizer : AdamW ($[\beta_1, \beta_2] = [0.5, 0.99]$)

batch size : 128

 

Table 1. Comparison with the state-of-the-art methods on HumanML3D [21] test set. We compute standard metrics following Guo et al. [21]. For each metric, we repeat the evaluation 20 times and report the average with 95% confidence interval. Red and Blue indicate the best and the second best result.
Table 2. Comparison with the state-of-the-art methods on KIT-ML [53] test set. We compute standard metrics following Guo et al. [21]. For each metric, we repeat the evaluation 20 times and report the average with 95% confidence interval. Red and Blue indicate the best and the second best result.

 

Quantitative results.

본 논문에서는 위의 Table 1과 Table 2를 통해 성능을 입증했다. HumanML3D와 KIT-ML 두 데이터셋 모두에서 VQ-VAE의 reconstruction performance는 real motion에 근접했다. 또한, text-motion 일관성 (R-Precision, MM-Dist)에서 SOTA인 Motion Diffuse와 비교할만한 성능을 보였고, FID에서는 Motion Diffuse를 앞섰다. 

 

 특히, $\tau$의 값을 0.5로 설정한 결과와 0으로 설정한 결과를 비교해보면, GPT를 학습시키는 동안 seqeunce를 수동적으로 손상시키는 것이 성능의 개선에 도움을 주는 것을 볼 수 있다. 

 

 또한, motion length를 예측하는 추가적은 모듈을 포함하지 않고, $End$ 토큰을 이용하여 motion length를 예측하도록 하므로 더욱 효율적이라고 할 수 있다. (MDM과 MotionDiffuse의 경우 ground truth motion length를 이용하여 model을 평가하는데, 이는 실제 application에 적합하다고 할 수 없다.)

 

Figure 4. Visual results on HumanML3D [21] dataset. We compare our generation with Guo et al. [21], MotionDiffuse [72], and MDM [65]. Distorted motions (red) and sliding (yellow) are highlighted. More visual results can be found on the project page project page.

 

Qualitative comparison.

위의 Figure 4에서는 HumanML3D에서의 결과를 시각화 한 것이다. 현재 SOTA인 모델들과 비교했을 때, 제안하는 기법에서 text description에 적합한 결과물을 보이는 것을 볼 수 있다. 이때 비교한 SOTA 모델은 다음과 같다

  1. (CVPR 2022) Generating diverse and natural 3d human motions from text.
  2. (ICLR 2023) Human motion diffusion model
  3. Motiondiffuse: Textdriven human motion generation with diffusion model

 

Discussion

Quatization strategies.

본 논문에서는 naive  VQ-VAE training이 고품질의 motion을 생성할 수 없다는 것을 발견하고, EMA와 Code Reset 기법을 적용하여 reconstruction과 generation 성능을 끌어올렸다. 

Table 3. Analysis of VQ-VAE quantizers on HumanML3D [21] test set. For all the quantizers, we set τ = 0.5 and use the same architectures (VQ-VAE and GPT) described in Section 4.1. We report FID and Top-1 for both reconstruction and generation. For each metric, we repeat the evaluation 20 times and report the average with 95% confidence interval.

 

Impact of dataset size.

앞서 말한것과 같이, 본 논문에서는 dataset 크기에 따른 분석을 추가로 진행했다. 본 분석의 목표는 HumanML3D가 motion generation 분야에서 필요한 충분한 데이터 크기를 가지고 있는지를 살펴보는 것인데, 이를 위해 본 논문에서는 제안하는 VQ-VAE와 T2M-GPT를 training data의 다른 subset을 이용하여 학습시켰다. 이때, subset은 training data의 10%, 20%, 50%, 80%, 100%를 포함하도록 했다. 이후 학습된 모델을 test set 전체를 이용하여 평가했다. 

 

Figure 5. Impact of dataset size on HumanML3D [21]. We train our motion VQ-VAE (Reconstruction) and T2M-GPT (Generation) on the subsets of HumanML3D [21] composed of 10%, 20%, 50%, 80%, and 100% training set respectively. All the models are evaluated on the entire test set. We report FID, MM-Dist, Top-1, and Top-3 accuracy for all the models. Results suggest that our model might benefit from more training data.

 

 실험 결과, training data의 10%에 해당하는 subset을 이용하여 모델을 학습한 결과, 생성된 motion은 좋은 퀄리티를 가지고 있으나, 주어진 text description에 적합한 motion을 생성하지 못하는 모습을 보였다. 또한 training data를 더욱 많이 사용하면 사용할수록 더욱 좋은 성능을 보였다.

 

Discussion

본 논문에서 저자들은 textual description으로부터 motion을 생성하는 VQ-VAE와 GPT를 기반으로 한 classic한 프레임워크를 선보였다. 제안하는 프레임워크는 diffusion 기반의 프레임워크와 비교할만한 성능 또는 좋은 성능을 보였다. 따라서 이를 통해 classic한 프레임워크가 여전히 motion generation 분야에서 경쟁력이 있다는 것을 볼 수 있다.