-
Notifications
You must be signed in to change notification settings - Fork 35
/
make_group.py
52 lines (42 loc) · 1.87 KB
/
make_group.py
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
#!/usr/bin/env python
# coding=utf-8
import os
import os.path as osp
import glob
import shutil
import random
import argparse
random.seed(2021)
parser = argparse.ArgumentParser()
parser.add_argument('--num_groups', default=30)
args = parser.parse_args()
num_groups = int(args.num_groups)
group_root = "groups"
if osp.exists(group_root):
shutil.rmtree(group_root)
os.makedirs(group_root, exist_ok=True)
materials = [name for name in os.listdir('.') if name != 'fbx' and name != group_root]
fbx_files = glob.glob("fbx/*.fbx")
fbx_files = [fbx_file for fbx_file in fbx_files if osp.exists(fbx_file.replace(".fbx", ".obj")) and osp.exists(fbx_file.replace(".fbx", ".txt"))]
random.shuffle(fbx_files)
group_len = len(fbx_files) // num_groups
print('assigning {} files into {} groups'.format(len(fbx_files), num_groups))
for i in range(num_groups):
start = group_len * i
end = group_len * (i+1)
group_dir = osp.join(group_root, 'group_' + str(i))
os.makedirs(group_dir, exist_ok=True)
# for material in materials:
# if osp.isdir(material):
# if osp.exists(osp.join(group_dir, material)):
# shutil.rmtree(osp.join(group_dir, material))
# shutil.copytree(material, osp.join(group_dir, material))
# else:
# shutil.copy(material, osp.join(group_dir, material))
# print('copy {} to {}'.format(material, osp.join(group_dir, material)))
group_fbx_dir = osp.join(group_dir, "fbx")
os.makedirs(group_fbx_dir, exist_ok=True)
for fbx_file in fbx_files[start:end]:
shutil.copy(fbx_file, osp.join(group_fbx_dir, osp.basename(fbx_file)))
shutil.copy(fbx_file.replace(".fbx", ".obj"), osp.join(group_fbx_dir, osp.basename(fbx_file).replace(".fbx", ".obj")))
shutil.copy(fbx_file.replace(".fbx", ".txt"), osp.join(group_fbx_dir, osp.basename(fbx_file).replace(".fbx", ".txt")))