Compare commits

...

4 Commits

Author SHA1 Message Date
fca984e76b Merge branch 'ab_global_only' of http://git.hofee.top/hofee/nbv_reconstruction into ab_global_only 2025-01-05 23:57:43 +08:00
dec67e8255 upd inference 2025-01-05 23:57:33 +08:00
9c2625b11e upd 2024-12-31 02:52:46 +08:00
2dfb6c57ce upd 2024-12-31 02:51:42 +08:00
10 changed files with 117 additions and 77 deletions

View File

@ -6,16 +6,16 @@ runner:
cuda_visible_devices: "0,1,2,3,4,5,6,7" cuda_visible_devices: "0,1,2,3,4,5,6,7"
experiment: experiment:
name: train_ab_global_only name: train_ab_global_only_p++_wp
root_dir: "experiments" root_dir: "experiments"
epoch: -1 # -1 stands for last epoch epoch: 922 # -1 stands for last epoch
test: test:
dataset_list: dataset_list:
- OmniObject3d_test - OmniObject3d_test
blender_script_path: "/media/hofee/data/project/python/nbv_reconstruction/blender/data_renderer.py" blender_script_path: "/media/hofee/data/project/python/nbv_reconstruction/blender/data_renderer.py"
output_dir: "/media/hofee/data/results/nbv_rec_inference/global_only_ycb_241204" output_dir: "/media/hofee/data/data/p++_wp_temp_cluster"
pipeline: nbv_reconstruction_pipeline pipeline: nbv_reconstruction_pipeline
voxel_size: 0.003 voxel_size: 0.003
min_new_area: 1.0 min_new_area: 1.0
@ -34,8 +34,8 @@ dataset:
# load_from_preprocess: True # load_from_preprocess: True
OmniObject3d_test: OmniObject3d_test:
root_dir: "/media/hofee/data/results/ycb_preprocessed_dataset" root_dir: "/media/hofee/data/data/new_testset_output"
model_dir: "/media/hofee/data/data/ycb_obj" model_dir: "/media/hofee/data/data/scaled_object_meshes"
source: seq_reconstruction_dataset_preprocessed source: seq_reconstruction_dataset_preprocessed
# split_file: "C:\\Document\\Datasets\\data_list\\OmniObject3d_test.txt" # split_file: "C:\\Document\\Datasets\\data_list\\OmniObject3d_test.txt"
type: test type: test
@ -52,7 +52,7 @@ dataset:
pipeline: pipeline:
nbv_reconstruction_pipeline: nbv_reconstruction_pipeline:
modules: modules:
pts_encoder: pointnet_encoder pts_encoder: pointnet++_encoder
seq_encoder: transformer_seq_encoder seq_encoder: transformer_seq_encoder
pose_encoder: pose_encoder pose_encoder: pose_encoder
view_finder: gf_view_finder view_finder: gf_view_finder
@ -60,6 +60,9 @@ pipeline:
global_scanned_feat: True global_scanned_feat: True
module: module:
pointnet++_encoder:
in_dim: 3
pointnet_encoder: pointnet_encoder:
in_dim: 3 in_dim: 3
out_dim: 1024 out_dim: 1024

View File

@ -22,6 +22,6 @@ runner:
datasets: datasets:
OmniObject3d: OmniObject3d:
root_dir: /media/hofee/data/results/ycb_view_data root_dir: /media/hofee/data/data/test_bottle/view
from: 0 from: 0
to: -1 # ..-1 means end to: -1 # ..-1 means end

View File

