ducido commited on
Commit
3386f52
·
verified ·
1 Parent(s): e023fe6

Upload create_scale.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. create_scale.py +43 -0
create_scale.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import os
3
+ import numpy as np
4
+ import math
5
+ import glob
6
+ import fire
7
+ import shutil
8
+
9
+ def main(scale_folder_name):
10
+ all_scale_dir = glob.glob(f'{scale_folder_name}/*')
11
+
12
+ for scale in all_scale_dir:
13
+ scale_percent = scale.split('/')[-1].split('_')[-1]
14
+ scale_percent = float(scale_percent)/100
15
+ print(scale_percent)
16
+ split_dir = glob.glob(scale + '/*')
17
+ for split in split_dir:
18
+ # modify file auto_lang_
19
+ auto_lang_ann_path = os.path.join(split, "lang_annotations/auto_lang_ann.npy")
20
+ auto_lang_ann = np.load(auto_lang_ann_path, allow_pickle=True).item()
21
+
22
+ lang_ann = auto_lang_ann['language']['ann']
23
+ lang_task = auto_lang_ann['language']['ann']
24
+ trajectories = auto_lang_ann['info']['indx']
25
+
26
+ length = len(lang_ann)
27
+ assert len(lang_ann) == len(lang_task) == len(trajectories) == length
28
+
29
+ auto_lang_ann['language']['ann'] = lang_ann[:math.ceil(length*scale_percent)]
30
+ auto_lang_ann['language']['task'] = lang_task[:math.ceil(length*scale_percent)]
31
+ auto_lang_ann['info']['indx'] = trajectories[:math.ceil(length*scale_percent)]
32
+
33
+ np.save(auto_lang_ann_path, auto_lang_ann)
34
+
35
+ # dummy .npz file to bypass lookup_naming_pattern
36
+ shutil.copy(
37
+ src= "calvin_debug_dataset/training/episode_0358484.npz",
38
+ dst= os.path.join(split)
39
+ )
40
+
41
+
42
+ if __name__ == '__main__':
43
+ fire.Fire(main)