Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
__pycache__
.ipynb_checkpoints
Mean.npy
Std.npy
amass_data
animations
body_models
joints
new_joints
new_joint_vecs
pose_data
File renamed without changes.
File renamed without changes.
Binary file removed HumanML3D/new_joint_vecs/012314.npy
Binary file not shown.
Binary file removed HumanML3D/new_joints/012314.npy
Binary file not shown.
2 changes: 1 addition & 1 deletion animation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"This will take a few hours for the whole dataset. Here we show ten animations for an example\n"
"This will take a few hours for the whole dataset."
]
},
{
Expand Down
141 changes: 141 additions & 0 deletions animation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import os
from os.path import join as pjoin
from tqdm import tqdm
import numpy as np
import argparse
import math


import matplotlib
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.animation import FuncAnimation, PillowWriter
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import mpl_toolkits.mplot3d.axes3d as p3
def plot_3d_motion(save_path, kinematic_tree, joints, title, figsize=(10, 10), fps=120, radius=4):
# matplotlib.use('Agg')

title_sp = title.split(' ')
if len(title_sp) > 10:
title = '\n'.join([' '.join(title_sp[:10]), ' '.join(title_sp[10:])])
def init():
ax.set_xlim3d([-radius / 2, radius / 2])
ax.set_ylim3d([0, radius])
ax.set_zlim3d([0, radius])
# print(title)
fig.suptitle(title, fontsize=20)
ax.grid(b=False)

def plot_xzPlane(minx, maxx, miny, minz, maxz):
## Plot a plane XZ
verts = [
[minx, miny, minz],
[minx, miny, maxz],
[maxx, miny, maxz],
[maxx, miny, minz]
]
xz_plane = Poly3DCollection([verts])
xz_plane.set_facecolor((0.5, 0.5, 0.5, 0.5))
ax.add_collection3d(xz_plane)

# return ax

# (seq_len, joints_num, 3)
data = joints.copy().reshape(len(joints), -1, 3)
fig = plt.figure(figsize=figsize)
ax = fig.add_subplot(111, projection = "3d")
init()
MINS = data.min(axis=0).min(axis=0)
MAXS = data.max(axis=0).max(axis=0)
colors = ['red', 'blue', 'black', 'red', 'blue',
'darkblue', 'darkblue', 'darkblue', 'darkblue', 'darkblue',
'darkred', 'darkred','darkred','darkred','darkred']
frame_number = data.shape[0]
# print(data.shape)

height_offset = MINS[1]
data[:, :, 1] -= height_offset
trajec = data[:, 0, [0, 2]]

data[..., 0] -= data[:, 0:1, 0]
data[..., 2] -= data[:, 0:1, 2]

# print(trajec.shape)

def update(index):
# print(index)
ax.cla()

ax.set_xlim3d([-radius / 2, radius / 2])
ax.set_ylim3d([0, radius])
ax.set_zlim3d([0, radius])
ax.grid(False)
ax.view_init(elev = 120, azim = -90)
ax.dist = 7.5

plot_xzPlane(MINS[0]-trajec[index, 0], MAXS[0]-trajec[index, 0], 0, MINS[2]-trajec[index, 1], MAXS[2]-trajec[index, 1])
# ax.scatter(data[index, :22, 0], data[index, :22, 1], data[index, :22, 2], color='black', s=3)

if index > 1:
ax.plot3D(trajec[:index, 0]-trajec[index, 0], np.zeros_like(trajec[:index, 0]), trajec[:index, 1]-trajec[index, 1], linewidth=1.0,
color='blue')
# ax = plot_xzPlane(ax, MINS[0], MAXS[0], 0, MINS[2], MAXS[2])


for i, (chain, color) in enumerate(zip(kinematic_tree, colors)):
# print(color)
if i < 5:
linewidth = 4.0
else:
linewidth = 2.0
ax.plot3D(data[index, chain, 0], data[index, chain, 1], data[index, chain, 2], linewidth=linewidth, color=color)
# print(trajec[:index, 0].shape)

plt.axis('off')
ax.set_xticklabels([])
ax.set_yticklabels([])
ax.set_zticklabels([])

ani = FuncAnimation(fig, update, frames=frame_number, interval=1000/fps, repeat=False)

ani.save(save_path, fps=fps)
plt.close()


def main():
parser = argparse.ArgumentParser()
parser.add_argument("--num-batches", type = int, default = 10)
parser.add_argument("--batch-idx", type = int, default = 0, help = "0 based batch index")
args = parser.parse_args()

src_dir = './HumanML3D/new_joints/'
tgt_ani_dir = "./HumanML3D/animations/"


kinematic_chain = [[0, 2, 5, 8, 11], [0, 1, 4, 7, 10], [0, 3, 6, 9, 12, 15], [9, 14, 17, 19, 21], [9, 13, 16, 18, 20]]
os.makedirs(tgt_ani_dir, exist_ok=True)

npy_files = os.listdir(src_dir)
npy_files = sorted(npy_files)
# npy_files = npy_files[:10]

n = len(npy_files)
batch_size = math.ceil(n / args.num_batches)
start = args.batch_idx * batch_size
end = min(start + batch_size, n)
batch = npy_files[start:end]
desc = f"batch {args.batch_idx + 1} / {args.num_batches} ({start}:{end} of {n})"


for npy_file in tqdm(batch, desc = desc):
src_path = pjoin(src_dir, npy_file)
data = np.load(src_path)
save_path = pjoin(tgt_ani_dir, npy_file[:-3] + 'mp4')
if os.path.exists(save_path):
continue
# You may set the title on your own.
plot_3d_motion(save_path, kinematic_chain, data, title="None", fps=20, radius=4)


if __name__ == "__main__":
main()
61 changes: 61 additions & 0 deletions cal_mean_variance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import numpy as np
import sys
import os
from os.path import join as pjoin


# root_rot_velocity (B, seq_len, 1)
# root_linear_velocity (B, seq_len, 2)
# root_y (B, seq_len, 1)
# ric_data (B, seq_len, (joint_num - 1)*3)
# rot_data (B, seq_len, (joint_num - 1)*6)
# local_velocity (B, seq_len, joint_num*3)
# foot contact (B, seq_len, 4)
def mean_variance(data_dir, save_dir, joints_num):
file_list = os.listdir(data_dir)
data_list = []

for file in file_list:
data = np.load(pjoin(data_dir, file))
if np.isnan(data).any():
print(file)
continue
data_list.append(data)

data = np.concatenate(data_list, axis=0)
print(data.shape)
Mean = data.mean(axis=0)
Std = data.std(axis=0)
Std[0:1] = Std[0:1].mean() / 1.0
Std[1:3] = Std[1:3].mean() / 1.0
Std[3:4] = Std[3:4].mean() / 1.0
Std[4: 4+(joints_num - 1) * 3] = Std[4: 4+(joints_num - 1) * 3].mean() / 1.0
Std[4+(joints_num - 1) * 3: 4+(joints_num - 1) * 9] = Std[4+(joints_num - 1) * 3: 4+(joints_num - 1) * 9].mean() / 1.0
Std[4+(joints_num - 1) * 9: 4+(joints_num - 1) * 9 + joints_num*3] = Std[4+(joints_num - 1) * 9: 4+(joints_num - 1) * 9 + joints_num*3].mean() / 1.0
Std[4 + (joints_num - 1) * 9 + joints_num * 3: ] = Std[4 + (joints_num - 1) * 9 + joints_num * 3: ].mean() / 1.0

assert 8 + (joints_num - 1) * 9 + joints_num * 3 == Std.shape[-1]

np.save(pjoin(save_dir, 'Mean.npy'), Mean)
np.save(pjoin(save_dir, 'Std.npy'), Std)

return Mean, Std


# The given data is used to double check if you are on the right track.
reference1 = np.load('./HumanML3D/Mean_reference.npy')
reference2 = np.load('./HumanML3D/Std_reference.npy')


if __name__ == '__main__':
data_dir = './HumanML3D/new_joint_vecs/'
save_dir = './HumanML3D/'
mean, std = mean_variance(data_dir, save_dir, 22)
# print(mean)
# print(Std)


print(abs(mean-reference1).sum())


print(abs(std-reference2).sum())
2 changes: 1 addition & 1 deletion common/quaternion.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

_EPS4 = np.finfo(float).eps * 4.0

_FLOAT_EPS = np.finfo(np.float).eps
_FLOAT_EPS = np.finfo(float).eps

# PyTorch-backed implementations
def qinv(q):
Expand Down
8 changes: 4 additions & 4 deletions environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ dependencies:
- zstd=1.4.9=haebb681_0
- pip:
- absl-py==1.0.0
- body-visualizer==1.1.0
#- body-visualizer==1.1.0
- cachetools==4.2.4
- charset-normalizer==2.0.12
- configer==1.4.1
#- configer==1.4.1
- configparser==5.2.0
- dotmap==1.3.23
- freetype-py==2.3.0
Expand All @@ -147,15 +147,15 @@ dependencies:
- grpcio==1.46.3
- idna==3.3
- imageio==2.19.3
- install==1.3.5
#- install==1.3.5
- markdown==3.3.7
- networkx==2.6.3
- numpy==1.18.5
- oauthlib==3.2.0
- opencv-python==4.5.5.64
- pillow==9.1.1
- protobuf==3.20.1
- psbody-mesh==0.4
#- psbody-mesh==0.4
- pyasn1==0.4.8
- pyasn1-modules==0.2.8
- pyglet==1.5.26
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading