| """ |
| Simple DROID Episode Visualizer |
| |
| Just loads and displays DROID episodes to verify data format. |
| No tracking, no projection - pure visualization. |
| """ |
|
|
| import sys |
| import numpy as np |
| import tensorflow_datasets as tfds |
| from pathlib import Path |
| import argparse |
| import cv2 |
| from tqdm import tqdm |
|
|
|
|
| def visualize_episode(droid_path: str, episode_index: int = 0, output_dir: str = '/tmp/droid_viz'): |
| """ |
| Load and visualize a DROID episode. |
| |
| Args: |
| droid_path: Path to DROID RLDS dataset |
| episode_index: Which episode to visualize |
| output_dir: Output directory for videos |
| """ |
| print(f"Loading episode {episode_index} from {droid_path}...") |
|
|
| |
| builder = tfds.builder_from_directory(droid_path) |
| dataset = builder.as_dataset(split='train') |
|
|
| |
| output_path = Path(output_dir) |
| output_path.mkdir(parents=True, exist_ok=True) |
|
|
| |
| for idx, episode in enumerate(dataset): |
| if idx != episode_index: |
| continue |
|
|
| print(f"✓ Found episode {episode_index}") |
|
|
| |
| steps = list(episode['steps']) |
| print(f" Total steps: {len(steps)}") |
|
|
| |
| try: |
| recording_path = episode['episode_metadata']['recording_folderpath'].numpy().decode('utf-8') |
| print(f" Recording: {recording_path}") |
| except: |
| recording_path = "unknown" |
|
|
| try: |
| language = steps[0]['language_instruction'].numpy().decode('utf-8') |
| print(f" Task: {language}") |
| except: |
| language = "No instruction" |
|
|
| |
| with open(output_path / 'episode_info.txt', 'w') as f: |
| f.write(f"Episode: {episode_index}\n") |
| f.write(f"Steps: {len(steps)}\n") |
| f.write(f"Recording: {recording_path}\n") |
| f.write(f"Task: {language}\n") |
|
|
| |
| valid_frames_ext = [] |
| valid_frames_wrist = [] |
|
|
| print("\nProcessing frames...") |
| for step_idx, step in enumerate(tqdm(steps)): |
| |
| try: |
| |
| img_ext_bytes = step['observation']['exterior_image_1_left'].numpy() |
| img_ext = cv2.imdecode(np.frombuffer(img_ext_bytes, dtype=np.uint8), cv2.IMREAD_COLOR) |
|
|
| |
| img_wrist_bytes = step['observation']['wrist_image_left'].numpy() |
| img_wrist = cv2.imdecode(np.frombuffer(img_wrist_bytes, dtype=np.uint8), cv2.IMREAD_COLOR) |
|
|
| if img_ext is not None and img_wrist is not None: |
| |
| img_ext = cv2.resize(img_ext, (448, 448)) |
| img_wrist = cv2.resize(img_wrist, (448, 448)) |
|
|
| |
| cv2.putText(img_ext, f"Frame {step_idx}/{len(steps)}", (10, 30), |
| cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 255, 255), 2) |
| cv2.putText(img_wrist, f"Frame {step_idx}/{len(steps)}", (10, 30), |
| cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 255, 255), 2) |
|
|
| valid_frames_ext.append(img_ext) |
| valid_frames_wrist.append(img_wrist) |
| else: |
| if step_idx == 0: |
| print(f" ⚠ Frame {step_idx}: decode returned None") |
| except Exception as e: |
| if step_idx == 0: |
| print(f" ⚠ Frame {step_idx}: decode failed - {e}") |
|
|
| print(f"\n✓ Successfully decoded {len(valid_frames_ext)} frames out of {len(steps)}") |
|
|
| if len(valid_frames_ext) == 0: |
| print("✗ No valid frames found. This episode may be corrupted.") |
| print(" Try a different episode with --episode-index N") |
| return False |
|
|
| |
| fourcc = cv2.VideoWriter_fourcc(*'mp4v') |
| video_ext = cv2.VideoWriter( |
| str(output_path / 'exterior_camera.mp4'), |
| fourcc, 10, (448, 448) |
| ) |
| video_wrist = cv2.VideoWriter( |
| str(output_path / 'wrist_camera.mp4'), |
| fourcc, 10, (448, 448) |
| ) |
|
|
| for frame_ext, frame_wrist in zip(valid_frames_ext, valid_frames_wrist): |
| video_ext.write(frame_ext) |
| video_wrist.write(frame_wrist) |
|
|
| video_ext.release() |
| video_wrist.release() |
|
|
| |
| cv2.imwrite(str(output_path / 'frame_0_exterior.png'), valid_frames_ext[0]) |
| cv2.imwrite(str(output_path / 'frame_0_wrist.png'), valid_frames_wrist[0]) |
|
|
| print(f"\n✓ Saved videos to {output_path}:") |
| print(f" exterior_camera.mp4") |
| print(f" wrist_camera.mp4") |
| print(f" frame_0_exterior.png") |
| print(f" frame_0_wrist.png") |
|
|
| |
| try: |
| joints = steps[0]['observation']['joint_position'].numpy() |
| print(f"\n✓ Joint positions (first frame): {joints}") |
| cart_pos = steps[0]['observation']['cartesian_position'].numpy() |
| print(f"✓ Cartesian position (first frame): {cart_pos}") |
| except Exception as e: |
| print(f"⚠ Could not read robot state: {e}") |
|
|
| return True |
|
|
| print(f"✗ Episode {episode_index} not found in dataset") |
| return False |
|
|
|
|
| def main(): |
| parser = argparse.ArgumentParser(description="Visualize DROID episode") |
|
|
| parser.add_argument( |
| '--droid-path', |
| type=str, |
| default='/mnt/kevin/data/droid/droid/1.0.0', |
| help='Path to DROID RLDS dataset' |
| ) |
| parser.add_argument( |
| '--episode-index', |
| type=int, |
| default=0, |
| help='Episode index to visualize (try different indices if one fails)' |
| ) |
| parser.add_argument( |
| '--output-dir', |
| type=str, |
| default='/tmp/droid_viz', |
| help='Output directory' |
| ) |
|
|
| args = parser.parse_args() |
|
|
| print("=" * 60) |
| print("DROID Episode Visualizer") |
| print("=" * 60 + "\n") |
|
|
| success = visualize_episode(args.droid_path, args.episode_index, args.output_dir) |
|
|
| if not success: |
| print("\nTry a different episode:") |
| print(" python visualize_droid_episode.py --episode-index 1") |
| print(" python visualize_droid_episode.py --episode-index 10") |
| print(" python visualize_droid_episode.py --episode-index 100") |
| return 1 |
|
|
| print("\n" + "=" * 60) |
| print("Visualization Complete!") |
| print("=" * 60) |
| return 0 |
|
|
|
|
| if __name__ == "__main__": |
| sys.exit(main()) |
|
|