Paper/BC with Generative model

[PhysicalAI] Diffusion Policy

충남대이적 2025. 10. 5. 14:55

참고한 자료들

<Youtube>

1 diffusion model 수학이 포함된 tutorial

2. [Open DMQA Seminar] Conditional Diffusion Models

3. Score-based Diffusion Models | Generative AI Animated

4. What are Diffusion Models?

5. Generative Modeling by Estimating Gradients of the Data Distribution

Prerequisite 

DDPM - Denoising Diffusion Probabilistic Models

Diffusion이란 처음에는 응집되어있다가 시간이 지남에 따라 퍼지는 현상을 말한다. Diffusion model은 원본 이미지에 노이즈를 조금씩 씌우는 Forward process와 완전한 노이즈 이미지에서 의미있는 이미지로 되돌리는 Reverse process로 구성되어있다. 공기분자들이 응집되어있다가 확산하는 과정을 미시적으로 살펴보면 모두 정규분포로 모델링할 수 있다. 이 개념에 착안해서 Diffusion도 forward process와 reverse process를 정규분포로 모델링한다.

$$
Forward_process : \underbrace{q(\mathbf{x}_t \mid \mathbf{x}_{t-1})}_{\text{Distribution of the noised images}}
= \mathcal{N}\bigl(\mathbf{x}_t; \sqrt{1 - \beta_t}\,\mathbf{x}_{t-1}, \beta_t\mathbf{I}\bigr)

\\[1em]

Reverse_process : \underbrace{p_\theta(\mathbf{x}_{t-1} \mid \mathbf{x}_t)}_{\text{Learned reverse distribution (denoising) }}
= \mathcal{N}\bigl(\mathbf{x}_{t-1}; \boldsymbol{\mu}_\theta(\mathbf{x}_t, t), \boldsymbol{\Sigma}_\theta(\mathbf{x}_t, t)\bigr)
$$

 

어쩌다가 diffusion은 model의 distribution이 아닌 noise를 학습하게 된걸까?

신경망의 목적은 negative log likelihood를 최소화하는 것이다.

$$ \mathcal{L}(\theta) = - \mathbb{E}_{x \sim p_{\text{data}}} \left[ \log p_\theta(x) \right] $$

 

위 수식을 bayes rule을 사용해서 조작하고, marcov chain property, KL divergence, ELBO를 사용해 수식을 유도하면 아래와 같은 loss function이 나온다.

 

$$
\mathbb{E}_q \Bigg[
    \underbrace{D_{\mathrm{KL}}\bigl(q(x_T \mid x_0)\,\|\,p(x_T)\bigr)}_{\text{Does Not depend on }\theta}
    \;+\;
    \sum_{t>1} D_{\mathrm{KL}}\bigl(q(x_{t-1} \mid x_t, x_0)\,\|\,p_\theta(x_{t-1}\mid x_t)\bigr)
    \;-\;
    \underbrace{\log p_\theta(x_0 \mid x_1)}_{\text{Negligible}}
\Bigg]
$$

 

결국 loss function중에 두 항은 무시할 수 있고, 하나의 항만 남게된다. q와 p 모두 정규분포로 모델링이 가능하기 때문에 두 분포의 KL-divergence가 계산가능하다. 계산을 하면 아래와 같이 간단한 형태로 나오게 된다(앞에 복잡한 계수가 있는데 이는 1로 처리)

 

 

Diffusion policy

DIffusion은 이미지 생성을 위한 모델이었기에 DDPM을 Visualmotor policy로 사용하기 위해서는 약간의 변경이 필요합니다.

 

1. changing the output $ x $ to represent robot actions

2. making the denoising processes conditioned on input observation $ O_t $

 

Closed-loop action-sequence prediction:

ACT에서 action sequnce를 생성했듯이 동일하게 DP에서도 action sequence를 생성한다. $T_o$(observation horizon)step의 observation data를 입력으로 받아 $T_p$(action prediction horizon)step만큼의 action step을 생성하고, $T_a$(action execution horizon)만큼의 action을 실행한다. 

Visual observation conditioning:

DDPM을 $ P(A_t, O_t) $를 학습시키는 대신 $ P(A_t | O_t) $를 학습시켰다. 이를 위해 다음과 같이 DDPM의 수식을 변경시켰다.

 

Network Architecture

CNN-based Diffusion Policy

