Skip to content

Commit b6f081a

Browse files
committed
resolve merge conflict
2 parents 8b57d73 + a560a58 commit b6f081a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+25
-136
lines changed

data/toy/train-set/poses0.npy

117 KB
Binary file not shown.

data/toy/train-set/poses1.npy

117 KB
Binary file not shown.

data/toy/train-set/poses10.npy

117 KB
Binary file not shown.

data/toy/train-set/poses11.npy

117 KB
Binary file not shown.

data/toy/train-set/poses12.npy

117 KB
Binary file not shown.

data/toy/train-set/poses13.npy

117 KB
Binary file not shown.

data/toy/train-set/poses14.npy

117 KB
Binary file not shown.

data/toy/train-set/poses15.npy

117 KB
Binary file not shown.

data/toy/train-set/poses16.npy

117 KB
Binary file not shown.

data/toy/train-set/poses17.npy

117 KB
Binary file not shown.

data/toy/train-set/poses18.npy

117 KB
Binary file not shown.

data/toy/train-set/poses19.npy

117 KB
Binary file not shown.

data/toy/train-set/poses2.npy

117 KB
Binary file not shown.

data/toy/train-set/poses20.npy

-117 KB
Binary file not shown.

data/toy/train-set/poses21.npy

-117 KB
Binary file not shown.

data/toy/train-set/poses22.npy

-117 KB
Binary file not shown.

data/toy/train-set/poses23.npy

-117 KB
Binary file not shown.

data/toy/train-set/poses24.npy

-117 KB
Binary file not shown.

data/toy/train-set/poses25.npy

-117 KB
Binary file not shown.

data/toy/train-set/poses26.npy

-117 KB
Binary file not shown.

data/toy/train-set/poses27.npy

-117 KB
Binary file not shown.

data/toy/train-set/poses28.npy

-117 KB
Binary file not shown.

data/toy/train-set/poses29.npy

-117 KB
Binary file not shown.

data/toy/train-set/poses3.npy

117 KB
Binary file not shown.

data/toy/train-set/poses30.npy

-117 KB
Binary file not shown.

data/toy/train-set/poses31.npy

-117 KB
Binary file not shown.

data/toy/train-set/poses32.npy

-117 KB
Binary file not shown.

data/toy/train-set/poses33.npy

-117 KB
Binary file not shown.

data/toy/train-set/poses34.npy

-117 KB
Binary file not shown.

data/toy/train-set/poses35.npy

-117 KB
Binary file not shown.

data/toy/train-set/poses36.npy

-117 KB
Binary file not shown.

data/toy/train-set/poses37.npy

-117 KB
Binary file not shown.

data/toy/train-set/poses38.npy

-117 KB
Binary file not shown.

data/toy/train-set/poses39.npy

-117 KB
Binary file not shown.

data/toy/train-set/poses4.npy

117 KB
Binary file not shown.

data/toy/train-set/poses5.npy

117 KB
Binary file not shown.

data/toy/train-set/poses6.npy

117 KB
Binary file not shown.

data/toy/train-set/poses7.npy

117 KB
Binary file not shown.

data/toy/train-set/poses8.npy

117 KB
Binary file not shown.

data/toy/train-set/poses9.npy

117 KB
Binary file not shown.

data/toy/val-set/poses0.npy

117 KB
Binary file not shown.

data/toy/val-set/poses1.npy

117 KB
Binary file not shown.

data/toy/val-set/poses10.npy

235 KB
Binary file not shown.

data/toy/val-set/poses11.npy

235 KB
Binary file not shown.

data/toy/val-set/poses12.npy

235 KB
Binary file not shown.

data/toy/val-set/poses13.npy

235 KB
Binary file not shown.

data/toy/val-set/poses14.npy

235 KB
Binary file not shown.

data/toy/val-set/poses15.npy

235 KB
Binary file not shown.

data/toy/val-set/poses16.npy

235 KB
Binary file not shown.

data/toy/val-set/poses17.npy

235 KB
Binary file not shown.

data/toy/val-set/poses18.npy

235 KB
Binary file not shown.

data/toy/val-set/poses19.npy

235 KB
Binary file not shown.

data/toy/val-set/poses2.npy

117 KB
Binary file not shown.

data/toy/val-set/poses3.npy

117 KB
Binary file not shown.

data/toy/val-set/poses4.npy

117 KB
Binary file not shown.

data/toy/val-set/poses5.npy

117 KB
Binary file not shown.

data/toy/val-set/poses6.npy

117 KB
Binary file not shown.

data/toy/val-set/poses7.npy

117 KB
Binary file not shown.

data/toy/val-set/poses8.npy

235 KB
Binary file not shown.

data/toy/val-set/poses9.npy

235 KB
Binary file not shown.

