Spaces:
Paused
Paused
Add code/cube3d/training/process_ldrs.py
Browse files
code/cube3d/training/process_ldrs.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import numpy as np
|
| 3 |
+
from process_single_ldr import process_ldr_data # 导入处理单个ldr文件的函数
|
| 4 |
+
|
| 5 |
+
# 处理所有ldr文件
|
| 6 |
+
def process_all_ldr_in_folder(folder_path, output_folder):
|
| 7 |
+
all_data = []
|
| 8 |
+
all_label_inverse_mappings = [] # 存储所有文件的label_inverse_mapping
|
| 9 |
+
filenames = [] # 存储所有文件的文件名
|
| 10 |
+
|
| 11 |
+
line_count = 0
|
| 12 |
+
|
| 13 |
+
# 遍历文件夹中的所有文件夹
|
| 14 |
+
for root, dirs, files in os.walk(folder_path):
|
| 15 |
+
for file in files:
|
| 16 |
+
if file.endswith('.ldr') and file.startswith('modified'): # 只处理ldr文件
|
| 17 |
+
file_path = os.path.join(root, file)
|
| 18 |
+
|
| 19 |
+
with open(file_path, 'r') as f:
|
| 20 |
+
lines = f.readlines()
|
| 21 |
+
if len(lines)>=300:
|
| 22 |
+
print(f"Skipped {file} due to exceeding line limit.")
|
| 23 |
+
# break
|
| 24 |
+
line_count += len(lines)
|
| 25 |
+
data, _ = process_ldr_data(lines)
|
| 26 |
+
|
| 27 |
+
all_data.append(data)
|
| 28 |
+
filenames.append(file)
|
| 29 |
+
|
| 30 |
+
print(f"Processed {file}")
|
| 31 |
+
|
| 32 |
+
# import ipdb; ipdb.set_trace()
|
| 33 |
+
print(f"Total lines processed: {line_count}") #1263
|
| 34 |
+
#import ipdb; ipdb.set_trace()
|
| 35 |
+
output_file = os.path.join(output_folder, "all_ldr_data_300_ronehot24.npz")
|
| 36 |
+
np.savez_compressed(output_file,
|
| 37 |
+
data=np.array(all_data, dtype=object), # 将所有数据以列表的形式存储
|
| 38 |
+
filenames=filenames) # 也可以保存文件名,方便后续查找
|
| 39 |
+
|
| 40 |
+
print(f"All LDR data have been processed and saved to {output_file}")
|
| 41 |
+
|
| 42 |
+
# 主程序
|
| 43 |
+
if __name__ == "__main__":
|
| 44 |
+
input_folder = '/public/home/wangshuo/gap/assembly/data' # 输入文件夹路径
|
| 45 |
+
output_folder = '/public/home/wangshuo/gap/assembly/data/processed_data' # 输出文件夹路径
|
| 46 |
+
|
| 47 |
+
os.makedirs(output_folder, exist_ok=True) # 确保输出文件夹存在
|
| 48 |
+
|
| 49 |
+
# 处理所有ldr文件并保存为npz文件
|
| 50 |
+
process_all_ldr_in_folder(input_folder, output_folder)
|