@ -8,11 +8,11 @@ runner:
root_dir: experiments root_dir: experiments
generate: generate:
port: 5002 port: 5002
from: 1 from: 0
to: 50 # -1 means all to: 50 # -1 means all
object_dir: /media/hofee/data/data/ycb_obj object_dir: /media/hofee/data/data/test_bottle/bottle_mesh
table_model_path: /media/hofee/data/data/others/table.obj table_model_path: /media/hofee/data/data/others/table.obj
output_dir: /media/hofee/data/results/ycb_view_data output_dir: /media/hofee/data/data/test_bottle/view
binocular_vision: true binocular_vision: true
plane_size: 10 plane_size: 10
max_views: 512 max_views: 512
@ -34,7 +34,7 @@ runner:
max_y: 0.05 max_y: 0.05
min_z: 0.01 min_z: 0.01
max_z: 0.01 max_z: 0.01
random_rotation_ratio: 0.3 random_rotation_ratio: 0.0
random_objects: random_objects:
num: 4 num: 4
cluster: 0.9 cluster: 0.9

View File

@ -75,6 +75,8 @@ class NBVReconstructionPipeline(nn.Module):
def forward_test(self, data): def forward_test(self, data):
main_feat = self.get_main_feat(data) main_feat = self.get_main_feat(data)
repeat_num = data.get("repeat_num", 100)
main_feat = main_feat.repeat(repeat_num, 1)
estimated_delta_rot_9d, in_process_sample = self.view_finder.next_best_view( estimated_delta_rot_9d, in_process_sample = self.view_finder.next_best_view(
main_feat main_feat
) )

View File

