Ubisoft La Forge Animation Dataset은 풍부한 캐릭터 애니메이션 데이터를 포함하는 전문적인 애니메이션 데이터셋입니다. 본 튜토리얼에서는 해당 데이터셋에서 제공하는 extract.py 도구를 사용하여 BVH 형식의 애니메이션 데이터를 처리하는 방법을 자세히 설명합니다. 초보 사용자도 애니메이션 데이터 추출 및 처리를 쉽게 시작할 수 있도록 돕는 것을 목표로 합니다.
Ubisoft La Forge Animation Dataset 이해
Ubisoft La Forge Animation Dataset은 Ubisoft La Forge 연구소에서 공개한 고품질 애니메이션 데이터셋으로, 애니메이션 연구, 모션 캡처 분석 등 다양한 분야에 활용될 수 있는 방대한 양의 캐릭터 애니메이션 데이터를 포함합니다. 데이터셋은 여러 형식의 애니메이션 파일을 제공하며, 그중 BVH(Biovision Hierarchy) 형식은 뼈대 계층 구조와 운동 데이터를 포함하는 일반적인 모션 데이터 형식입니다.

위 이미지는 데이터셋의 LaFAN1 애니메이션 예시로, 다양한 동작을 하는 캐릭터 애니메이션 효과를 보여줍니다.
extract.py 도구 소개
extract.py는 Ubisoft La Forge Animation Dataset에서 제공하는 Python 스크립트 도구로, 프로젝트의 lafan1 디렉토리 내에 위치합니다 (경로: lafan1/extract.py). 이 도구는 주로 BVH 파일에서 애니메이션 데이터를 추출하여 추가 처리 및 분석에 적합한 형식으로 변환하는 데 사용됩니다. extract.py의 주요 기능은 다음과 같습니다:
- BVH 파일을 읽고 뼈대 계층 구조 및 운동 데이터 파싱
- 오일러 각 회전을 쿼터니언(Quaternion) 표현으로 변환
- 애니메이션 클립 추출 및 슬라이딩 윈도우 기반 애니메이션 시퀀스 생성
- 데이터 정규화를 위한 애니메이션 통계 정보 계산
사전 준비
extract.py를 사용하기 전에 numpy와 같은 필수 라이브러리가 환경에 설치되어 있는지 확인해야 합니다. 또한, Ubisoft La Forge Animation Dataset의 BVH 파일에 접근할 수 있어야 합니다. 데이터셋을 아직 다운로드하지 않았다면 다음 명령을 사용하여 저장소를 클론할 수 있습니다:
git clone https://gitcode.com/gh_mirrors/ub/ubisoft-laforge-animation-dataset
extract.py를 이용한 BVH 애니메이션 데이터 처리 단계
1단계: extract.py 모듈 임포트
Python 코드에서 extract.py 모듈은 다음과 같이 임포트할 수 있습니다:
from lafan1 import extract
2단계: BVH 파일 읽기
extract.py는 BVH 파일을 읽기 위한 read_bvh 함수를 제공합니다. 이 함수는 lafan1/extract.py 파일의 43번째 줄에 정의되어 있으며, 다음과 같은 시그니처를 가집니다:
def read_bvh(filename, start=None, end=None, order=None):
"""
Reads a BVH file and extracts animation information.
:param filename: BVh filename
:param start: start frame
:param end: end frame
:param order: order of euler rotations
:return: A simple Anim object conatining the extracted information.
"""
사용 예시는 다음과 같습니다:
anim = extract.read_bvh("path/to/animation.bvh")
read_bvh 함수는 애니메이션의 쿼터니언 회전, 위치, 뼈대 오프셋, 부모 뼈대 인덱스, 뼈대 이름 등을 포함하는 Anim 객체를 반환합니다.
3단계: 애니메이션 시퀀스 추출
extract.py의 get_lafan1_set 함수를 사용하여 BVH 파일에서 특정 애니메이션 시퀀스를 추출할 수 있습니다. 이 함수는 lafan1/extract.py 파일의 169번째 줄에 정의되어 있으며, 다음과 같습니다:
def get_lafan1_set(bvh_path, actors, window=50, offset=20):
"""
Extract the same test set as in the article, given the location of the BVH files.
:param bvh_path: Path to the dataset BVH files
:param list: actor prefixes to use in set
:param window: width of the sliding windows (in timesteps)
:param offset: offset between windows (in timesteps)
:return: tuple:
X: local positions
Q: local quaternions
parents: list of parent indices defining the bone hierarchy
contacts_l: binary tensor of left-foot contacts of shape (Batchsize, Timesteps, 2)
contacts_r: binary tensor of right-foot contacts of shape (Batchsize, Timesteps, 2)
"""
사용 예시는 다음과 같습니다:
X, Q, parents, contacts_l, contacts_r = extract.get_lafan1_set("path/to/bvh_files", ["actor1", "actor2"])
이 함수는 BVH 파일에 대해 슬라이딩 윈도우 처리를 수행하여 지역 위치(local positions), 지역 쿼터니언(local quaternions), 뼈대 계층 구조 및 발 접촉 정보를 추출합니다.
4단계: 훈련 통계 정보 계산
get_train_stats 함수는 훈련 세트의 통계 정보를 계산하여 데이터 정규화에 사용합니다. 이 함수는 lafan1/extract.py 파일의 235번째 줄에 정의되어 있으며, 다음과 같습니다:
def get_train_stats(bvh_folder, train_set):
"""
Extract the same training set as in the paper in order to compute the normalizing statistics
:return: Tuple of (local position mean vector, local position standard deviation vector, local joint offsets tensor)
"""
사용 예시는 다음과 같습니다:
x_mean, x_std, offsets = extract.get_train_stats("path/to/bvh_files", ["actor1", "actor2"])
데이터 처리 시 핵심 기술
쿼터니언과 오일러 각 변환
애니메이션 데이터 처리에서 쿼터니언은 오일러 각의 짐벌 락(Gimbal Lock) 문제를 피할 수 있어 회전을 표현하는 데 자주 사용됩니다. extract.py는 lafan1/utils.py의 euler_to_quat 함수를 사용하여 오일러 각을 쿼터니언으로 변환합니다:
def euler_to_quat(e, order='zyx'):
"""
Converts from an euler representation to a quaternion representation
:param e: euler tensor
:param order: order of euler rotations
:return: quaternion tensor
"""
순방향 기구학(Forward Kinematics) 계산
extract.py는 lafan1/utils.py의 quat_fk 함수를 사용하여 순방향 기구학을 계산하고, 지역 좌표를 전역 좌표로 변환합니다:
def quat_fk(lrot, lpos, parents):
"""
Performs Forward Kinematics (FK) on local quaternions and local positions to retrieve global representations
:param lrot: tensor of local quaternions with shape (..., Nb of joints, 4)
:param lpos: tensor of local positions with shape (..., Nb of joints, 3)
:param parents: list of parents indices
:return: tuple of tensors of global quaternion, global positions
"""
쿼터니언 불연속성 제거
애니메이션의 부드러움을 보장하기 위해 extract.py는 lafan1/utils.py의 remove_quat_discontinuities 함수를 사용하여 쿼터니언의 불연속성을 제거합니다:
def remove_quat_discontinuities(rotations):
"""
Removing quat discontinuities on the time dimension (removing flips)
:param rotations: Array of quaternions of shape (T, J, 4)
:return: The processed array without quaternion inversion.
"""
평가 지표
애니메이션 데이터 처리에서 흔히 사용되는 평가 지표로는 L2P와 L2Q가 있습니다. L2P는 위치 오차의 L2 노름이며, L2Q는 회전 오차의 L2 노름입니다. 이러한 지표는 애니메이션 데이터 처리의 품질을 평가하는 데 도움이 됩니다.
결론
본 튜토리얼을 통해 Ubisoft La Forge Animation Dataset의 extract.py 도구를 사용하여 BVH 애니메이션 데이터를 처리하는 방법을 익혔습니다. BVH 파일 읽기부터 애니메이션 시퀀스 추출, 훈련 통계 정보 계산까지, extract.py는 포괄적인 애니메이션 데이터 처리 파이프라인을 제공합니다. 이 튜토리얼이 고품질의 애니메이션 데이터셋을 연구 및 개발에 더 잘 활용하는 데 도움이 되기를 바랍니다.