@@ -67,7 +67,7 @@ def main():
6767
6868    # path where to store stuff during creation 
6969    tmp_path  =  os .path .join (output_path , TMP_DIR )
70-     create_dir (output_path )
70+     create_dir (tmp_path )
7171
7272    # update or write metafile 
7373    create_or_update_creation_metafile (output_path )
@@ -309,7 +309,12 @@ def main():
309309
310310            boxes_3d_dict ["instance_numbers" ] =  box_mapping .tolist ()
311311        else :
312-             instance_img  =  cv2 .imread (instance_path , cv2 .IMREAD_UNCHANGED )
312+             # Only imread if file exists. Else set instance_img to None 
313+             # so no orientations are created. 
314+             if  os .path .isfile (instance_path ):
315+                 instance_img  =  cv2 .imread (instance_path , cv2 .IMREAD_UNCHANGED )
316+             else :
317+                 instance_img  =  None 
313318
314319        # Intrinsics ----------------------------------------------------------- 
315320        intrinsics_path  =  os .path .join (output_path , split_dir ,
@@ -331,31 +336,36 @@ def main():
331336            json .dump (normalized_intrinsics , j , indent = 4 )
332337
333338        # Orientations --------------------------------------------------------- 
334-         orientations_path  =  os .path .join (output_path , split_dir ,
335-                                          SUNRGBDMeta .ORIENTATIONS_DIR ,
336-                                          cam_path , f'{ i :05d}  )
337-         create_dir (os .path .dirname (orientations_path ))
338- 
339-         orientations  =  np .array (orientations_list )
340-         orientations_dict  =  {}
341-         for  key , value  in  enumerate (orientations ):
342-             # +1 as 0 indicates void/no instance 
343-             current_key  =  key  +  1 
344-             mask  =  instance_img  ==  current_key 
345-             # This happens when no pixel was inside a 3d box, which leads 
346-             # to no instance being created 
347-             if  mask .sum () ==  0 :
348-                 continue 
349- 
350-             orientations_dict [current_key ] =  value 
351- 
352-         with  open (orientations_path , "w" ) as  j :
353-             json .dump (orientations_dict , j , indent = 4 )
354- 
355-         if  is_train :
356-             train_dirs .append (os .path .join (cam_path , f"{ i :05d}  ))
357-         else :
358-             test_dirs .append (os .path .join (cam_path , f"{ i :05d}  ))
339+ 
340+         # The orientations of the instance can only be saved, if instances are 
341+         # created or loaded. 
342+         # instance_img will be None, if it couldn't be loaded 
343+         if  args .create_instances  or  instance_img  is  not None :
344+             orientations_path  =  os .path .join (output_path , split_dir ,
345+                                              SUNRGBDMeta .ORIENTATIONS_DIR ,
346+                                              cam_path , f'{ i :05d}  )
347+             create_dir (os .path .dirname (orientations_path ))
348+ 
349+             orientations  =  np .array (orientations_list )
350+             orientations_dict  =  {}
351+             for  key , value  in  enumerate (orientations ):
352+                 # +1 as 0 indicates void/no instance 
353+                 current_key  =  key  +  1 
354+                 mask  =  instance_img  ==  current_key 
355+                 # This happens when no pixel was inside a 3d box, which leads 
356+                 # to no instance being created 
357+                 if  mask .sum () ==  0 :
358+                     continue 
359+ 
360+                 orientations_dict [current_key ] =  value 
361+ 
362+             with  open (orientations_path , "w" ) as  j :
363+                 json .dump (orientations_dict , j , indent = 4 )
364+ 
365+             if  is_train :
366+                 train_dirs .append (os .path .join (cam_path , f"{ i :05d}  ))
367+             else :
368+                 test_dirs .append (os .path .join (cam_path , f"{ i :05d}  ))
359369
360370    # write file lists 
361371    def  _write_list_to_file (list_ , filepath ):
0 commit comments