mp_transformer/config.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# might move this to a yaml or json
22
CONFIG = {
3-
"pose_dim": 3,
3+
"pose_dim": 6,
44
"num_attention_heads": 4,
55
"num_transformer_layers": 4,
66
# "latent_dim": 8,
@@ -39,8 +39,10 @@
3939
# "lr": 5e-4,
4040
"batch_size": 8,
4141
# "batch_size": 16,
42-
"N_train": 200000,
43-
"N_val": 40000,
42+
# "N_train": 200000,
43+
"N_train": 2,
44+
# "N_val": 40000,
45+
"N_val": 2,
4446
"sequence_length": 128,
4547
#"epochs": 295,
4648
"epochs": 230,

mp_transformer/datasets/toy_dataset.py

+13-20
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,23 @@
1414

1515
TOY_DATA_PATH = "data/toy/train-set"
1616

17-
global counter
18-
counter = 0
19-
2017

2118
def normalize_pose(pose):
22-
"""Radians to [0, 1]"""
23-
global counter
24-
# print('before')
25-
if not np.all(-np.pi <= pose) and np.all(pose <= np.pi):
26-
print(pose, end="\n")
27-
print(np.where(~(-np.pi <= pose)))
28-
print(np.where(~(pose <= np.pi)))
29-
counter += 1
30-
print(counter)
31-
pose = 0.5 + (pose / (2 * np.pi))
32-
# print('after')
33-
# print(pose)
34-
# assert np.all(0 <= pose) and np.all(pose <= 1)
19+
"""Transform [-1, 1] to [0, 1]"""
20+
print(pose)
21+
print(np.where(pose < -1))
22+
print(np.where(pose > 1))
23+
assert np.all(pose >= -1) and np.all(pose <= 1)
24+
pose = (pose + 1) / 2
25+
assert np.all(pose >= 0) and np.all(pose <= 1)
3526
return pose
3627

3728

3829
def unnormalize_pose(pose):
39-
"""[0, 1] to radians"""
40-
assert np.all(0 <= pose) and np.all(pose <= 1)
41-
pose = (pose - 0.5) * (2 * np.pi)
42-
assert np.all(-np.pi <= pose) and np.all(pose <= np.pi)
30+
"""Transform [0, 1] to [-1, 1]"""
31+
assert np.all(pose >= 0) and np.all(pose <= 1)
32+
pose = pose * 2 - 1
33+
assert np.all(pose >= -1) and np.all(pose <= 1)
4334
return pose
4435

4536

@@ -103,6 +94,7 @@ def __getitem__(self, idx):
10394

10495
def _get_single_item(self, idx):
10596
pose = self.poses[idx]
97+
# print(f"{idx=}")
10698
pose = normalize_pose(pose)
10799
pose = torch.tensor(pose).to(torch.float32)
108100
ret = {"pose": pose}
@@ -120,6 +112,7 @@ def _get_single_item(self, idx):
120112
return ret
121113

122114
def _get_segment(self, idx):
115+
print(f"{idx=}")
123116
images = []
124117
poses = []
125118
timestamps = []

mp_transformer/models/decoder.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,9 @@ def forward(self, timestamps, latent_primitives):
248248
recons_sequence = self.masked_average(
249249
recons_subseqs, repeated_transfo, gaussian_masks
250250
)
251-
print(f"{recons_sequence.max()=}")
252-
print(f"{recons_sequence.min()=}")
251+
if recons_sequence.min() < 0 or recons_sequence.max() > 1:
252+
print(f"{recons_sequence.max()=}")
253+
print(f"{recons_sequence.min()=}")
253254

254255
return {
255256
"recons_sequence": recons_sequence,

mp_transformer/models/encoder.py

+1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ def compute_primitive_features(self, poses, timestamps):
141141
torch.tensor: tensor of size BSxMxD of features with M the number of primitives
142142
"""
143143

144+
# breakpoint()
144145
# Get the batch size from the input data
145146
batch_size = poses.shape[0]
146147

mp_transformer/train.py

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def main(config, no_log=False, debug=False, checkpoint_path=None):
115115
log_every_n_steps=1,
116116
gpus=gpus,
117117
resume_from_checkpoint=checkpoint_path,
118+
num_sanity_val_steps=0,
118119
)
119120

120121
trainer.fit(

mp_transformer/utils/generate_toy_data.py

+2-111
Original file line numberDiff line numberDiff line change
@@ -23,78 +23,9 @@
2323
# return bone_lengths, key_marker_width
2424

2525

26-
# def generate_gaussian_process_poses(N, bone_lengths, train_or_val):
27-
# """Uses gaussian processes of two speeds to animate different parts of the limb."""
28-
29-
# print(f"Drawing {N} samples, might take a while...")
30-
31-
# if train_or_val == "train":
32-
# rbf = gaussian_process.kernels.RBF(length_scale=0.25)
33-
# rbf_slow = gaussian_process.kernels.RBF(length_scale=0.6)
34-
# elif train_or_val == "val":
35-
# rbf = gaussian_process.kernels.RBF(length_scale=0.15) # val-set
36-
# rbf_slow = gaussian_process.kernels.RBF(length_scale=0.55) # val-set
37-
# else:
38-
# raise ValueError(f"{train_or_val} must be 'train' or 'val' in Gaussian Process.")
39-
40-
# GP = gaussian_process.GaussianProcessRegressor(kernel=rbf)
41-
# GP_slow = gaussian_process.GaussianProcessRegressor(kernel=rbf_slow)
42-
43-
# t = np.linspace(0, 120, N)
44-
# # TODO: hardcode if I end up using only 3 joints
45-
# y = np.empty((N, len(bone_lengths)))
46-
47-
# y[:, 0] = 3 * GP_slow.sample_y(t[:, None], random_state=None)[:, 0]
48-
49-
# y_samples = 0.7 * GP.sample_y(t[:, None], n_samples=len(bone_lengths) - 1, random_state=None).T
50-
# y[:, 1:] = np.column_stack(y_samples)
51-
52-
# print("RAW")
53-
# print(f"y.min() = {y.min()}, y.max() = {y.max()}")
54-
55-
# # Wrap angles between -pi and pi
56-
# y = (y + np.pi) % (2 * np.pi) - np.pi
57-
# print("FIRT WRAP")
58-
# print(f"y.min() = {y.min()}, y.max() = {y.max()}")
59-
60-
# # Unwrap handles the case where the angle jumps from -pi to pi
61-
# y = np.unwrap(y, axis=0)
62-
# print("UNWRAP")
63-
# print(f"y.min() = {y.min()}, y.max() = {y.max()}")
64-
65-
66-
# # Wrap again since unwrapping can lead to values outside of [-pi, pi]
67-
# y = (y + np.pi) % (2 * np.pi) - np.pi
68-
# print("SECOND WRAP")
69-
# print(f"y.min() = {y.min()}, y.max() = {y.max()}")
70-
71-
# # Check for discontinuities
72-
# y_diff = np.diff(y, axis=0)
73-
# print("DIFF")
74-
# print(y_diff)
75-
# print(f"y_diff.min() = {y_diff.min()}, y_diff.max() = {y_diff.max()}")
76-
77-
# max_jump = np.pi
78-
# indices_of_jumps = np.where(np.abs(y_diff) > max_jump)
79-
# print(f"indices_of_jumps = {indices_of_jumps}")
80-
81-
# # if np.any(abs(y_diff) > max_jump):
82-
# # raise ValueError("Detected a discontinuity in the pose sequence.")
83-
84-
# window_size = 2 # Adjust as needed
85-
86-
# for idx in indices_of_jumps[0]:
87-
# print(f"Jump at index {idx} in column {indices_of_jumps[1][0]}:")
88-
# print(f"Values before: {y[idx-window_size:idx+1]}")
89-
# print(f"Values after: {y[idx+1:idx+window_size+1]}")
90-
# print(f"Difference causing the jump: {y_diff[idx]}")
91-
# print("---")
92-
93-
# return y
94-
95-
9626
def generate_gaussian_process_poses(N, bone_lengths, train_or_val):
97-
"""Uses gaussian processes of two speeds to animate different parts of the limb."""
27+
"""Uses gaussian processes of two speeds to animate different parts of the limb.
28+
To avoid discontinuities angles are represented as sin and cos."""
9829

9930
print(f"Drawing {N} samples, might take a while...")
10031

@@ -158,46 +89,6 @@ def generate_gaussian_process_poses(N, bone_lengths, train_or_val):
15889
return y
15990

16091

161-
# def forward(angles, bone_lenghts=BONE_LENGTHS):
162-
# """forward
163-
# Compute forward kinematics
164-
# angles --> cartesian coordinates
165-
166-
# :param angles:
167-
# List of angles for each bone_length in the hierarchy
168-
# relative to its parent bone_length
169-
# :param bone_lengths: List of bone_length lengths
170-
# """
171-
# bone_lengths = np.array(bone_lenghts)
172-
# if bone_lengths is None:
173-
# bone_lengths = np.ones_like(angles)
174-
# elif len(bone_lengths) == 2:
175-
# bone_lengths = bone_lengths * np.ones_like(angles)
176-
# else:
177-
# try:
178-
# assert len(angles) == len(bone_lengths)
179-
# # assert angles.shape == bone_lengths.shape
180-
# except AssertionError as excp:
181-
# raise Exception(
182-
# f"Number of angles and bone_lengths should be the same"
183-
# f" but: {len(angles)} is not {len(bone_lengths)}"
184-
# # f" but: {angles.shape} is not {bone_lengths.shape}"
185-
# ) from excp
186-
187-
# coordinates = [(0, 0)]
188-
# cumulative_angle = 0
189-
# for angle, bone_length in zip(angles, bone_lengths):
190-
# offs = coordinates[-1]
191-
# cumulative_angle += angle
192-
# coordinates += [
193-
# (
194-
# bone_length * np.cos(cumulative_angle) + offs[0],
195-
# bone_length * np.sin(cumulative_angle) + offs[1],
196-
# )
197-
# ]
198-
# return coordinates
199-
200-
20192
def forward(angles, bone_lengths=BONE_LENGTHS):
20293
"""
20394
Compute forward kinematics

0 commit comments

Comments
 (0)