Ligeng-Zhu commited on
Commit
6afd575
1 Parent(s): a38a6a5

Upload create_wds_tar.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. create_wds_tar.py +34 -0
create_wds_tar.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import tarfile
3
+ from math import ceil, floor
4
+
5
+ directory = "results_10M_val"
6
+
7
+ all_files = []
8
+ print(f"enumerating files {directory}")
9
+ for root, dirs, files in os.walk(directory):
10
+ for file in files:
11
+ file_path = os.path.join(root, file)
12
+ all_files.append(file_path)
13
+
14
+
15
+ all_files = sorted(all_files)
16
+
17
+ samples_per_tar = 1000
18
+ total = ceil(len(all_files) / samples_per_tar)
19
+
20
+ print(len(all_files))
21
+
22
+ output_tar = f"{directory}_{0}-of-{total}.tar"
23
+ tar = tarfile.open(output_tar, "w")
24
+ # for _idx in range(total):
25
+ for idx, f in enumerate(all_files):
26
+ print(output_tar, f"[{idx % samples_per_tar}/{samples_per_tar}]", f)
27
+ tar.add(f)
28
+ if (idx + 1) % samples_per_tar == 0:
29
+ tar.close()
30
+ output_tar = f"{directory}_{(idx + 1) // samples_per_tar}-of-{total}.tar"
31
+ tar = tarfile.open(output_tar, "w")
32
+ print("switch files")
33
+ # break
34
+ print("finish all")