|
| 1 | +import argparse |
| 2 | +import os |
| 3 | + |
| 4 | +import h5py |
| 5 | +import numpy as np |
| 6 | +import paddle |
| 7 | + |
| 8 | + |
| 9 | +def load_ds_trackA_info(file_path, key_list): |
| 10 | + path_trackA_ds = file_path |
| 11 | + key_list = np.sort([int(key) for key in key_list]) |
| 12 | + key_list = [str(key) for key in key_list] |
| 13 | + bounds = np.loadtxt(path_trackA_ds + "/watertight_global_bounds.txt") |
| 14 | + pressure_mean_std = paddle.to_tensor( |
| 15 | + data=np.loadtxt(path_trackA_ds + "/train_pressure_min_std.txt") |
| 16 | + ).to("float32") |
| 17 | + voxel_mean_std = paddle.to_tensor( |
| 18 | + data=np.loadtxt(path_trackA_ds + "/voxel_mean_std.txt") |
| 19 | + ).to("float32") |
| 20 | + pos_mean_std = np.loadtxt(path_trackA_ds + "/pos_mean_std.txt") |
| 21 | + normal_mean_std = np.loadtxt(path_trackA_ds + "/normal_mean_std.txt") |
| 22 | + PN_mean_std = paddle.to_tensor( |
| 23 | + data=np.concatenate([pos_mean_std, normal_mean_std], axis=-1) |
| 24 | + ).to("float32") |
| 25 | + physics_info = { |
| 26 | + "key_list": key_list, |
| 27 | + "bounds": bounds, |
| 28 | + "voxel_mean_std": voxel_mean_std, |
| 29 | + "pressure_mean_std": pressure_mean_std, |
| 30 | + "PN_mean_std": PN_mean_std, |
| 31 | + } |
| 32 | + return physics_info |
| 33 | + |
| 34 | + |
| 35 | +def load_ds_trackB_info(file_path, key_list): |
| 36 | + path_trackB_ds = file_path |
| 37 | + key_list = np.sort([int(key) for key in key_list]) |
| 38 | + key_list = [str(key) for key in key_list] |
| 39 | + pressure_mean_std = paddle.to_tensor( |
| 40 | + data=np.loadtxt(path_trackB_ds + "/train_pressure_mean_std.txt") |
| 41 | + ).to("float32") |
| 42 | + bounds = np.loadtxt(path_trackB_ds + "/global_bounds.txt") |
| 43 | + voxel_mean_std = paddle.to_tensor( |
| 44 | + data=np.loadtxt(path_trackB_ds + "/voxel_mean_std.txt") |
| 45 | + ).to("float32") |
| 46 | + PNA_mean_std = paddle.to_tensor( |
| 47 | + data=np.loadtxt(path_trackB_ds + "/PosNormalArea_mean_std.txt") |
| 48 | + ).to("float32") |
| 49 | + PN_mean_std = PNA_mean_std[:, :6] |
| 50 | + physics_info = { |
| 51 | + "key_list": key_list, |
| 52 | + "bounds": bounds, |
| 53 | + "voxel_mean_std": voxel_mean_std, |
| 54 | + "pressure_mean_std": pressure_mean_std, |
| 55 | + "PN_mean_std": PN_mean_std, |
| 56 | + } |
| 57 | + return physics_info |
| 58 | + |
| 59 | + |
| 60 | +def load_extra_info(file_path, key_list, track_type="A"): |
| 61 | + if track_type == "A": |
| 62 | + physics_info = load_ds_trackA_info(file_path, key_list) |
| 63 | + else: |
| 64 | + physics_info = load_ds_trackB_info(file_path, key_list) |
| 65 | + return physics_info |
| 66 | + |
| 67 | + |
| 68 | +def add_physics_info_to_group(group, physics_info): |
| 69 | + for key, value in physics_info.items(): |
| 70 | + group.create_dataset(key, data=value) |
| 71 | + |
| 72 | + |
| 73 | +def merge_h5_files(fileA_path, fileB_path, merged_file_path): |
| 74 | + with h5py.File(fileA_path, "r") as fileA, h5py.File( |
| 75 | + fileB_path, "r" |
| 76 | + ) as fileB, h5py.File(merged_file_path, "w") as merged_file: |
| 77 | + key_list_A = list(fileA.keys()) |
| 78 | + key_list_B = list(fileB.keys()) |
| 79 | + physics_info_A = load_extra_info( |
| 80 | + os.path.dirname(fileA_path), key_list_A, track_type="A" |
| 81 | + ) |
| 82 | + physics_info_B = load_extra_info( |
| 83 | + os.path.dirname(fileB_path), key_list_B, track_type="B" |
| 84 | + ) |
| 85 | + for key in fileA.keys(): |
| 86 | + group = fileA[key] |
| 87 | + new_key = "A_" + key |
| 88 | + merged_file.copy(group, new_key) |
| 89 | + add_physics_info_to_group(merged_file[new_key], physics_info_A) |
| 90 | + for key in fileB.keys(): |
| 91 | + group = fileB[key] |
| 92 | + new_key = "B_" + key |
| 93 | + merged_file.copy(group, new_key) |
| 94 | + add_physics_info_to_group(merged_file[new_key], physics_info_B) |
| 95 | + |
| 96 | + |
| 97 | +if __name__ == "__main__": |
| 98 | + parser = argparse.ArgumentParser( |
| 99 | + description="train / test a paddle model to predict frames" |
| 100 | + ) |
| 101 | + parser.add_argument( |
| 102 | + "--A_dir", |
| 103 | + default="/home/xiaoli/project/3D-ShapeNet-car/src/Dataset/converted_dataset/trackA/test.h5", |
| 104 | + type=str, |
| 105 | + help="", |
| 106 | + ) |
| 107 | + parser.add_argument( |
| 108 | + "--B_dir", |
| 109 | + default="/home/xiaoli/project/3D-ShapeNet-car/src/Dataset/converted_dataset/trackB/test.h5", |
| 110 | + type=str, |
| 111 | + help="", |
| 112 | + ) |
| 113 | + parser.add_argument( |
| 114 | + "--C_dir", |
| 115 | + default="/home/xiaoli/project/3D-ShapeNet-car/src/Dataset/converted_dataset/trackC/k1.h5", |
| 116 | + type=str, |
| 117 | + help="", |
| 118 | + ) |
| 119 | + params = parser.parse_args() |
| 120 | + merge_h5_files(params.A_dir, params.B_dir, params.C_dir) |
| 121 | +print("done") |
0 commit comments