인공지능 공부

모션 데이터에 DTW 적용하기

DualQuaternion 2023. 8. 3. 17:12

영상에서 VIBE를 적용하고, 거기에서 SMPL 파라미터를 추출한 다음 3d joint position을 빼는 방법으로 두개의 데이터를 준비했다.

 

이걸 위해서 쓴 포지션 익스포터

import pickle
import joblib
import pandas as pd
from pandas import DataFrame
import json
import numpy as np
import shutil

path = "output/differentV2/different/vibe_output.pkl"

data = joblib.load(path)

data[1]['joints3d'].tofile("joints3d_4.txt",", ")

 

그리고 그 두개 데이터를 입력으로 해서 DTW를 수행해본 결과는 다음과 같았다.

 

혹시 몰라서 테스트용으로, 하나의 데이터 앞에 0 값을 넣어서 테스트 해보니 그 결과가 예상한 대로 나왔다.

 

두개는 원래 같은 데이터인데, query 쪽에 첫 프레임의 값을 여러번 반복해서 넣었더니 나온 결과이다. 마음에 든다.

 

자 그럼 이제 이게 어떤 결과를 낳았는지를 확인해야 한다.

 

내가 DTW를 한 이유는 그나마 유사한 동작이 있는 부분을 찾아내기 위함이었다.

 

그게 제대로 되었는지 확인을 하려면 DTW의 결과를 viewer에서 반영해서 보여줘야 한다.

 

이걸 어떻게 해야 하려나?

 

DTW의 기능을 좀 더 확인해보자.

 

DTW의 help 기능을 통해서 확인한 내용은 다음과 같다.

 

 |  - ``distance`` the minimum global distance computed, *not* normalized.
 |  - ``normalizedDistance`` distance computed, *normalized* for path
 |    length, if normalization is known for chosen step pattern.
 |  - ``N,M`` query and reference length
 |  - ``call`` the function call that created the object
 |  - ``index1`` matched elements: indices in ``x``
 |  - ``index2`` corresponding mapped indices in ``y``
 |  - ``stepPattern`` the ``stepPattern`` object used for the computation
 |  - ``jmin`` last element of reference matched, if ``open_end=True``
 |  - ``directionMatrix`` if ``keep_internals=True``, the directions of
 |    steps that would be taken at each alignment pair (integers indexing
 |    production rules in the chosen step pattern)
 |  - ``stepsTaken`` the list of steps taken from the beginning to the end
 |    of the alignment (integers indexing chosen step pattern)
 |  - ``index1s, index2s`` same as ``index1/2``, excluding intermediate
 |    steps for multi-step patterns like [asymmetricP05()]
 |  - ``costMatrix`` if ``keep_internals=True``, the cumulative cost matrix
 |  - ``query, reference`` if ``keep_internals=True`` and passed as the
 |    ``x`` and ``y`` arguments, the query and reference timeseries.

query의 몇번째 값이 reference의 몇번쨰 값에 해당하는지만 알면 될 것 같은데....

index1과 index2가 뭔가 내가 원하는 값인 것으로 보인다.

 

출력해보자. 

명령어는 다음과 같았고, 

print(alignment.index1)
print(alignment.index2)

결과는 이와 같았다. 

index1은 1씩 순차적으로 증가하고 있으니 index2의 데이터만 가져다가 쓰면 될 것 같다. 

 

index2의 익스포트는 아래 코드로 간단하게 하면 된다. 

alignment.index2.tofile("dtwResult.txt",",")

 

편하네?ㅋㅋㅋㅋ

 

이제 DTW 전과 후의 모션을 비교해서 가시화 하는 작업을 해봐야겠다.