@@ -45,32 +45,22 @@ def __init__(self, config_data: DictConfig, config_2D: DictConfig, split: str) -
45
45
for scan_id in self .scan_ids :
46
46
pose_data = arkit .load_poses (osp .join (self .data_dir , 'scans' , scan_id ),scan_id , skip = self .frame_skip )
47
47
self .frame_pose_data [scan_id ] = pose_data
48
-
49
48
50
49
def compute2DFeatures (self ) -> None :
51
50
for scan_id in tqdm (self .scan_ids ):
52
51
self .compute2DImagesAndSeg (scan_id )
53
- self .compute2DFeaturesEachScan (scan_id )
52
+ self .compute2DFeaturesEachScan (scan_id )
54
53
55
54
def compute2DImagesAndSeg (self , scan_id : str ) -> None :
56
55
obj_id_imgs = {}
57
- scene_folder = osp .join (self .data_dir , 'scans' , scan_id )
58
56
59
57
scene_out_dir = osp .join (self .out_dir , scan_id )
60
58
load_utils .ensure_dir (scene_out_dir )
61
59
62
60
objects_path = osp .join (self .data_dir , 'scans' , scan_id , f"{ scan_id } _3dod_annotation.json" )
63
61
if not osp .exists (objects_path ):
64
62
raise FileNotFoundError (f"Annotations file not found for scan ID: { scan_id } " )
65
-
66
- gt_pt_path = osp .join (scene_folder , 'gt-projection-seg.pt' )
67
- if osp .exists (gt_pt_path ):
68
- os .remove (gt_pt_path )
69
-
70
- gt_pt_path = osp .join (scene_out_dir , 'gt-projection-seg.pt' )
71
- if osp .exists (gt_pt_path ):
72
- os .remove (gt_pt_path )
73
-
63
+
74
64
annotations = load_utils .load_json (objects_path )
75
65
ply_data = arkit .load_ply_data (osp .join (self .data_dir ,'scans' ), scan_id , annotations )
76
66
instance_ids = ply_data ['objectId' ]
@@ -110,11 +100,8 @@ def compute2DFeaturesEachScan(self, scan_id: str) -> None:
110
100
111
101
scene_out_dir = osp .join (self .out_dir , scan_id )
112
102
load_utils .ensure_dir (scene_out_dir )
113
- pt_2d_path = osp .join (scene_out_dir , 'data2D.pt' )
114
- if osp .exists (pt_2d_path ):
115
- os .remove (pt_2d_path )
116
-
117
- obj_id_to_label_id_map = np .load (osp .join (scene_out_dir , 'object_id_to_label_id_map.npz' ),allow_pickle = True )['obj_id_to_label_id_map' ].item ()
103
+
104
+ obj_id_to_label_id_map = load_utils .load_npz_as_dict (osp .join (scene_out_dir , 'object_id_to_label_id_map.npz' ))['obj_id_to_label_id_map' ]
118
105
119
106
# Multi-view Image -- Object (Embeddings)
120
107
object_image_embeddings , object_image_votes_topK , frame_idxs = self .computeImageFeaturesAllObjectsEachScan (scene_folder , scene_out_dir , obj_id_to_label_id_map )
@@ -147,36 +134,6 @@ def compute2DFeaturesEachScan(self, scan_id: str) -> None:
147
134
148
135
np .savez_compressed (osp .join (scene_out_dir , 'data2D.npz' ), ** data2D )
149
136
150
- def computeAllImageFeaturesEachScan (self , scan_id : str ) -> None :
151
- scene_folder = osp .join (self .data_dir , 'scans' , scan_id )
152
- color_path = osp .join (scene_folder ,f'{ scan_id } _frames' , 'lowres_wide' )
153
-
154
- scene_out_dir = osp .join (self .out_dir , scan_id )
155
- load_utils .ensure_dir (scene_out_dir )
156
-
157
- frame_idxs = list (self .frame_pose_data [scan_id ].keys ())
158
-
159
- # Extract Scene Image Features
160
- scene_images_pt = []
161
- scene_image_embeddings = []
162
- # sky_direction=self.metadata[self.metadata['video_id']==int(scan_id)]['sky_direction'].values[0]
163
-
164
- for frame_index in frame_idxs :
165
- image = Image .open (osp .join (color_path , f'{ scan_id } _{ frame_index } .png' ))
166
-
167
- image = image .resize ((self .model_image_size [1 ], self .model_image_size [0 ]), Image .BICUBIC )
168
- image_pt = self .model .base_tf (image )
169
-
170
- scene_image_embeddings .append (self .extractFeatures ([image_pt ], return_only_cls_mean = False ))
171
- scene_images_pt .append (image_pt )
172
-
173
- scene_image_embeddings = np .concatenate (scene_image_embeddings )
174
- data2D = {}
175
- data2D ['scene' ] = {'scene_embeddings' : scene_image_embeddings , 'images' : scene_images_pt ,
176
- 'frame_idxs' : frame_idxs }
177
- # torch.save(data2D, osp.join(scene_out_dir, 'data2D_all_images.pt'))
178
- np .savez_compressed (osp .join (scene_out_dir , 'data2D_all_images.npz' ), ** data2D )
179
-
180
137
def computeSelectedImageFeaturesEachScan (self , scan_id : str , color_path : str , frame_idxs : List [int ]) -> Tuple [np .ndarray , List [torch .tensor ], np .ndarray , List [int ]]:
181
138
# Sample Camera Indexes Based on Rotation Matrix From Grid
182
139
pose_data = []
@@ -204,9 +161,7 @@ def computeSelectedImageFeaturesEachScan(self, scan_id: str, color_path: str, fr
204
161
scene_image_embeddings = self .extractFeatures (scene_images_pt , return_only_cls_mean = False )
205
162
206
163
return pose_data , scene_images_pt , scene_image_embeddings , sampled_frame_idxs
207
- # return pose_data, None, None, sampled_frame_idxs
208
164
209
-
210
165
def computeImageFeaturesAllObjectsEachScan (self , scene_folder : str , scene_out_dir : str , obj_id_to_label_id_map : dict ) -> Tuple [Dict [int , Dict [int , np .ndarray ]], Dict [int , List [int ]], List [str ]]:
211
166
object_anno_2D = np .load (osp .join (scene_out_dir , 'gt-projection-seg.npz' ),allow_pickle = True )
212
167
object_image_votes = {}
0 commit comments