File size: 1,660 Bytes
bbde80b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import numpy as np
import os
import pickle

raw_dir = './data/AMASS/amass_202203/'
processed_dir = './data/AMASS/amass_fps60'
os.makedirs(processed_dir, exist_ok=True)

files = []
length = 0
target_fps = 60

def traverse(f):
    fs = os.listdir(f)
    for f1 in fs:
        tmp_path = os.path.join(f,f1)
        # file
        if not os.path.isdir(tmp_path):
            files.append(tmp_path)
        # dir
        else:
            traverse(tmp_path)

traverse(raw_dir)

print('files:', len(files))

fnames = []
all_motions = []

with open('data/AMASS/fps.csv', 'w') as f:
    print('fname_new, len_ori, fps, len_new', file=f)
    for fname in sorted(files):
        try:
            raw_x = np.load(fname)
            x = dict(raw_x)
            fps = x['mocap_framerate']
            len_ori = len(x['trans'])
            sample_stride = round(fps / target_fps)
            x['mocap_framerate'] = target_fps
            x['trans'] = x['trans'][::sample_stride]
            x['dmpls'] = x['dmpls'][::sample_stride]
            x['poses'] = x['poses'][::sample_stride]
            fname_new = '_'.join(fname.split('/')[2:])
            len_new = len(x['trans'])
            
            length += len_new
            print(fname_new, ',', len_ori, ',', fps, ',', len_new, file=f)
            fnames.append(fname_new)
            all_motions.append(x)
            np.savez('%s/%s' % (processed_dir, fname_new), x)
        except:
            pass
        
#         break

print('poseFrame:', length)
print('motions:', len(fnames))

with open("data/AMASS/all_motions_fps%d.pkl" % target_fps, "wb") as myprofile:  
    pickle.dump(all_motions, myprofile)