@@ -35,7 +35,10 @@ def load_rl_policy(env, train_cfg, log_dir):
3535 if not checkpoint_files :
3636 raise FileNotFoundError (f"No checkpoint files found in { log_dir } " )
3737
38- last_ckpt = sorted (checkpoint_files )[- 1 ]
38+ try :
39+ * _ , last_ckpt = sorted (checkpoint_files )
40+ except ValueError as e :
41+ raise FileNotFoundError (f"No checkpoint files found in { log_dir } " ) from e
3942 runner .load (last_ckpt )
4043 print (f"Loaded RL checkpoint from { last_ckpt } " )
4144
@@ -52,7 +55,10 @@ def load_bc_policy(env, bc_cfg, log_dir):
5255 if not checkpoint_files :
5356 raise FileNotFoundError (f"No checkpoint files found in { log_dir } " )
5457
55- last_ckpt = sorted (checkpoint_files )[- 1 ]
58+ try :
59+ * _ , last_ckpt = sorted (checkpoint_files )
60+ except ValueError as e :
61+ raise FileNotFoundError (f"No checkpoint files found in { log_dir } " ) from e
5662 print (f"Loaded BC checkpoint from { last_ckpt } " )
5763 bc_runner .load (last_ckpt )
5864
@@ -61,34 +67,26 @@ def load_bc_policy(env, bc_cfg, log_dir):
6167
6268def get_stereo_frame (env , step_count ):
6369 """Get stereo frame as numpy array."""
64- # Get individual camera images
65- rgb_left , _ , _ , _ = env .left_cam .render (rgb = True , depth = False )
66- rgb_right , _ , _ , _ = env .right_cam .render (rgb = True , depth = False )
67-
68- # Convert to numpy arrays and format for OpenCV
69- left_img = rgb_left [0 ].cpu ().numpy () # Take first environment
70- right_img = rgb_right [0 ].cpu ().numpy () # Take first environment
70+ # Get stacked stereo rgb image (B, 6, H, W)
71+ stacked_stereo_rgb = env .get_stereo_rgb_images (normalize = False ).cpu ().numpy ()[0 ]
72+ stacked_stereo_rgb = stacked_stereo_rgb .transpose (1 , 2 , 0 )
7173
72- # Convert from RGB to BGR for OpenCV
74+ # Split stacked stereo rgb image into left and right images
75+ left_img , right_img = np .split (stacked_stereo_rgb , 2 , axis = 2 )
7376 left_img = cv2 .cvtColor (left_img , cv2 .COLOR_RGB2BGR )
7477 right_img = cv2 .cvtColor (right_img , cv2 .COLOR_RGB2BGR )
78+ stereo_rgb_img = np .concatenate ([left_img , right_img ], axis = 1 )
7579
76- # Resize images for better display
77- scale = 2.0
78- left_img = cv2 .resize (left_img , (int (left_img .shape [1 ] * scale ), int (left_img .shape [0 ] * scale )))
79- right_img = cv2 .resize (right_img , (int (right_img .shape [1 ] * scale ), int (right_img .shape [0 ] * scale )))
80- # Concatenate images horizontally (side by side)
81- stereo_img = np .hstack ([left_img , right_img ])
8280 # Add a vertical line separator between the two images
8381 separator_x = left_img .shape [1 ]
8482 cv2 .line (
85- img = stereo_img ,
83+ img = stereo_rgb_img ,
8684 pt1 = (separator_x , 0 ),
87- pt2 = (separator_x , stereo_img .shape [0 ]),
85+ pt2 = (separator_x , stereo_rgb_img .shape [0 ]),
8886 color = (255 , 255 , 255 ),
8987 thickness = 2 ,
9088 )
91- return stereo_img
89+ return stereo_rgb_img
9290
9391
9492def display_stereo_images (env , step_count ):
0 commit comments