Spaces:
Paused
Paused
Add code/cube3d/training/batch_process_ldrs.py
Browse files
code/cube3d/training/batch_process_ldrs.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import numpy as np
|
| 3 |
+
from process_single_ldr import process_ldr_data, process_ldr_flatten, process_ldr_flatten_bottom
|
| 4 |
+
import re
|
| 5 |
+
|
| 6 |
+
# 处理所有ldr文件
|
| 7 |
+
def process_all_ldr_in_folder(folder_path, output_folder):
|
| 8 |
+
all_data = []
|
| 9 |
+
all_label_inverse_mappings = [] # 存储所有文件的label_inverse_mapping
|
| 10 |
+
filenames = [] # 存储所有文件的文件名
|
| 11 |
+
|
| 12 |
+
line_count = 0
|
| 13 |
+
|
| 14 |
+
ldr_files = [f for f in os.listdir(input_folder) if
|
| 15 |
+
os.path.isfile(os.path.join(input_folder, f)) and
|
| 16 |
+
re.match(r'modified_car_\d+_车底_rot\.ldr', f)]
|
| 17 |
+
|
| 18 |
+
ldr_files.sort(key=lambda x: int(re.search(r'(\d+)', x).group(1)))
|
| 19 |
+
|
| 20 |
+
#import ipdb; ipdb.set_trace()
|
| 21 |
+
# 遍历文件夹中的所有文件夹
|
| 22 |
+
#for file in os.listdir(folder_path):
|
| 23 |
+
for idx, file in enumerate(ldr_files, 1):
|
| 24 |
+
# if file == 'modified_car_81_rot.ldr' or file == 'modified_car_1320_rot.ldr' or file == 'modified_car_1688_rot.ldr' :
|
| 25 |
+
# continue
|
| 26 |
+
if file.endswith('.ldr') and file.startswith('modified'): # 只处理ldr文件
|
| 27 |
+
file_path = os.path.join(folder_path, file)
|
| 28 |
+
|
| 29 |
+
with open(file_path, 'r') as f:
|
| 30 |
+
lines = f.readlines()
|
| 31 |
+
#if len(lines)>110:
|
| 32 |
+
#print(file, len(lines))
|
| 33 |
+
# #break
|
| 34 |
+
line_count += len(lines)
|
| 35 |
+
|
| 36 |
+
#data, _ = process_ldr_data(lines)
|
| 37 |
+
data, _ = process_ldr_flatten_bottom(lines)
|
| 38 |
+
if data.shape[0]>100:
|
| 39 |
+
# import ipdb; ipdb.set_trace()
|
| 40 |
+
print(file, idx)
|
| 41 |
+
|
| 42 |
+
print(file, data.shape[0])
|
| 43 |
+
|
| 44 |
+
#sort
|
| 45 |
+
sort_cols = data[:, [-4, -5, -3]]
|
| 46 |
+
sort_idx = np.lexsort((sort_cols[:, 2], sort_cols[:, 1], sort_cols[:, 0]))
|
| 47 |
+
data = data[sort_idx]
|
| 48 |
+
|
| 49 |
+
all_data.append(data)
|
| 50 |
+
filenames.append(file)
|
| 51 |
+
|
| 52 |
+
#print(f"Processed {file}")
|
| 53 |
+
|
| 54 |
+
print(f"Total lines processed: {line_count}") #1263
|
| 55 |
+
#import ipdb; ipdb.set_trace()
|
| 56 |
+
output_file = os.path.join(output_folder, "bottom_train.npz")
|
| 57 |
+
np.savez_compressed(output_file,
|
| 58 |
+
data=np.array(all_data, dtype=object), # 将所有数据以列表的形式存储
|
| 59 |
+
filenames=filenames) # 也可以保存文件名,方便后续查找
|
| 60 |
+
|
| 61 |
+
print(f"All LDR data have been processed and saved to {output_file}")
|
| 62 |
+
|
| 63 |
+
# 主程序
|
| 64 |
+
if __name__ == "__main__":
|
| 65 |
+
input_folder = '/public/home/wangshuo/gap/assembly/data/car_1k/subset_bottom_300/ldr_rot_expand_trans' # 输入文件夹路径
|
| 66 |
+
output_folder = '/public/home/wangshuo/gap/assembly/data/car_1k/subset_bottom_300' # 输出文件夹路径
|
| 67 |
+
|
| 68 |
+
os.makedirs(output_folder, exist_ok=True) # 确保输出文件夹存在
|
| 69 |
+
|
| 70 |
+
# 处理所有ldr文件并保存为npz文件
|
| 71 |
+
process_all_ldr_in_folder(input_folder, output_folder)
|