CNN에는 FiLM(Feature-wise Linear Modulation)를 사용해 conditional distribution $ P(At|Ot) $을 모델링한다.

CNN모델은 hyperparameter에는 큰 영향을 받지 않고 대부분 잘 작동하는 것이 장점이다.

하지만, 로봇이 빠르게 움직여야하는 상황에서는 잘 동작하지 않는다는 단점이 있다.

Time-series diffusion transformer

transformer구조는 성능이 좋으나, hyperparameter의 영향을 많이 받는다고 한다.

Visual Encoder

각각의 카메라는 다른 visual encoder를 사용했으며, 모델에 입력을 전달할 때는 concat해서 전달한다.

DP에서는 ResNet-18(without pretraining)을 사용했고, 약간의 수정을 했다.

1. Replace the global average pooling with a spatial softmax pooling to maintain spatial information

2. Replace BatchNorm with GroupNorm for stable training. This is important when the normalization layer is used in conjunction with Exponential Moving Average(commonly used in DDPMs).

Noise Schedule

iDDPM에서 제안한 Square Cosine Schedule을 사용했다.

noise schedule은 DP가 action sequnce의 low-frequency characteristics와 high-frequency characteristics의 정도를 조절하기 때문에 생각보다 중요한 변수이다.

  • 저주파 성분(low-frequency) : 느리고 부드럽게 변하는 동작 패턴 (예: 천천히 팔을 들어올리는 로봇 모션)
  • 고주파 성분(high-frequency) : 빠르고 세밀한 변화 (예: 로봇 손목이 빠르게 각도를 조정하거나 미세한 힘 조절)

만약 노이즈 스케줄이 너무 강하거나 너무 빠르게 증가하면, 모델이 세밀한 고주파 정보를 잃고 부드럽지만 디테일이 부족한 행동만 생성할 수 있다. 반대로 노이즈가 너무 약하거나 느리게 증가하면 고주파를 더 잘 보존할 수 있지만 안정적으로 저주파를 학습하기 어려울 수 있다.

Accelerating Inference for Real-time Control

DDIM에서 사용한 방법으로 제어속도를 높였다는데 DDIM이 뭔지 공부해봐야겠다.
3080기준으로 0.1s만에 추론이 가능하다.

Intriguing Properties of Diffusion Policy

Model Multi-Modal Action Distributions

diffusion의 태생이 고차원의 이미지를 생성하는 작업이다보니 고차원의 분포를 표현할 수 있는 능력이 있다. 아래 그림과 같이 Push T작업을 위해 왼쪽으로 갈 수도 있고, 오른쪽으로 갈 수도 있다. 하나의 작업을 위해 여러가지 방식이 있을 수 있다는 것이 사람의 시연데이터의 multi-modal한 특성이다. LSTM-GMM은 한 쪽으로만 경로가 생성되고, BET는 두 경로간에 왔다갔다해서 두 분포를 제대로 분리하지 못했다. IBC는 깔끔하게 하나만 학습했다.

 

 

Synergy with Position Control

 

다른 연구에서는 속도제어대신 위치제어를 사용할 경우 성능이 감소하는 현상을 보였는데, DP의 경우 위치제어를 할 때 더 좋은 성능을 보여줌을 알 수 있다. 그 이유를 저자는 두 가지로 설명한다.

 

1. First, action multimodality is more pronounced in position-control mode than it is when using velocity control.

2. position control suffers less than velocity control from compounding error effects and is thus more suitable for action sequence prediction

 

모든 작업에 대해서 위치제어가 속도제어보다 나을까? 라는 재밌는 토론이 있었는데 분명 위치제어가 정밀한 작업에는 더 좋은 방법일 수 있겠으나 물을 담은 그릇을 옮김다든지, 정밀함 보다는 일정한 속도(용접)과 같은 작업에서는 속도제어의 이점도 있을 것이라고 생각한다.

 

Benefits of Action-Sequence Prediction

 

diffusion이 고차원출력을 잘 할 수 있기 때문에 Action Sequnce를 추론할 때 Temporal action consistency가 다른 모델들보다 좋았다. 또한 action sequnce를 예측하는 것이기 때문에 중지했을 때(컵에 물을 따르는 상황) 멈추는 동작에 과적합되는 경우가 있는데 DP는 action sequnce를 출력함으로써 이러한 문제를 완하했다.(하지만, 완전하게 없앤건 아님. 실패 동영상을 보면 stuck되는 경우가 있음)