Upload folder using huggingface_hub
Browse files- inference.py +13 -4
inference.py
CHANGED
|
@@ -27,9 +27,11 @@ def run_inference(model, cfg, transforms_dict, root_dir, split, scale, pc_tiling
|
|
| 27 |
data_las = read_gridnet_tile(
|
| 28 |
filepath, xyz=True, intensity=True, rgb=True, semantic=False, instance=False, remap=True
|
| 29 |
)
|
|
|
|
| 30 |
|
| 31 |
pos_list = []
|
| 32 |
pred_list = []
|
|
|
|
| 33 |
pos_offset_init = None
|
| 34 |
for x in range(2**pc_tiling):
|
| 35 |
data = SampleRecursiveMainXYAxisTiling(x=x, steps=pc_tiling)(data_las)
|
|
@@ -48,6 +50,7 @@ def run_inference(model, cfg, transforms_dict, root_dir, split, scale, pc_tiling
|
|
| 48 |
# For full resolution level
|
| 49 |
semantic_pred = output.full_res_semantic_pred(super_index_level0_to_level1=nag[0].super_index, sub_level0_to_raw=nag[0].sub)
|
| 50 |
pos_list.append(data.pos.cpu())
|
|
|
|
| 51 |
|
| 52 |
pred_list.append(semantic_pred.cpu())
|
| 53 |
|
|
@@ -57,6 +60,13 @@ def run_inference(model, cfg, transforms_dict, root_dir, split, scale, pc_tiling
|
|
| 57 |
merged_pos = torch.cat(pos_list, dim=0)
|
| 58 |
merged_pred = torch.cat(pred_list, dim=0)
|
| 59 |
merged_pos_offset = pos_offset_init + offset_initial_las
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
pos_data = (merged_pos.numpy() / scale).astype(int)
|
| 62 |
x, y, z = pos_data[:, 0], pos_data[:, 1], pos_data[:, 2]
|
|
@@ -148,6 +158,8 @@ def main():
|
|
| 148 |
parser.add_argument('--split', type=str, default='test', help="Data split to process (only used in inference mode) test or val split")
|
| 149 |
parser.add_argument('--weights', type=str, required=True, help="Path to model checkpoint")
|
| 150 |
parser.add_argument('--root_dir', type=str, required=True, help="Root directory of the dataset")
|
|
|
|
|
|
|
| 151 |
|
| 152 |
args = parser.parse_args()
|
| 153 |
cfg = init_config(overrides=["experiment=semantic/gridnet"])
|
|
@@ -158,15 +170,12 @@ def main():
|
|
| 158 |
model = model.eval().cuda()
|
| 159 |
|
| 160 |
SCALE = [0.001, 0.001, 0.001]
|
| 161 |
-
pc_tiling =
|
| 162 |
-
import time
|
| 163 |
-
start = time.time()
|
| 164 |
|
| 165 |
if args.mode == 'inference':
|
| 166 |
run_inference(model, cfg, transforms_dict, args.root_dir, args.split, SCALE, pc_tiling)
|
| 167 |
elif args.mode == 'export_log':
|
| 168 |
export_logits(model, cfg, transforms_dict, args.root_dir, SCALE, pc_tiling)
|
| 169 |
-
print(time.time()-start)
|
| 170 |
|
| 171 |
|
| 172 |
if __name__ == '__main__':
|
|
|
|
| 27 |
data_las = read_gridnet_tile(
|
| 28 |
filepath, xyz=True, intensity=True, rgb=True, semantic=False, instance=False, remap=True
|
| 29 |
)
|
| 30 |
+
data_las.initial_index = torch.arange(data_las.pos.shape[0]) # to keep initial order of points
|
| 31 |
|
| 32 |
pos_list = []
|
| 33 |
pred_list = []
|
| 34 |
+
indices_list = []
|
| 35 |
pos_offset_init = None
|
| 36 |
for x in range(2**pc_tiling):
|
| 37 |
data = SampleRecursiveMainXYAxisTiling(x=x, steps=pc_tiling)(data_las)
|
|
|
|
| 50 |
# For full resolution level
|
| 51 |
semantic_pred = output.full_res_semantic_pred(super_index_level0_to_level1=nag[0].super_index, sub_level0_to_raw=nag[0].sub)
|
| 52 |
pos_list.append(data.pos.cpu())
|
| 53 |
+
indices_list.append(data.initial_index.cpu())
|
| 54 |
|
| 55 |
pred_list.append(semantic_pred.cpu())
|
| 56 |
|
|
|
|
| 60 |
merged_pos = torch.cat(pos_list, dim=0)
|
| 61 |
merged_pred = torch.cat(pred_list, dim=0)
|
| 62 |
merged_pos_offset = pos_offset_init + offset_initial_las
|
| 63 |
+
|
| 64 |
+
# only for full res point cloud and keep initial order of points
|
| 65 |
+
merged_indices = torch.cat(indices_list, dim=0)
|
| 66 |
+
sorted_indices = torch.argsort(merged_indices)
|
| 67 |
+
merged_pos = merged_pos[sorted_indices]
|
| 68 |
+
merged_pred = merged_pred[sorted_indices]
|
| 69 |
+
|
| 70 |
|
| 71 |
pos_data = (merged_pos.numpy() / scale).astype(int)
|
| 72 |
x, y, z = pos_data[:, 0], pos_data[:, 1], pos_data[:, 2]
|
|
|
|
| 158 |
parser.add_argument('--split', type=str, default='test', help="Data split to process (only used in inference mode) test or val split")
|
| 159 |
parser.add_argument('--weights', type=str, required=True, help="Path to model checkpoint")
|
| 160 |
parser.add_argument('--root_dir', type=str, required=True, help="Root directory of the dataset")
|
| 161 |
+
parser.add_argument('--pc_tiling', type=str, default='3', help="PC tiling for point cloud sampling")
|
| 162 |
+
|
| 163 |
|
| 164 |
args = parser.parse_args()
|
| 165 |
cfg = init_config(overrides=["experiment=semantic/gridnet"])
|
|
|
|
| 170 |
model = model.eval().cuda()
|
| 171 |
|
| 172 |
SCALE = [0.001, 0.001, 0.001]
|
| 173 |
+
pc_tiling = int(args.pc_tiling)
|
|
|
|
|
|
|
| 174 |
|
| 175 |
if args.mode == 'inference':
|
| 176 |
run_inference(model, cfg, transforms_dict, args.root_dir, args.split, SCALE, pc_tiling)
|
| 177 |
elif args.mode == 'export_log':
|
| 178 |
export_logits(model, cfg, transforms_dict, args.root_dir, SCALE, pc_tiling)
|
|
|
|
| 179 |
|
| 180 |
|
| 181 |
if __name__ == '__main__':
|