Compare commits
22 Commits
a1226eb294
...
ab_global_
Author | SHA1 | Date | |
---|---|---|---|
1123e69bff | |||
5e8684d149 | |||
96fa40cc35 | |||
b82b92eebb | |||
2487039445 | |||
f533104e4a | |||
a21538c90a | |||
872405e239 | |||
b13e45bafc | |||
63a246c0c8 | |||
9e39c6c6c9 | |||
3c9e2c8d12 | |||
a883a31968 | |||
49bcf203a8 | |||
![]() |
1c443e533d | ||
![]() |
3b9c966fd9 | ||
![]() |
a41571e79c | ||
bd27226f0f | |||
5c56dae24f | |||
ebb1ab3c61 | |||
0f61e1d64d | |||
9ca0851bf7 |
@@ -5,5 +5,5 @@ from runners.data_spliter import DataSpliter
|
|||||||
class DataSplitApp:
|
class DataSplitApp:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def start():
|
def start():
|
||||||
DataSpliter("configs/server/split_dataset_config.yaml").run()
|
DataSpliter("configs/server/server_split_dataset_config.yaml").run()
|
||||||
|
|
@@ -12,18 +12,16 @@ runner:
|
|||||||
|
|
||||||
generate:
|
generate:
|
||||||
voxel_threshold: 0.003
|
voxel_threshold: 0.003
|
||||||
overlap_area_threshold: 25
|
overlap_area_threshold: 30
|
||||||
compute_with_normal: False
|
compute_with_normal: False
|
||||||
scan_points_threshold: 10
|
scan_points_threshold: 10
|
||||||
overwrite: False
|
overwrite: False
|
||||||
seq_num: 15
|
seq_num: 10
|
||||||
dataset_list:
|
dataset_list:
|
||||||
- OmniObject3d
|
- OmniObject3d
|
||||||
|
|
||||||
datasets:
|
datasets:
|
||||||
OmniObject3d:
|
OmniObject3d:
|
||||||
root_dir: C:\\Document\\Local Project\\nbv_rec\\nbv_reconstruction\\temp
|
root_dir: /data/hofee/nbv_rec_part2_preprocessed
|
||||||
from: 0
|
from: 155
|
||||||
to: 1 # -1 means end
|
to: 165 # ..-1 means end
|
||||||
|
|
||||||
|
|
||||||
|
@@ -84,7 +84,7 @@ module:
|
|||||||
gf_view_finder:
|
gf_view_finder:
|
||||||
t_feat_dim: 128
|
t_feat_dim: 128
|
||||||
pose_feat_dim: 256
|
pose_feat_dim: 256
|
||||||
main_feat_dim: 2048
|
main_feat_dim: 3072
|
||||||
regression_head: Rx_Ry_and_T
|
regression_head: Rx_Ry_and_T
|
||||||
pose_mode: rot_matrix
|
pose_mode: rot_matrix
|
||||||
per_point_feature: False
|
per_point_feature: False
|
||||||
|
22
configs/server/server_split_dataset_config.yaml
Normal file
22
configs/server/server_split_dataset_config.yaml
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
runner:
|
||||||
|
general:
|
||||||
|
seed: 0
|
||||||
|
device: cpu
|
||||||
|
cuda_visible_devices: "0,1,2,3,4,5,6,7"
|
||||||
|
|
||||||
|
experiment:
|
||||||
|
name: server_split_dataset
|
||||||
|
root_dir: "experiments"
|
||||||
|
|
||||||
|
split: #
|
||||||
|
root_dir: "/data/hofee/data/new_full_data"
|
||||||
|
type: "unseen_instance" # "unseen_category"
|
||||||
|
datasets:
|
||||||
|
OmniObject3d_train:
|
||||||
|
path: "/data/hofee/data/new_full_data_list/OmniObject3d_train.txt"
|
||||||
|
ratio: 0.9
|
||||||
|
|
||||||
|
OmniObject3d_test:
|
||||||
|
path: "/data/hofee/data/new_full_data_list/OmniObject3d_test.txt"
|
||||||
|
ratio: 0.1
|
@@ -7,13 +7,13 @@ runner:
|
|||||||
parallel: False
|
parallel: False
|
||||||
|
|
||||||
experiment:
|
experiment:
|
||||||
name: full_w_global_feat_wo_local_pts_feat
|
name: train_ab_global_and_partial_global
|
||||||
root_dir: "experiments"
|
root_dir: "experiments"
|
||||||
use_checkpoint: False
|
use_checkpoint: False
|
||||||
epoch: -1 # -1 stands for last epoch
|
epoch: -1 # -1 stands for last epoch
|
||||||
max_epochs: 5000
|
max_epochs: 5000
|
||||||
save_checkpoint_interval: 1
|
save_checkpoint_interval: 1
|
||||||
test_first: True
|
test_first: False
|
||||||
|
|
||||||
train:
|
train:
|
||||||
optimizer:
|
optimizer:
|
||||||
@@ -25,60 +25,60 @@ runner:
|
|||||||
test:
|
test:
|
||||||
frequency: 3 # test frequency
|
frequency: 3 # test frequency
|
||||||
dataset_list:
|
dataset_list:
|
||||||
- OmniObject3d_test
|
#- OmniObject3d_test
|
||||||
- OmniObject3d_val
|
- OmniObject3d_val
|
||||||
|
|
||||||
pipeline: nbv_reconstruction_global_pts_pipeline
|
pipeline: nbv_reconstruction_pipeline
|
||||||
|
|
||||||
dataset:
|
dataset:
|
||||||
OmniObject3d_train:
|
OmniObject3d_train:
|
||||||
root_dir: "/home/data/hofee/project/nbv_rec/data/nbv_rec_data_512_preproc_npy"
|
root_dir: "/data/hofee/data/new_full_data"
|
||||||
model_dir: "../data/scaled_object_meshes"
|
model_dir: "../data/scaled_object_meshes"
|
||||||
source: nbv_reconstruction_dataset
|
source: nbv_reconstruction_dataset
|
||||||
split_file: "/home/data/hofee/project/nbv_rec/data/OmniObject3d_train.txt"
|
split_file: "/data/hofee/data/new_full_data_list/OmniObject3d_train.txt"
|
||||||
type: train
|
type: train
|
||||||
cache: True
|
cache: True
|
||||||
ratio: 1
|
ratio: 1
|
||||||
batch_size: 160
|
batch_size: 80
|
||||||
num_workers: 16
|
num_workers: 128
|
||||||
pts_num: 4096
|
pts_num: 8192
|
||||||
load_from_preprocess: True
|
load_from_preprocess: True
|
||||||
|
|
||||||
OmniObject3d_test:
|
OmniObject3d_test:
|
||||||
root_dir: "/home/data/hofee/project/nbv_rec/data/nbv_rec_data_512_preproc_npy"
|
root_dir: "/data/hofee/data/new_full_data"
|
||||||
model_dir: "../data/scaled_object_meshes"
|
model_dir: "../data/scaled_object_meshes"
|
||||||
source: nbv_reconstruction_dataset
|
source: nbv_reconstruction_dataset
|
||||||
split_file: "/home/data/hofee/project/nbv_rec/data/OmniObject3d_test.txt"
|
split_file: "/data/hofee/data/new_full_data_list/OmniObject3d_test.txt"
|
||||||
type: test
|
type: test
|
||||||
cache: True
|
cache: True
|
||||||
filter_degree: 75
|
filter_degree: 75
|
||||||
eval_list:
|
eval_list:
|
||||||
- pose_diff
|
- pose_diff
|
||||||
ratio: 0.05
|
ratio: 1
|
||||||
batch_size: 160
|
batch_size: 80
|
||||||
num_workers: 12
|
num_workers: 12
|
||||||
pts_num: 4096
|
pts_num: 8192
|
||||||
load_from_preprocess: True
|
load_from_preprocess: True
|
||||||
|
|
||||||
OmniObject3d_val:
|
OmniObject3d_val:
|
||||||
root_dir: "/home/data/hofee/project/nbv_rec/data/nbv_rec_data_512_preproc_npy"
|
root_dir: "/data/hofee/data/new_full_data"
|
||||||
model_dir: "../data/scaled_object_meshes"
|
model_dir: "../data/scaled_object_meshes"
|
||||||
source: nbv_reconstruction_dataset
|
source: nbv_reconstruction_dataset
|
||||||
split_file: "/home/data/hofee/project/nbv_rec/data/OmniObject3d_train.txt"
|
split_file: "/data/hofee/data/new_full_data_list/OmniObject3d_train.txt"
|
||||||
type: test
|
type: test
|
||||||
cache: True
|
cache: True
|
||||||
filter_degree: 75
|
filter_degree: 75
|
||||||
eval_list:
|
eval_list:
|
||||||
- pose_diff
|
- pose_diff
|
||||||
ratio: 0.005
|
ratio: 0.1
|
||||||
batch_size: 160
|
batch_size: 80
|
||||||
num_workers: 12
|
num_workers: 12
|
||||||
pts_num: 4096
|
pts_num: 8192
|
||||||
load_from_preprocess: True
|
load_from_preprocess: True
|
||||||
|
|
||||||
|
|
||||||
pipeline:
|
pipeline:
|
||||||
nbv_reconstruction_local_pts_pipeline:
|
nbv_reconstruction_pipeline:
|
||||||
modules:
|
modules:
|
||||||
pts_encoder: pointnet_encoder
|
pts_encoder: pointnet_encoder
|
||||||
seq_encoder: transformer_seq_encoder
|
seq_encoder: transformer_seq_encoder
|
||||||
@@ -87,16 +87,6 @@ pipeline:
|
|||||||
eps: 1e-5
|
eps: 1e-5
|
||||||
global_scanned_feat: True
|
global_scanned_feat: True
|
||||||
|
|
||||||
nbv_reconstruction_global_pts_pipeline:
|
|
||||||
modules:
|
|
||||||
pts_encoder: pointnet_encoder
|
|
||||||
pose_seq_encoder: transformer_seq_encoder
|
|
||||||
pose_encoder: pose_encoder
|
|
||||||
view_finder: gf_view_finder
|
|
||||||
eps: 1e-5
|
|
||||||
global_scanned_feat: True
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module:
|
module:
|
||||||
|
|
||||||
@@ -107,11 +97,11 @@ module:
|
|||||||
feature_transform: False
|
feature_transform: False
|
||||||
|
|
||||||
transformer_seq_encoder:
|
transformer_seq_encoder:
|
||||||
embed_dim: 1344
|
embed_dim: 320
|
||||||
num_heads: 4
|
num_heads: 4
|
||||||
ffn_dim: 256
|
ffn_dim: 256
|
||||||
num_layers: 3
|
num_layers: 3
|
||||||
output_dim: 2048
|
output_dim: 1024
|
||||||
|
|
||||||
gf_view_finder:
|
gf_view_finder:
|
||||||
t_feat_dim: 128
|
t_feat_dim: 128
|
||||||
@@ -128,6 +118,9 @@ module:
|
|||||||
pose_dim: 9
|
pose_dim: 9
|
||||||
out_dim: 256
|
out_dim: 256
|
||||||
|
|
||||||
|
pts_num_encoder:
|
||||||
|
out_dim: 64
|
||||||
|
|
||||||
loss_function:
|
loss_function:
|
||||||
gf_loss:
|
gf_loss:
|
||||||
|
|
||||||
|
@@ -7,8 +7,9 @@ from PytorchBoot.utils.log_util import Log
|
|||||||
import torch
|
import torch
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
sys.path.append(r"/home/data/hofee/project/nbv_rec/nbv_reconstruction")
|
sys.path.append(r"/data/hofee/project/nbv_rec/nbv_reconstruction")
|
||||||
|
|
||||||
from utils.data_load import DataLoadUtil
|
from utils.data_load import DataLoadUtil
|
||||||
from utils.pose import PoseUtil
|
from utils.pose import PoseUtil
|
||||||
@@ -31,7 +32,7 @@ class NBVReconstructionDataset(BaseDataset):
|
|||||||
self.load_from_preprocess = config.get("load_from_preprocess", False)
|
self.load_from_preprocess = config.get("load_from_preprocess", False)
|
||||||
|
|
||||||
if self.type == namespace.Mode.TEST:
|
if self.type == namespace.Mode.TEST:
|
||||||
self.model_dir = config["model_dir"]
|
#self.model_dir = config["model_dir"]
|
||||||
self.filter_degree = config["filter_degree"]
|
self.filter_degree = config["filter_degree"]
|
||||||
if self.type == namespace.Mode.TRAIN:
|
if self.type == namespace.Mode.TRAIN:
|
||||||
scale_ratio = 1
|
scale_ratio = 1
|
||||||
@@ -66,7 +67,9 @@ class NBVReconstructionDataset(BaseDataset):
|
|||||||
if max_coverage_rate > scene_max_coverage_rate:
|
if max_coverage_rate > scene_max_coverage_rate:
|
||||||
scene_max_coverage_rate = max_coverage_rate
|
scene_max_coverage_rate = max_coverage_rate
|
||||||
max_coverage_rate_list.append(max_coverage_rate)
|
max_coverage_rate_list.append(max_coverage_rate)
|
||||||
mean_coverage_rate = np.mean(max_coverage_rate_list)
|
|
||||||
|
if max_coverage_rate_list:
|
||||||
|
mean_coverage_rate = np.mean(max_coverage_rate_list)
|
||||||
|
|
||||||
for seq_idx in range(seq_num):
|
for seq_idx in range(seq_num):
|
||||||
label_path = DataLoadUtil.get_label_path(
|
label_path = DataLoadUtil.get_label_path(
|
||||||
@@ -112,6 +115,15 @@ class NBVReconstructionDataset(BaseDataset):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
Log.error(f"Save cache failed: {e}")
|
Log.error(f"Save cache failed: {e}")
|
||||||
|
|
||||||
|
def voxel_downsample_with_mapping(self, point_cloud, voxel_size=0.003):
|
||||||
|
voxel_indices = np.floor(point_cloud / voxel_size).astype(np.int32)
|
||||||
|
unique_voxels, inverse, counts = np.unique(voxel_indices, axis=0, return_inverse=True, return_counts=True)
|
||||||
|
idx_sort = np.argsort(inverse)
|
||||||
|
idx_unique = idx_sort[np.cumsum(counts)-counts]
|
||||||
|
downsampled_points = point_cloud[idx_unique]
|
||||||
|
return downsampled_points, inverse
|
||||||
|
|
||||||
|
|
||||||
def __getitem__(self, index):
|
def __getitem__(self, index):
|
||||||
data_item_info = self.datalist[index]
|
data_item_info = self.datalist[index]
|
||||||
scanned_views = data_item_info["scanned_views"]
|
scanned_views = data_item_info["scanned_views"]
|
||||||
@@ -122,7 +134,10 @@ class NBVReconstructionDataset(BaseDataset):
|
|||||||
scanned_views_pts,
|
scanned_views_pts,
|
||||||
scanned_coverages_rate,
|
scanned_coverages_rate,
|
||||||
scanned_n_to_world_pose,
|
scanned_n_to_world_pose,
|
||||||
) = ([], [], [], [])
|
) = ([], [], [])
|
||||||
|
start_time = time.time()
|
||||||
|
start_indices = [0]
|
||||||
|
total_points = 0
|
||||||
for view in scanned_views:
|
for view in scanned_views:
|
||||||
frame_idx = view[0]
|
frame_idx = view[0]
|
||||||
coverage_rate = view[1]
|
coverage_rate = view[1]
|
||||||
@@ -144,8 +159,12 @@ class NBVReconstructionDataset(BaseDataset):
|
|||||||
n_to_world_trans = n_to_world_pose[:3, 3]
|
n_to_world_trans = n_to_world_pose[:3, 3]
|
||||||
n_to_world_9d = np.concatenate([n_to_world_6d, n_to_world_trans], axis=0)
|
n_to_world_9d = np.concatenate([n_to_world_6d, n_to_world_trans], axis=0)
|
||||||
scanned_n_to_world_pose.append(n_to_world_9d)
|
scanned_n_to_world_pose.append(n_to_world_9d)
|
||||||
|
total_points += len(downsampled_target_point_cloud)
|
||||||
|
start_indices.append(total_points)
|
||||||
|
|
||||||
|
|
||||||
|
end_time = time.time()
|
||||||
|
#Log.info(f"load data time: {end_time - start_time}")
|
||||||
nbv_idx, nbv_coverage_rate = nbv[0], nbv[1]
|
nbv_idx, nbv_coverage_rate = nbv[0], nbv[1]
|
||||||
nbv_path = DataLoadUtil.get_path(self.root_dir, scene_name, nbv_idx)
|
nbv_path = DataLoadUtil.get_path(self.root_dir, scene_name, nbv_idx)
|
||||||
cam_info = DataLoadUtil.load_cam_info(nbv_path)
|
cam_info = DataLoadUtil.load_cam_info(nbv_path)
|
||||||
@@ -158,29 +177,27 @@ class NBVReconstructionDataset(BaseDataset):
|
|||||||
best_to_world_9d = np.concatenate(
|
best_to_world_9d = np.concatenate(
|
||||||
[best_to_world_6d, best_to_world_trans], axis=0
|
[best_to_world_6d, best_to_world_trans], axis=0
|
||||||
)
|
)
|
||||||
|
|
||||||
combined_scanned_views_pts = np.concatenate(scanned_views_pts, axis=0)
|
combined_scanned_views_pts = np.concatenate(scanned_views_pts, axis=0)
|
||||||
fps_downsampled_combined_scanned_pts, fps_idx = PtsUtil.fps_downsample_point_cloud(
|
voxel_downsampled_combined_scanned_pts_np, inverse = self.voxel_downsample_with_mapping(combined_scanned_views_pts, 0.003)
|
||||||
combined_scanned_views_pts, self.pts_num, require_idx=True
|
random_downsampled_combined_scanned_pts_np, random_downsample_idx = PtsUtil.random_downsample_point_cloud(voxel_downsampled_combined_scanned_pts_np, self.pts_num, require_idx=True)
|
||||||
)
|
|
||||||
|
all_idx_unique = np.arange(len(voxel_downsampled_combined_scanned_pts_np))
|
||||||
combined_scanned_views_pts_mask = np.zeros(len(scanned_views_pts), dtype=np.uint8)
|
all_random_downsample_idx = all_idx_unique[random_downsample_idx]
|
||||||
|
scanned_pts_mask = []
|
||||||
start_idx = 0
|
for idx, start_idx in enumerate(start_indices):
|
||||||
for i in range(len(scanned_views_pts)):
|
if idx == len(start_indices) - 1:
|
||||||
end_idx = start_idx + len(scanned_views_pts[i])
|
break
|
||||||
combined_scanned_views_pts_mask[start_idx:end_idx] = i
|
end_idx = start_indices[idx+1]
|
||||||
start_idx = end_idx
|
view_inverse = inverse[start_idx:end_idx]
|
||||||
|
view_unique_downsampled_idx = np.unique(view_inverse)
|
||||||
fps_downsampled_combined_scanned_pts_mask = combined_scanned_views_pts_mask[fps_idx]
|
view_unique_downsampled_idx_set = set(view_unique_downsampled_idx)
|
||||||
|
mask = np.array([idx in view_unique_downsampled_idx_set for idx in all_random_downsample_idx])
|
||||||
|
scanned_pts_mask.append(mask)
|
||||||
|
|
||||||
|
|
||||||
data_item = {
|
data_item = {
|
||||||
"scanned_pts": np.asarray(scanned_views_pts, dtype=np.float32), # Ndarray(S x Nv x 3)
|
"scanned_pts": np.asarray(scanned_views_pts, dtype=np.float32), # Ndarray(S x Nv x 3)
|
||||||
"scanned_pts_mask": np.asarray(fps_downsampled_combined_scanned_pts_mask,dtype=np.uint8), # Ndarray(N), range(0, S)
|
"combined_scanned_pts": np.asarray(random_downsampled_combined_scanned_pts_np, dtype=np.float32), # Ndarray(N x 3)
|
||||||
"combined_scanned_pts": np.asarray(fps_downsampled_combined_scanned_pts, dtype=np.float32), # Ndarray(N x 3)
|
"scanned_pts_mask": np.asarray(scanned_pts_mask, dtype=np.bool), # Ndarray(N)
|
||||||
"scanned_coverage_rate": scanned_coverages_rate, # List(S): Float, range(0, 1)
|
"scanned_coverage_rate": scanned_coverages_rate, # List(S): Float, range(0, 1)
|
||||||
"scanned_n_to_world_pose_9d": np.asarray(scanned_n_to_world_pose, dtype=np.float32), # Ndarray(S x 9)
|
"scanned_n_to_world_pose_9d": np.asarray(scanned_n_to_world_pose, dtype=np.float32), # Ndarray(S x 9)
|
||||||
"best_coverage_rate": nbv_coverage_rate, # Float, range(0, 1)
|
"best_coverage_rate": nbv_coverage_rate, # Float, range(0, 1)
|
||||||
@@ -206,7 +223,9 @@ class NBVReconstructionDataset(BaseDataset):
|
|||||||
collate_data["scanned_n_to_world_pose_9d"] = [
|
collate_data["scanned_n_to_world_pose_9d"] = [
|
||||||
torch.tensor(item["scanned_n_to_world_pose_9d"]) for item in batch
|
torch.tensor(item["scanned_n_to_world_pose_9d"]) for item in batch
|
||||||
]
|
]
|
||||||
|
collate_data["scanned_pts_mask"] = [
|
||||||
|
torch.tensor(item["scanned_pts_mask"]) for item in batch
|
||||||
|
]
|
||||||
''' ------ Fixed Length ------ '''
|
''' ------ Fixed Length ------ '''
|
||||||
|
|
||||||
collate_data["best_to_world_pose_9d"] = torch.stack(
|
collate_data["best_to_world_pose_9d"] = torch.stack(
|
||||||
@@ -215,17 +234,14 @@ class NBVReconstructionDataset(BaseDataset):
|
|||||||
collate_data["combined_scanned_pts"] = torch.stack(
|
collate_data["combined_scanned_pts"] = torch.stack(
|
||||||
[torch.tensor(item["combined_scanned_pts"]) for item in batch]
|
[torch.tensor(item["combined_scanned_pts"]) for item in batch]
|
||||||
)
|
)
|
||||||
collate_data["scanned_pts_mask"] = torch.stack(
|
|
||||||
[torch.tensor(item["scanned_pts_mask"]) for item in batch]
|
|
||||||
)
|
|
||||||
|
|
||||||
for key in batch[0].keys():
|
for key in batch[0].keys():
|
||||||
if key not in [
|
if key not in [
|
||||||
"scanned_pts",
|
"scanned_pts",
|
||||||
"scanned_pts_mask",
|
|
||||||
"scanned_n_to_world_pose_9d",
|
"scanned_n_to_world_pose_9d",
|
||||||
"best_to_world_pose_9d",
|
"best_to_world_pose_9d",
|
||||||
"combined_scanned_pts",
|
"combined_scanned_pts",
|
||||||
|
"scanned_pts_mask",
|
||||||
]:
|
]:
|
||||||
collate_data[key] = [item[key] for item in batch]
|
collate_data[key] = [item[key] for item in batch]
|
||||||
return collate_data
|
return collate_data
|
||||||
@@ -241,10 +257,9 @@ if __name__ == "__main__":
|
|||||||
torch.manual_seed(seed)
|
torch.manual_seed(seed)
|
||||||
np.random.seed(seed)
|
np.random.seed(seed)
|
||||||
config = {
|
config = {
|
||||||
"root_dir": "/home/data/hofee/project/nbv_rec/data/nbv_rec_data_512_preproc_npy",
|
"root_dir": "/data/hofee/nbv_rec_part2_preprocessed",
|
||||||
"model_dir": "/home/data/hofee/project/nbv_rec/data/scaled_object_meshes",
|
|
||||||
"source": "nbv_reconstruction_dataset",
|
"source": "nbv_reconstruction_dataset",
|
||||||
"split_file": "/home/data/hofee/project/nbv_rec/data/OmniObject3d_test.txt",
|
"split_file": "/data/hofee/data/sample.txt",
|
||||||
"load_from_preprocess": True,
|
"load_from_preprocess": True,
|
||||||
"ratio": 0.5,
|
"ratio": 0.5,
|
||||||
"batch_size": 2,
|
"batch_size": 2,
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
import torch
|
import torch
|
||||||
|
import time
|
||||||
from torch import nn
|
from torch import nn
|
||||||
import PytorchBoot.namespace as namespace
|
import PytorchBoot.namespace as namespace
|
||||||
import PytorchBoot.stereotype as stereotype
|
import PytorchBoot.stereotype as stereotype
|
||||||
@@ -6,10 +7,10 @@ from PytorchBoot.factory.component_factory import ComponentFactory
|
|||||||
from PytorchBoot.utils import Log
|
from PytorchBoot.utils import Log
|
||||||
|
|
||||||
|
|
||||||
@stereotype.pipeline("nbv_reconstruction_global_pts_n_num_pipeline")
|
@stereotype.pipeline("nbv_reconstruction_pipeline")
|
||||||
class NBVReconstructionGlobalPointsPipeline(nn.Module):
|
class NBVReconstructionPipeline(nn.Module):
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
super(NBVReconstructionGlobalPointsPipeline, self).__init__()
|
super(NBVReconstructionPipeline, self).__init__()
|
||||||
self.config = config
|
self.config = config
|
||||||
self.module_config = config["modules"]
|
self.module_config = config["modules"]
|
||||||
|
|
||||||
@@ -19,12 +20,8 @@ class NBVReconstructionGlobalPointsPipeline(nn.Module):
|
|||||||
self.pose_encoder = ComponentFactory.create(
|
self.pose_encoder = ComponentFactory.create(
|
||||||
namespace.Stereotype.MODULE, self.module_config["pose_encoder"]
|
namespace.Stereotype.MODULE, self.module_config["pose_encoder"]
|
||||||
)
|
)
|
||||||
self.pts_num_encoder = ComponentFactory.create(
|
self.seq_encoder = ComponentFactory.create(
|
||||||
namespace.Stereotype.MODULE, self.module_config["pts_num_encoder"]
|
namespace.Stereotype.MODULE, self.module_config["seq_encoder"]
|
||||||
)
|
|
||||||
|
|
||||||
self.transformer_seq_encoder = ComponentFactory.create(
|
|
||||||
namespace.Stereotype.MODULE, self.module_config["transformer_seq_encoder"]
|
|
||||||
)
|
)
|
||||||
self.view_finder = ComponentFactory.create(
|
self.view_finder = ComponentFactory.create(
|
||||||
namespace.Stereotype.MODULE, self.module_config["view_finder"]
|
namespace.Stereotype.MODULE, self.module_config["view_finder"]
|
||||||
@@ -32,7 +29,6 @@ class NBVReconstructionGlobalPointsPipeline(nn.Module):
|
|||||||
|
|
||||||
|
|
||||||
self.eps = float(self.config["eps"])
|
self.eps = float(self.config["eps"])
|
||||||
self.enable_global_scanned_feat = self.config["global_scanned_feat"]
|
|
||||||
|
|
||||||
def forward(self, data):
|
def forward(self, data):
|
||||||
mode = data["mode"]
|
mode = data["mode"]
|
||||||
@@ -92,50 +88,50 @@ class NBVReconstructionGlobalPointsPipeline(nn.Module):
|
|||||||
scanned_n_to_world_pose_9d_batch = data[
|
scanned_n_to_world_pose_9d_batch = data[
|
||||||
"scanned_n_to_world_pose_9d"
|
"scanned_n_to_world_pose_9d"
|
||||||
] # List(B): Tensor(S x 9)
|
] # List(B): Tensor(S x 9)
|
||||||
scanned_pts_mask_batch = data[
|
|
||||||
"scanned_pts_mask"
|
scanned_pts_mask_batch = data["scanned_pts_mask"] # List(B): Tensor(N)
|
||||||
] # Tensor(B x N)
|
|
||||||
|
|
||||||
device = next(self.parameters()).device
|
device = next(self.parameters()).device
|
||||||
|
|
||||||
embedding_list_batch = []
|
embedding_list_batch = []
|
||||||
|
|
||||||
combined_scanned_pts_batch = data["combined_scanned_pts"] # Tensor(B x N x 3)
|
combined_scanned_pts_batch = data["combined_scanned_pts"] # Tensor(B x N x 3)
|
||||||
global_scanned_feat, perpoint_scanned_feat_batch = self.pts_encoder.encode_points(
|
global_scanned_feat, per_point_feat_batch = self.pts_encoder.encode_points(
|
||||||
combined_scanned_pts_batch, require_per_point_feat=True
|
combined_scanned_pts_batch, require_per_point_feat=True
|
||||||
) # global_scanned_feat: Tensor(B x Dg), perpoint_scanned_feat: Tensor(B x N x Dl)
|
) # global_scanned_feat: Tensor(B x Dg)
|
||||||
|
batch_size = len(scanned_n_to_world_pose_9d_batch)
|
||||||
for scanned_n_to_world_pose_9d, scanned_mask, perpoint_scanned_feat in zip(
|
for i in range(batch_size):
|
||||||
scanned_n_to_world_pose_9d_batch,
|
seq_len = len(scanned_n_to_world_pose_9d_batch[i])
|
||||||
scanned_pts_mask_batch,
|
scanned_n_to_world_pose_9d = scanned_n_to_world_pose_9d_batch[i].to(device) # Tensor(S x 9)
|
||||||
perpoint_scanned_feat_batch,
|
scanned_pts_mask = scanned_pts_mask_batch[i] # Tensor(S x N)
|
||||||
):
|
per_point_feat = per_point_feat_batch[i] # Tensor(N x Dp)
|
||||||
scanned_target_pts_num = [] # List(S): Int
|
partial_point_feat_seq = []
|
||||||
partial_feat_seq = []
|
for j in range(seq_len):
|
||||||
|
partial_per_point_feat = per_point_feat[scanned_pts_mask[j]]
|
||||||
|
if partial_per_point_feat.shape[0] == 0:
|
||||||
|
partial_point_feat = torch.zeros(per_point_feat.shape[1], device=device)
|
||||||
|
else:
|
||||||
|
partial_point_feat = torch.mean(partial_per_point_feat, dim=0) # Tensor(Dp)
|
||||||
|
partial_point_feat_seq.append(partial_point_feat)
|
||||||
|
partial_point_feat_seq = torch.stack(partial_point_feat_seq, dim=0) # Tensor(S x Dp)
|
||||||
|
|
||||||
seq_len = len(scanned_n_to_world_pose_9d)
|
pose_feat_seq = self.pose_encoder.encode_pose(scanned_n_to_world_pose_9d) # Tensor(S x Dp)
|
||||||
for seq_idx in range(seq_len):
|
|
||||||
partial_idx_in_combined_pts = scanned_mask == seq_idx # Ndarray(V), N->V idx mask
|
|
||||||
partial_perpoint_feat = perpoint_scanned_feat[partial_idx_in_combined_pts] # Ndarray(V x Dl)
|
|
||||||
partial_feat = torch.mean(partial_perpoint_feat, dim=0)[0] # Tensor(Dl)
|
|
||||||
partial_feat_seq.append(partial_feat)
|
|
||||||
scanned_target_pts_num.append(partial_perpoint_feat.shape[0])
|
|
||||||
|
|
||||||
scanned_target_pts_num = torch.tensor(scanned_target_pts_num, dtype=torch.int32).to(device) # Tensor(S)
|
|
||||||
scanned_n_to_world_pose_9d = scanned_n_to_world_pose_9d.to(device) # Tensor(S x 9)
|
|
||||||
|
|
||||||
pose_feat_seq = self.pose_encoder.encode_pose(scanned_n_to_world_pose_9d) # Tensor(S x Dp)
|
|
||||||
pts_num_feat_seq = self.pts_num_encoder.encode_pts_num(scanned_target_pts_num) # Tensor(S x Dn)
|
|
||||||
partial_feat_seq = torch.stack(partial_feat_seq) # Tensor(S x Dl)
|
|
||||||
|
|
||||||
seq_embedding = torch.cat([pose_feat_seq, pts_num_feat_seq, partial_feat_seq], dim=-1) # Tensor(S x (Dp+Dn+Dl))
|
|
||||||
embedding_list_batch.append(seq_embedding) # List(B): Tensor(S x (Dp+Dn+Dl))
|
|
||||||
|
|
||||||
seq_feat = self.transformer_seq_encoder.encode_sequence(embedding_list_batch) # Tensor(B x Ds)
|
|
||||||
|
|
||||||
|
seq_embedding = torch.cat([partial_point_feat_seq, pose_feat_seq], dim=-1)
|
||||||
|
|
||||||
|
embedding_list_batch.append(seq_embedding) # List(B): Tensor(S x (Dp))
|
||||||
|
|
||||||
|
seq_feat = self.seq_encoder.encode_sequence(embedding_list_batch) # Tensor(B x Ds)
|
||||||
main_feat = torch.cat([seq_feat, global_scanned_feat], dim=-1) # Tensor(B x (Ds+Dg))
|
main_feat = torch.cat([seq_feat, global_scanned_feat], dim=-1) # Tensor(B x (Ds+Dg))
|
||||||
|
|
||||||
if torch.isnan(main_feat).any():
|
if torch.isnan(main_feat).any():
|
||||||
|
for i in range(len(main_feat)):
|
||||||
|
if torch.isnan(main_feat[i]).any():
|
||||||
|
scanned_pts_mask = scanned_pts_mask_batch[i]
|
||||||
|
Log.info(f"scanned_pts_mask shape: {scanned_pts_mask.shape}")
|
||||||
|
Log.info(f"scanned_pts_mask sum: {scanned_pts_mask.sum()}")
|
||||||
|
import ipdb
|
||||||
|
ipdb.set_trace()
|
||||||
Log.error("nan in main_feat", True)
|
Log.error("nan in main_feat", True)
|
||||||
|
|
||||||
return main_feat
|
return main_feat
|
48
preprocess/pack_preprocessed_data.py
Normal file
48
preprocess/pack_preprocessed_data.py
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
def pack_scene_data(root, scene, output_dir):
|
||||||
|
scene_dir = os.path.join(output_dir, scene)
|
||||||
|
if not os.path.exists(scene_dir):
|
||||||
|
os.makedirs(scene_dir)
|
||||||
|
|
||||||
|
pts_dir = os.path.join(root, scene, "pts")
|
||||||
|
if os.path.exists(pts_dir):
|
||||||
|
shutil.move(pts_dir, os.path.join(scene_dir, "pts"))
|
||||||
|
|
||||||
|
scan_points_indices_dir = os.path.join(root, scene, "scan_points_indices")
|
||||||
|
if os.path.exists(scan_points_indices_dir):
|
||||||
|
shutil.move(scan_points_indices_dir, os.path.join(scene_dir, "scan_points_indices"))
|
||||||
|
|
||||||
|
scan_points_file = os.path.join(root, scene, "scan_points.txt")
|
||||||
|
if os.path.exists(scan_points_file):
|
||||||
|
shutil.move(scan_points_file, os.path.join(scene_dir, "scan_points.txt"))
|
||||||
|
|
||||||
|
model_pts_nrm_file = os.path.join(root, scene, "points_and_normals.txt")
|
||||||
|
if os.path.exists(model_pts_nrm_file):
|
||||||
|
shutil.move(model_pts_nrm_file, os.path.join(scene_dir, "points_and_normals.txt"))
|
||||||
|
|
||||||
|
camera_dir = os.path.join(root, scene, "camera_params")
|
||||||
|
if os.path.exists(camera_dir):
|
||||||
|
shutil.move(camera_dir, os.path.join(scene_dir, "camera_params"))
|
||||||
|
|
||||||
|
scene_info_file = os.path.join(root, scene, "scene_info.json")
|
||||||
|
if os.path.exists(scene_info_file):
|
||||||
|
shutil.move(scene_info_file, os.path.join(scene_dir, "scene_info.json"))
|
||||||
|
|
||||||
|
def pack_all_scenes(root, scene_list, output_dir):
|
||||||
|
for idx, scene in enumerate(scene_list):
|
||||||
|
print(f"正在打包场景 {scene} ({idx+1}/{len(scene_list)})")
|
||||||
|
pack_scene_data(root, scene, output_dir)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
root = r"H:\AI\Datasets\nbv_rec_part2"
|
||||||
|
output_dir = r"H:\AI\Datasets\scene_info_part2"
|
||||||
|
scene_list = os.listdir(root)
|
||||||
|
from_idx = 0
|
||||||
|
to_idx = len(scene_list)
|
||||||
|
print(f"正在打包场景 {scene_list[from_idx:to_idx]}")
|
||||||
|
|
||||||
|
pack_all_scenes(root, scene_list[from_idx:to_idx], output_dir)
|
||||||
|
print("打包完成")
|
||||||
|
|
41
preprocess/pack_upload_data.py
Normal file
41
preprocess/pack_upload_data.py
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
def pack_scene_data(root, scene, output_dir):
|
||||||
|
scene_dir = os.path.join(output_dir, scene)
|
||||||
|
if not os.path.exists(scene_dir):
|
||||||
|
os.makedirs(scene_dir)
|
||||||
|
|
||||||
|
pts_dir = os.path.join(root, scene, "pts")
|
||||||
|
if os.path.exists(pts_dir):
|
||||||
|
shutil.move(pts_dir, os.path.join(scene_dir, "pts"))
|
||||||
|
|
||||||
|
camera_dir = os.path.join(root, scene, "camera_params")
|
||||||
|
if os.path.exists(camera_dir):
|
||||||
|
shutil.move(camera_dir, os.path.join(scene_dir, "camera_params"))
|
||||||
|
|
||||||
|
scene_info_file = os.path.join(root, scene, "scene_info.json")
|
||||||
|
if os.path.exists(scene_info_file):
|
||||||
|
shutil.move(scene_info_file, os.path.join(scene_dir, "scene_info.json"))
|
||||||
|
|
||||||
|
label_dir = os.path.join(root, scene, "label")
|
||||||
|
if os.path.exists(label_dir):
|
||||||
|
shutil.move(label_dir, os.path.join(scene_dir, "label"))
|
||||||
|
|
||||||
|
|
||||||
|
def pack_all_scenes(root, scene_list, output_dir):
|
||||||
|
for idx, scene in enumerate(scene_list):
|
||||||
|
print(f"packing {scene} ({idx+1}/{len(scene_list)})")
|
||||||
|
pack_scene_data(root, scene, output_dir)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
root = r"H:\AI\Datasets\nbv_rec_part2"
|
||||||
|
output_dir = r"H:\AI\Datasets\upload_part2"
|
||||||
|
scene_list = os.listdir(root)
|
||||||
|
from_idx = 0
|
||||||
|
to_idx = len(scene_list)
|
||||||
|
print(f"packing {scene_list[from_idx:to_idx]}")
|
||||||
|
|
||||||
|
pack_all_scenes(root, scene_list[from_idx:to_idx], output_dir)
|
||||||
|
print("packing done")
|
||||||
|
|
@@ -164,10 +164,10 @@ def save_scene_data(root, scene, scene_idx=0, scene_total=1,file_type="txt"):
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
#root = "/media/hofee/repository/new_data_with_normal"
|
#root = "/media/hofee/repository/new_data_with_normal"
|
||||||
root = r"C:\Document\Datasets\nbv_rec_part2"
|
root = r"H:\AI\Datasets\nbv_rec_part2"
|
||||||
scene_list = os.listdir(root)
|
scene_list = os.listdir(root)
|
||||||
from_idx = 600 # 1000
|
from_idx = 0 # 1000
|
||||||
to_idx = len(scene_list) # 1500
|
to_idx = 600 # 1500
|
||||||
|
|
||||||
|
|
||||||
cnt = 0
|
cnt = 0
|
||||||
|
109
runners/inferece_server.py
Normal file
109
runners/inferece_server.py
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
import os
|
||||||
|
import json
|
||||||
|
import torch
|
||||||
|
import numpy as np
|
||||||
|
from flask import Flask, request, jsonify
|
||||||
|
|
||||||
|
import PytorchBoot.namespace as namespace
|
||||||
|
import PytorchBoot.stereotype as stereotype
|
||||||
|
from PytorchBoot.factory import ComponentFactory
|
||||||
|
|
||||||
|
from PytorchBoot.runners.runner import Runner
|
||||||
|
from PytorchBoot.utils import Log
|
||||||
|
|
||||||
|
from utils.pts import PtsUtil
|
||||||
|
|
||||||
|
@stereotype.runner("inferencer")
|
||||||
|
class InferencerServer(Runner):
|
||||||
|
def __init__(self, config_path):
|
||||||
|
super().__init__(config_path)
|
||||||
|
|
||||||
|
''' Web Server '''
|
||||||
|
self.app = Flask(__name__)
|
||||||
|
''' Pipeline '''
|
||||||
|
self.pipeline_name = self.config[namespace.Stereotype.PIPELINE]
|
||||||
|
self.pipeline:torch.nn.Module = ComponentFactory.create(namespace.Stereotype.PIPELINE, self.pipeline_name)
|
||||||
|
self.pipeline = self.pipeline.to(self.device)
|
||||||
|
|
||||||
|
''' Experiment '''
|
||||||
|
self.load_experiment("nbv_evaluator")
|
||||||
|
|
||||||
|
def get_input_data(self, data):
|
||||||
|
input_data = {}
|
||||||
|
scanned_pts = data["scanned_pts"]
|
||||||
|
scanned_n_to_world_pose_9d = data["scanned_n_to_world_pose_9d"]
|
||||||
|
combined_scanned_views_pts = np.concatenate(scanned_pts, axis=0)
|
||||||
|
fps_downsampled_combined_scanned_pts, fps_idx = PtsUtil.fps_downsample_point_cloud(
|
||||||
|
combined_scanned_views_pts, self.pts_num, require_idx=True
|
||||||
|
)
|
||||||
|
combined_scanned_views_pts_mask = np.zeros(len(scanned_pts), dtype=np.uint8)
|
||||||
|
start_idx = 0
|
||||||
|
for i in range(len(scanned_pts)):
|
||||||
|
end_idx = start_idx + len(scanned_pts[i])
|
||||||
|
combined_scanned_views_pts_mask[start_idx:end_idx] = i
|
||||||
|
start_idx = end_idx
|
||||||
|
|
||||||
|
fps_downsampled_combined_scanned_pts_mask = combined_scanned_views_pts_mask[fps_idx]
|
||||||
|
|
||||||
|
input_data["scanned_pts_mask"] = np.asarray(fps_downsampled_combined_scanned_pts_mask, dtype=np.uint8)
|
||||||
|
input_data["scanned_n_to_world_pose_9d"] = np.asarray(scanned_n_to_world_pose_9d, dtype=np.float32)
|
||||||
|
input_data["combined_scanned_pts"] = np.asarray(fps_downsampled_combined_scanned_pts, dtype=np.float32)
|
||||||
|
return input_data
|
||||||
|
|
||||||
|
def get_result(self, output_data):
|
||||||
|
|
||||||
|
estimated_delta_rot_9d = output_data["pred_pose_9d"]
|
||||||
|
result = {
|
||||||
|
"estimated_delta_rot_9d": estimated_delta_rot_9d.tolist()
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
Log.info("Loading from epoch {}.".format(self.current_epoch))
|
||||||
|
|
||||||
|
@self.app.route("/inference", methods=["POST"])
|
||||||
|
def inference():
|
||||||
|
data = request.json
|
||||||
|
input_data = self.get_input_data(data)
|
||||||
|
output_data = self.pipeline.forward_test(input_data)
|
||||||
|
result = self.get_result(output_data)
|
||||||
|
return jsonify(result)
|
||||||
|
|
||||||
|
|
||||||
|
self.app.run(host="0.0.0.0", port=5000)
|
||||||
|
|
||||||
|
def get_checkpoint_path(self, is_last=False):
|
||||||
|
return os.path.join(self.experiment_path, namespace.Direcotry.CHECKPOINT_DIR_NAME,
|
||||||
|
"Epoch_{}.pth".format(
|
||||||
|
self.current_epoch if self.current_epoch != -1 and not is_last else "last"))
|
||||||
|
|
||||||
|
def load_checkpoint(self, is_last=False):
|
||||||
|
self.load(self.get_checkpoint_path(is_last))
|
||||||
|
Log.success(f"Loaded checkpoint from {self.get_checkpoint_path(is_last)}")
|
||||||
|
if is_last:
|
||||||
|
checkpoint_root = os.path.join(self.experiment_path, namespace.Direcotry.CHECKPOINT_DIR_NAME)
|
||||||
|
meta_path = os.path.join(checkpoint_root, "meta.json")
|
||||||
|
if not os.path.exists(meta_path):
|
||||||
|
raise FileNotFoundError(
|
||||||
|
"No checkpoint meta.json file in the experiment {}".format(self.experiments_config["name"]))
|
||||||
|
file_path = os.path.join(checkpoint_root, "meta.json")
|
||||||
|
with open(file_path, "r") as f:
|
||||||
|
meta = json.load(f)
|
||||||
|
self.current_epoch = meta["last_epoch"]
|
||||||
|
self.current_iter = meta["last_iter"]
|
||||||
|
|
||||||
|
def load_experiment(self, backup_name=None):
|
||||||
|
super().load_experiment(backup_name)
|
||||||
|
self.current_epoch = self.experiments_config["epoch"]
|
||||||
|
self.load_checkpoint(is_last=(self.current_epoch == -1))
|
||||||
|
|
||||||
|
def create_experiment(self, backup_name=None):
|
||||||
|
super().create_experiment(backup_name)
|
||||||
|
|
||||||
|
|
||||||
|
def load(self, path):
|
||||||
|
state_dict = torch.load(path)
|
||||||
|
self.pipeline.load_state_dict(state_dict)
|
||||||
|
|
||||||
|
|
||||||
|
|
@@ -85,14 +85,16 @@ class StrategyGenerator(Runner):
|
|||||||
pts_path = os.path.join(root,scene_name, "pts", f"{frame_idx}.npy")
|
pts_path = os.path.join(root,scene_name, "pts", f"{frame_idx}.npy")
|
||||||
nrm_path = os.path.join(root,scene_name, "nrm", f"{frame_idx}.npy")
|
nrm_path = os.path.join(root,scene_name, "nrm", f"{frame_idx}.npy")
|
||||||
idx_path = os.path.join(root,scene_name, "scan_points_indices", f"{frame_idx}.npy")
|
idx_path = os.path.join(root,scene_name, "scan_points_indices", f"{frame_idx}.npy")
|
||||||
|
|
||||||
pts = np.load(pts_path)
|
pts = np.load(pts_path)
|
||||||
if pts.shape[0] == 0:
|
if self.compute_with_normal:
|
||||||
nrm = np.zeros((0,3))
|
if pts.shape[0] == 0:
|
||||||
else:
|
nrm = np.zeros((0,3))
|
||||||
nrm = np.load(nrm_path)
|
else:
|
||||||
indices = np.load(idx_path)
|
nrm = np.load(nrm_path)
|
||||||
|
nrm_list.append(nrm)
|
||||||
pts_list.append(pts)
|
pts_list.append(pts)
|
||||||
nrm_list.append(nrm)
|
indices = np.load(idx_path)
|
||||||
scan_points_indices_list.append(indices)
|
scan_points_indices_list.append(indices)
|
||||||
if pts.shape[0] > 0:
|
if pts.shape[0] > 0:
|
||||||
non_zero_cnt += 1
|
non_zero_cnt += 1
|
||||||
|
@@ -53,6 +53,8 @@ class DataLoadUtil:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def get_label_num(root, scene_name):
|
def get_label_num(root, scene_name):
|
||||||
label_dir = os.path.join(root, scene_name, "label")
|
label_dir = os.path.join(root, scene_name, "label")
|
||||||
|
if not os.path.exists(label_dir):
|
||||||
|
return 0
|
||||||
return len(os.listdir(label_dir))
|
return len(os.listdir(label_dir))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -210,6 +212,17 @@ class DataLoadUtil:
|
|||||||
else:
|
else:
|
||||||
pts = np.load(npy_path)
|
pts = np.load(npy_path)
|
||||||
return pts
|
return pts
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def load_from_preprocessed_nrm(path, file_type="npy"):
|
||||||
|
npy_path = os.path.join(
|
||||||
|
os.path.dirname(path), "nrm", os.path.basename(path) + "." + file_type
|
||||||
|
)
|
||||||
|
if file_type == "txt":
|
||||||
|
nrm = np.loadtxt(npy_path)
|
||||||
|
else:
|
||||||
|
nrm = np.load(npy_path)
|
||||||
|
return nrm
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def cam_pose_transformation(cam_pose_before):
|
def cam_pose_transformation(cam_pose_before):
|
||||||
|
30
utils/pts.py
30
utils/pts.py
@@ -14,16 +14,38 @@ class PtsUtil:
|
|||||||
downsampled_points = point_cloud[idx_unique]
|
downsampled_points = point_cloud[idx_unique]
|
||||||
return downsampled_points, idx_unique
|
return downsampled_points, idx_unique
|
||||||
else:
|
else:
|
||||||
unique_voxels = np.unique(voxel_indices, axis=0, return_inverse=True)
|
import ipdb; ipdb.set_trace()
|
||||||
return unique_voxels[0]*voxel_size
|
unique_voxels = np.unique(voxel_indices, axis=0, return_inverse=False)
|
||||||
|
return unique_voxels*voxel_size
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def voxel_downsample_point_cloud_o3d(point_cloud, voxel_size=0.005):
|
||||||
|
pcd = o3d.geometry.PointCloud()
|
||||||
|
pcd.points = o3d.utility.Vector3dVector(point_cloud)
|
||||||
|
pcd = pcd.voxel_down_sample(voxel_size)
|
||||||
|
return np.asarray(pcd.points)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def random_downsample_point_cloud(point_cloud, num_points, require_idx=False):
|
def voxel_downsample_point_cloud_and_trace_o3d(point_cloud, voxel_size=0.005):
|
||||||
|
pcd = o3d.geometry.PointCloud()
|
||||||
|
pcd.points = o3d.utility.Vector3dVector(point_cloud)
|
||||||
|
max_bound = pcd.get_max_bound()
|
||||||
|
min_bound = pcd.get_min_bound()
|
||||||
|
pcd = pcd.voxel_down_sample_and_trace(voxel_size, max_bound, min_bound, True)
|
||||||
|
|
||||||
|
return np.asarray(pcd.points)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def random_downsample_point_cloud(point_cloud, num_points, require_idx=False, replace=True):
|
||||||
if point_cloud.shape[0] == 0:
|
if point_cloud.shape[0] == 0:
|
||||||
if require_idx:
|
if require_idx:
|
||||||
return point_cloud, np.array([])
|
return point_cloud, np.array([])
|
||||||
return point_cloud
|
return point_cloud
|
||||||
idx = np.random.choice(len(point_cloud), num_points, replace=True)
|
if not replace and num_points > len(point_cloud):
|
||||||
|
if require_idx:
|
||||||
|
return point_cloud, np.arange(len(point_cloud))
|
||||||
|
return point_cloud
|
||||||
|
idx = np.random.choice(len(point_cloud), num_points, replace=replace)
|
||||||
if require_idx:
|
if require_idx:
|
||||||
return point_cloud[idx], idx
|
return point_cloud[idx], idx
|
||||||
return point_cloud[idx]
|
return point_cloud[idx]
|
||||||
|
@@ -62,7 +62,7 @@ class ReconstructionUtil:
|
|||||||
|
|
||||||
max_rec_pts = np.vstack(point_cloud_list)
|
max_rec_pts = np.vstack(point_cloud_list)
|
||||||
downsampled_max_rec_pts = PtsUtil.voxel_downsample_point_cloud(max_rec_pts, threshold)
|
downsampled_max_rec_pts = PtsUtil.voxel_downsample_point_cloud(max_rec_pts, threshold)
|
||||||
|
combined_point_cloud = PtsUtil.voxel_downsample_point_cloud(combined_point_cloud, threshold)
|
||||||
max_rec_pts_num = downsampled_max_rec_pts.shape[0]
|
max_rec_pts_num = downsampled_max_rec_pts.shape[0]
|
||||||
max_real_rec_pts_coverage, _ = ReconstructionUtil.compute_coverage_rate(target_point_cloud, downsampled_max_rec_pts, threshold)
|
max_real_rec_pts_coverage, _ = ReconstructionUtil.compute_coverage_rate(target_point_cloud, downsampled_max_rec_pts, threshold)
|
||||||
|
|
||||||
@@ -75,6 +75,7 @@ class ReconstructionUtil:
|
|||||||
cnt_processed_view = 0
|
cnt_processed_view = 0
|
||||||
remaining_views.remove(init_view)
|
remaining_views.remove(init_view)
|
||||||
curr_rec_pts_num = combined_point_cloud.shape[0]
|
curr_rec_pts_num = combined_point_cloud.shape[0]
|
||||||
|
drop_output_ratio = 0.4
|
||||||
|
|
||||||
import time
|
import time
|
||||||
while remaining_views:
|
while remaining_views:
|
||||||
@@ -84,6 +85,8 @@ class ReconstructionUtil:
|
|||||||
best_covered_num = 0
|
best_covered_num = 0
|
||||||
|
|
||||||
for view_index in remaining_views:
|
for view_index in remaining_views:
|
||||||
|
if np.random.rand() < drop_output_ratio:
|
||||||
|
continue
|
||||||
if point_cloud_list[view_index].shape[0] == 0:
|
if point_cloud_list[view_index].shape[0] == 0:
|
||||||
continue
|
continue
|
||||||
if selected_views:
|
if selected_views:
|
||||||
|
27
utils/vis.py
27
utils/vis.py
@@ -158,18 +158,23 @@ class visualizeUtil:
|
|||||||
np.savetxt(os.path.join(output_dir, "target_normal.txt"), sampled_visualized_normal)
|
np.savetxt(os.path.join(output_dir, "target_normal.txt"), sampled_visualized_normal)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def save_pts_nrm(pts_nrm, output_dir):
|
def save_pts_nrm(root, scene, frame_idx, output_dir, binocular=False):
|
||||||
pts = pts_nrm[:, :3]
|
path = DataLoadUtil.get_path(root, scene, frame_idx)
|
||||||
nrm = pts_nrm[:, 3:]
|
pts_world = DataLoadUtil.load_from_preprocessed_pts(path, "npy")
|
||||||
|
nrm_camera = DataLoadUtil.load_from_preprocessed_nrm(path, "npy")
|
||||||
|
cam_info = DataLoadUtil.load_cam_info(path, binocular=binocular)
|
||||||
|
cam_to_world = cam_info["cam_to_world"]
|
||||||
|
nrm_world = nrm_camera @ cam_to_world[:3, :3].T
|
||||||
visualized_nrm = []
|
visualized_nrm = []
|
||||||
num_samples = 10
|
num_samples = 10
|
||||||
for i in range(len(pts)):
|
for i in range(len(pts_world)):
|
||||||
visualized_nrm.append(pts[i] + 0.02*t * nrm[i] for t in range(num_samples))
|
for t in range(num_samples):
|
||||||
visualized_nrm = np.array(visualized_nrm).reshape(-1, 3)
|
visualized_nrm.append(pts_world[i] - 0.02 * t * nrm_world[i])
|
||||||
|
|
||||||
|
visualized_nrm = np.array(visualized_nrm)
|
||||||
np.savetxt(os.path.join(output_dir, "nrm.txt"), visualized_nrm)
|
np.savetxt(os.path.join(output_dir, "nrm.txt"), visualized_nrm)
|
||||||
np.savetxt(os.path.join(output_dir, "pts.txt"), pts)
|
np.savetxt(os.path.join(output_dir, "pts.txt"), pts_world)
|
||||||
|
|
||||||
|
|
||||||
# ------ Debug ------
|
# ------ Debug ------
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@@ -184,6 +189,4 @@ if __name__ == "__main__":
|
|||||||
# visualizeUtil.save_seq_cam_pos_and_cam_axis(root, scene, [0, 121, 286, 175, 111,366,45,230,232,225,255,17,199,78,60], output_dir)
|
# visualizeUtil.save_seq_cam_pos_and_cam_axis(root, scene, [0, 121, 286, 175, 111,366,45,230,232,225,255,17,199,78,60], output_dir)
|
||||||
# visualizeUtil.save_target_mesh_at_world_space(root, model_dir, scene)
|
# visualizeUtil.save_target_mesh_at_world_space(root, model_dir, scene)
|
||||||
#visualizeUtil.save_points_and_normals(root, scene,"10", output_dir, binocular=True)
|
#visualizeUtil.save_points_and_normals(root, scene,"10", output_dir, binocular=True)
|
||||||
pts_nrm = np.loadtxt(r"C:\Document\Local Project\nbv_rec\nbv_reconstruction\pts_nrm_target.txt")
|
visualizeUtil.save_pts_nrm(root, scene, "116", output_dir, binocular=True)
|
||||||
visualizeUtil.save_pts_nrm(pts_nrm, output_dir)
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user