MCPcopy Create free account
hub / github.com/TeleHuman/PBHC / eval_batch_traj

Function eval_batch_traj

humanoidverse/sample_eps.py:22–96  ·  view source on GitHub ↗
(saved_motion_dict, ref_motion_data_preblend, motion_len, tmp_path, robot_cfg_path)

Source from the content-addressed store, hash-verified

20
21
22def eval_batch_traj(saved_motion_dict, ref_motion_data_preblend, motion_len, tmp_path, robot_cfg_path):
23 from humanoidverse.measure_traj import get_appendix_motion_data,get_motionlib_data,blend_motion, eval_accuracy, eval_smoothness
24 # for each episode
25 # redump one motion to tmp file
26 # reload the motion
27 # follow the old code to compute the metrics
28 # aggregate the metrics
29
30 total_result = {
31 '_raw': [],
32 }
33
34 N,L = saved_motion_dict['dof'].shape[0], saved_motion_dict['dof'].shape[1]
35 keys_to_save = saved_motion_dict.keys()
36 assert L == motion_len, f"Motion length {L} does not match the expected length {motion_len}"
37
38
39 for i in range(N):
40 dump_data = {}
41
42 motion_key = f"motion{i}"
43 dump_data[motion_key] = {
44 key: saved_motion_dict[key][i] for key in keys_to_save
45 }
46 dump_data[motion_key]['fps'] = 50
47
48 joblib.dump(dump_data, tmp_path)
49
50
51 pol_appendix = get_appendix_motion_data(tmp_path)
52 pol_motion_data = get_motionlib_data(tmp_path, robot_cfg_path)
53
54 if i ==0:
55 ref_motion_data = blend_motion(ref_motion_data_preblend, pol_appendix['motion_times'])
56
57 # breakpoint()
58
59 traj_data = {
60 'pol': pol_motion_data,
61 'ref': ref_motion_data,
62 'appendix': pol_appendix,
63 }
64
65
66 metrics_accuracy:dict = toolz.dicttoolz.valmap(lambda x: x.item() * 1e3, eval_accuracy(traj_data,True))
67 metrics_smoothness:dict = toolz.dicttoolz.valmap(lambda x: x.item() * 1e3, eval_smoothness(traj_data,True))
68
69 result = {
70 'accuracy': metrics_accuracy,
71 'smoothness': metrics_smoothness,
72 }
73 total_result['_raw'].append(result)
74
75 # aggregate the metrics
76 aggr_accuracy = {}
77 aggr_smoothness = {}
78 for key in total_result['_raw'][0]['accuracy'].keys():
79 key_arr = np.array([total_result['_raw'][i]['accuracy'][key] for i in range(N)])

Callers 1

mainFunction · 0.70

Calls 6

get_appendix_motion_dataFunction · 0.90
get_motionlib_dataFunction · 0.90
blend_motionFunction · 0.90
eval_accuracyFunction · 0.90
eval_smoothnessFunction · 0.90
meanMethod · 0.45

Tested by

no test coverage detected