@ -64,11 +64,15 @@ class SeqReconstructionDataset(BaseDataset):
scene_max_cr_idx = 0 scene_max_cr_idx = 0
frame_len = DataLoadUtil.get_scene_seq_length(self.root_dir, scene_name) frame_len = DataLoadUtil.get_scene_seq_length(self.root_dir, scene_name)
for i in range(frame_len): for i in range(10,frame_len):
path = DataLoadUtil.get_path(self.root_dir, scene_name, i) path = DataLoadUtil.get_path(self.root_dir, scene_name, i)
pts = DataLoadUtil.load_from_preprocessed_pts(path, "npy") pts = DataLoadUtil.load_from_preprocessed_pts(path, "npy")
print(pts.shape)
if pts.shape[0] == 0: if pts.shape[0] == 0:
continue continue
else:
break
print(i)
datalist.append({ datalist.append({
"scene_name": scene_name, "scene_name": scene_name,
"first_frame": i, "first_frame": i,
@ -180,9 +184,9 @@ if __name__ == "__main__":
np.random.seed(seed) np.random.seed(seed)
config = { config = {
"root_dir": "/media/hofee/data/results/ycb_view_data", "root_dir": "/media/hofee/data/data/test_bottle/view",
"source": "seq_reconstruction_dataset", "source": "seq_reconstruction_dataset",
"split_file": "/media/hofee/data/results/ycb_test.txt", "split_file": "/media/hofee/data/data/test_bottle/test_bottle.txt",
"load_from_preprocess": True, "load_from_preprocess": True,
"filter_degree": 75, "filter_degree": 75,
"num_workers": 0, "num_workers": 0,
@ -190,7 +194,7 @@ if __name__ == "__main__":
"type": namespace.Mode.TEST, "type": namespace.Mode.TEST,
} }
output_dir = "/media/hofee/data/results/ycb_preprocessed_dataset" output_dir = "/media/hofee/data/data/test_bottle/preprocessed_dataset"
os.makedirs(output_dir, exist_ok=True) os.makedirs(output_dir, exist_ok=True)
ds = SeqReconstructionDataset(config) ds = SeqReconstructionDataset(config)

View File

@ -21,7 +21,7 @@ class SeqReconstructionDatasetPreprocessed(BaseDataset):
super(SeqReconstructionDatasetPreprocessed, self).__init__(config) super(SeqReconstructionDatasetPreprocessed, self).__init__(config)
self.config = config self.config = config
self.root_dir = config["root_dir"] self.root_dir = config["root_dir"]
self.real_root_dir = r"/media/hofee/data/results/ycb_view_data" self.real_root_dir = r"/media/hofee/data/data/new_testset"
self.item_list = os.listdir(self.root_dir) self.item_list = os.listdir(self.root_dir)
def __getitem__(self, index): def __getitem__(self, index):
@ -66,7 +66,7 @@ if __name__ == "__main__":
load_from_preprocess: True load_from_preprocess: True
''' '''
config = { config = {
"root_dir": "H:\\AI\\Datasets\\packed_test_data", "root_dir": "/media/hofee/data/data/test_bottle/preprocessed_dataset",
"source": "seq_reconstruction_dataset", "source": "seq_reconstruction_dataset",
"split_file": "H:\\AI\\Datasets\\data_list\\OmniObject3d_test.txt", "split_file": "H:\\AI\\Datasets\\data_list\\OmniObject3d_test.txt",
"load_from_preprocess": True, "load_from_preprocess": True,

View File

@ -164,7 +164,7 @@ 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"/media/hofee/data/results/ycb_view_data" root = r"/media/hofee/data/data/test_bottle/view"
scene_list = os.listdir(root) scene_list = os.listdir(root)
from_idx = 0 # 1000 from_idx = 0 # 1000
to_idx = len(scene_list) # 1500 to_idx = len(scene_list) # 1500

View File

@ -83,6 +83,7 @@ class Inferencer(Runner):
data = test_set.__getitem__(i) data = test_set.__getitem__(i)
scene_name = data["scene_name"] scene_name = data["scene_name"]
inference_result_path = os.path.join(self.output_dir, test_set_name, f"{scene_name}.pkl") inference_result_path = os.path.join(self.output_dir, test_set_name, f"{scene_name}.pkl")
if os.path.exists(inference_result_path): if os.path.exists(inference_result_path):
Log.info(f"Inference result already exists for scene: {scene_name}") Log.info(f"Inference result already exists for scene: {scene_name}")
continue continue
@ -143,12 +144,24 @@ class Inferencer(Runner):
voxel_downsampled_combined_scanned_pts_np, inverse = self.voxel_downsample_with_mapping(combined_scanned_pts, voxel_threshold) voxel_downsampled_combined_scanned_pts_np, inverse = self.voxel_downsample_with_mapping(combined_scanned_pts, voxel_threshold)
output = self.pipeline(input_data) output = self.pipeline(input_data)
pred_pose_9d = output["pred_pose_9d"] pred_pose_9d = output["pred_pose_9d"]
import ipdb; ipdb.set_trace()
pred_pose = torch.eye(4, device=pred_pose_9d.device) pred_pose = torch.eye(4, device=pred_pose_9d.device)
# # save pred_pose_9d ------
# root = "/media/hofee/data/project/python/nbv_reconstruction/nbv_reconstruction/temp_output_result"
# scene_dir = os.path.join(root, scene_name)
# if not os.path.exists(scene_dir):
# os.makedirs(scene_dir)
# pred_9d_path = os.path.join(scene_dir,f"pred_pose_9d_{len(pred_cr_seq)}.npy")
# pts_path = os.path.join(scene_dir,f"combined_scanned_pts_{len(pred_cr_seq)}.txt")
# np_combined_scanned_pts = input_data["combined_scanned_pts"][0].cpu().numpy()
# np.save(pred_9d_path, pred_pose_9d.cpu().numpy())
# np.savetxt(pts_path, np_combined_scanned_pts)
# # ----- ----- -----
pred_pose_9d_candidates = PredictResult(pred_pose_9d.cpu().numpy(), input_pts=input_data["combined_scanned_pts"][0].cpu().numpy(), cluster_params=dict(eps=0.25, min_samples=3)).candidate_9d_poses
for pred_pose_9d in pred_pose_9d_candidates:
#import ipdb; ipdb.set_trace()
pred_pose_9d = torch.tensor(pred_pose_9d, dtype=torch.float32).to(self.device).unsqueeze(0)
pred_pose[:3,:3] = PoseUtil.rotation_6d_to_matrix_tensor_batch(pred_pose_9d[:,:6])[0] pred_pose[:3,:3] = PoseUtil.rotation_6d_to_matrix_tensor_batch(pred_pose_9d[:,:6])[0]
pred_pose[:3,3] = pred_pose_9d[0,6:] pred_pose[:3,3] = pred_pose_9d[0,6:]
try: try:
new_target_pts, new_target_normals, new_scan_points_indices = RenderUtil.render_pts(pred_pose, scene_path, self.script_path, scan_points, voxel_threshold=voxel_threshold, filter_degree=filter_degree, nO_to_nL_pose=O_to_L_pose) new_target_pts, new_target_normals, new_scan_points_indices = RenderUtil.render_pts(pred_pose, scene_path, self.script_path, scan_points, voxel_threshold=voxel_threshold, filter_degree=filter_degree, nO_to_nL_pose=O_to_L_pose)
#import ipdb; ipdb.set_trace() #import ipdb; ipdb.set_trace()
@ -211,6 +224,7 @@ class Inferencer(Runner):
Log.success(f"delta pts num < {self.min_new_pts_num}:, {pts_num}, {last_pts_num}") Log.success(f"delta pts num < {self.min_new_pts_num}:, {pts_num}, {last_pts_num}")
last_pts_num = pts_num last_pts_num = pts_num
break
input_data["scanned_n_to_world_pose_9d"] = input_data["scanned_n_to_world_pose_9d"][0].cpu().numpy().tolist() input_data["scanned_n_to_world_pose_9d"] = input_data["scanned_n_to_world_pose_9d"][0].cpu().numpy().tolist()

View File

@ -88,6 +88,7 @@ class RenderUtil:
'/home/hofee/blender-4.0.2-linux-x64/blender', '-b', '-P', script_path, '--', temp_dir '/home/hofee/blender-4.0.2-linux-x64/blender', '-b', '-P', script_path, '--', temp_dir
], capture_output=True, text=True) ], capture_output=True, text=True)
#print(result) #print(result)
#import ipdb; ipdb.set_trace()
path = os.path.join(temp_dir, "tmp") path = os.path.join(temp_dir, "tmp")
cam_info = DataLoadUtil.load_cam_info(path, binocular=True) cam_info = DataLoadUtil.load_cam_info(path, binocular=True)
depth_L, depth_R = DataLoadUtil.load_depth( depth_L, depth_R = DataLoadUtil.load_depth(

View File

@ -7,6 +7,7 @@ import trimesh
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from utils.data_load import DataLoadUtil from utils.data_load import DataLoadUtil
from utils.pts import PtsUtil from utils.pts import PtsUtil
from utils.pose import PoseUtil
class visualizeUtil: class visualizeUtil:
@ -34,6 +35,21 @@ class visualizeUtil:
np.savetxt(os.path.join(output_dir, "all_cam_pos.txt"), all_cam_pos) np.savetxt(os.path.join(output_dir, "all_cam_pos.txt"), all_cam_pos)
np.savetxt(os.path.join(output_dir, "all_cam_axis.txt"), all_cam_axis) np.savetxt(os.path.join(output_dir, "all_cam_axis.txt"), all_cam_axis)
@staticmethod
def get_cam_pose_and_cam_axis(cam_pose, is_6d_pose):
if is_6d_pose:
matrix_cam_pose = np.eye(4)
matrix_cam_pose[:3,:3] = PoseUtil.rotation_6d_to_matrix_numpy(cam_pose[:6])
matrix_cam_pose[:3, 3] = cam_pose[6:]
else:
matrix_cam_pose = cam_pose
cam_pos = matrix_cam_pose[:3, 3]
cam_axis = matrix_cam_pose[:3, 2]
num_samples = 10
sample_points = [cam_pos + 0.02*t * cam_axis for t in range(num_samples)]
sample_points = np.array(sample_points)
return cam_pos, sample_points
@staticmethod @staticmethod
def save_all_combined_pts(root, scene, output_dir): def save_all_combined_pts(root, scene, output_dir):
length = DataLoadUtil.get_scene_seq_length(root, scene) length = DataLoadUtil.get_scene_seq_length(root, scene)