syCen commited on
Commit
d3d4f01
·
verified ·
1 Parent(s): 04bf5e3

Upload copy_folders_from_data.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. copy_folders_from_data.py +41 -41
copy_folders_from_data.py CHANGED
@@ -1,43 +1,43 @@
1
- import os
2
  import json
 
3
  import shutil
4
-
5
-
6
- def copy_task_folders(json_path, src_root, dst_root):
7
- # load json
8
- with open(json_path, "r") as f:
9
- data = json.load(f)
10
-
11
- os.makedirs(dst_root, exist_ok=True)
12
-
13
- # collect unique task folders
14
- task_set = set()
15
- for item in data:
16
- task = item["id"].split("/")[0]
17
- task_set.add(task)
18
-
19
- print(f"Found {len(task_set)} unique task folders")
20
-
21
- # copy folders
22
- for task in task_set:
23
- src_path = os.path.join(src_root, task)
24
- dst_path = os.path.join(dst_root, task)
25
-
26
- if not os.path.exists(src_path):
27
- print(f"[WARNING] Missing: {src_path}")
28
- continue
29
-
30
- if os.path.exists(dst_path):
31
- print(f"[SKIP] Exists: {dst_path}")
32
- continue
33
-
34
- print(f"[COPY] {src_path} -> {dst_path}")
35
- shutil.copytree(src_path, dst_path)
36
-
37
-
38
- if __name__ == "__main__":
39
- json_path = "data.json" # path to your json
40
- src_root = "/net/holy-isilon/ifs/rc_labs/ydu_lab/sycen/data/rh20t/RH20T_cfg5"
41
- dst_root = "./scaling_dataset"
42
-
43
- copy_task_folders(json_path, src_root, dst_root)
 
 
1
  import json
2
+ import os
3
  import shutil
4
+ from tqdm import tqdm
5
+
6
+ JSON_PATH = "./egocamera/data.json"
7
+ SRC_ROOT = "/net/holy-isilon/ifs/rc_labs/ydu_lab/sycen/data/rh20t/RH20T_cfg5"
8
+ DST_ROOT = "./egocamera"
9
+
10
+ with open(JSON_PATH, "r") as f:
11
+ data = json.load(f)
12
+
13
+ copied = set() # 防止重复 copy
14
+
15
+ for item in tqdm(data):
16
+ # 解析路径
17
+ # id: task_xxx/.../cam_id/frame_id
18
+ parts = item["id"].split("/")
19
+ task_folder = parts[0]
20
+ cam_id = parts[1]
21
+
22
+ cam_folder = f"cam_{cam_id}"
23
+
24
+ src_path = os.path.join(SRC_ROOT, task_folder, cam_folder)
25
+ dst_path = os.path.join(DST_ROOT, task_folder, cam_folder)
26
+
27
+ key = (task_folder, cam_folder)
28
+
29
+ # 防止重复复制
30
+ if key in copied:
31
+ continue
32
+ copied.add(key)
33
+
34
+ if not os.path.exists(src_path):
35
+ print(f"❌ Missing: {src_path}")
36
+ continue
37
+
38
+ os.makedirs(os.path.dirname(dst_path), exist_ok=True)
39
+
40
+ print(f"Copying: {src_path} → {dst_path}")
41
+ shutil.copytree(src_path, dst_path, dirs_exist_ok=True)
42
+
43
+ print("✅ Done!")