hs1ang-hsu / BLAPose

Official implementation of "Enhancing 3D Human Pose Estimation with Bone Length Adjustment"
2 stars 0 forks source link

请问这个模型中的action_dict.pkl 以及prediction.pkl怎么生成的 #1

Open Duke-good opened 1 day ago

Duke-good commented 1 day ago

请问自己的训练模型如何生成这个action_dict.pkl 有和prediction.pkl文件

hs1ang-hsu commented 1 day ago

We generated action_dict.pkl and prediction.pkl by evaluating with other models. Take VideoPose3D as an example, we added a few lines to run.py.

At line 699, we collected the predicted_3d_pos by

predicted_3d_pos = predicted_3d_pos.cpu().numpy().reshape(-1, inputs_3d.shape[-2], inputs_3d.shape[-1]) 
output_prediction.append(predicted_3d_pos) 

After the evaluation is complete, we save output_prediction and all_actions, which is the evaluating order of subjects. At line 857, we added

run_evaluation(all_actions, action_filter) 
import pickle 
pickle.dump(output_prediction, open('prediction.pkl', 'wb')) 
pickle.dump(all_actions, open('action_dict.pkl', 'wb')) 
Duke-good commented 1 day ago

可以分享一下在STCformer中如何生成action_dict.pkl和prediction.pkl吗?谢谢大佬!

hs1ang-hsu commented 15 hours ago

We add a few lines in run_stc.py

We used a dictionary to save the results:

output_dict = {'S9': {}, 'S11': {}}

Since they did not provide the model with refine net, we just collect output_3D_single at line 69.

output_save = output_3D_single.clone().cpu().tolist() 
for i in range(len(output_save)): 
    if action[i] not in output_dict[subject[i]]: 
        output_dict[subject[i]][action[i]] = [] 
    output_dict[subject[i]][action[i]] += output_save[i] 

Then after the for loop (at line 105), we converted the dictionary to our format. I'm sorry for the unorganized code. It works great for me.

import pickle
acts = ['Directions', 'Discussion', 'Eating', 'Greeting', 'Phoning', 'Photo', 'Posing', 'Purchases', 'Sitting', 'SittingDown', 'Smoking', 'Waiting', 'WalkDog', 'Walking', 'WalkTogether']
output_prediction = []
all_actions = {}
for act in acts:
    all_actions[act] = []
    for sub in ['S9', 'S11']:
        for a in output_dict[sub].keys():
            if act == 'Sitting' and 'SittingDown' in a:
                continue
            if act in a:
                all_actions[act].append((sub, a))
                N = len(output_dict[sub][a])
                segment = int(N/4)
                for i in range(0, N, segment):
                    output_prediction.append(np.array(output_dict[sub][a][i:i+segment]))

pickle.dump(output_prediction, open('prediction.pkl', 'wb'))
pickle.dump(all_actions, open('action_dict.pkl', 'wb'))