Examples & Code Samples¶
Ready-to-run code examples and configuration files for common Dataphy workflows.
Configuration Examples¶
Basic Episode Augmentation¶
Simple augmentation config for getting started:
basic_aug.yaml
version: 1
pipeline:
sync_views: true
steps:
- name: color_jitter
magnitude: 0.1
- name: cutout
holes: 1
size_range: [8, 16]
background:
adapter: none
seed: 42
Robotics-Optimized Augmentation¶
Configuration optimized for robotics datasets:
robotics_aug.yaml
version: 1
pipeline:
# Synchronize augmentations across all camera views
sync_views: true
steps:
# Preserve spatial context for robot-object relationships
- name: random_crop_pad
keep_ratio_min: 0.88
# Small spatial shifts to simulate minor camera movements
- name: random_translate
px: 8
# Lighting variations for different environments
- name: color_jitter
magnitude: 0.15
# Subtle texture effects for sensor realism
- name: random_conv
kernel_variance: 0.035
# Small occlusion patches to simulate partial blocking
- name: cutout
holes: 1
size_range: [8, 16]
background:
adapter: none
seed: 42
Python Scripts¶
Dataset Exploration Script¶
explore_dataset.py
#!/usr/bin/env python3
"""
Explore a robotics dataset and print detailed information.
"""
from pathlib import Path
from dataphy.dataset.registry import create_dataset_loader
def explore_dataset(dataset_path: str):
"""Explore and print dataset information."""
# Load dataset (auto-detect format)
loader = create_dataset_loader(dataset_path)
# Get dataset info
info = loader.get_dataset_info()
print(f"Dataset Overview:")
print(f" Format: {info.format}")
print(f" Episodes: {info.total_episodes}")
print(f" Total timesteps: {info.total_timesteps:,}")
# List episodes
episodes = loader.get_episode_ids()
print(f"\nEpisodes: {len(episodes)}")
for i, episode_id in enumerate(episodes[:5]):
print(f" {i}: {episode_id}")
if len(episodes) > 5:
print(f" ... and {len(episodes) - 5} more")
# Examine first episode
if episodes:
episode_data = loader.get_episode(episodes[0])
print(f"\nFirst Episode: {episodes[0]}")
print(f" Timesteps: {len(episode_data)}")
print(f" Cameras: {list(episode_data[0].keys())}")
# Show first timestep
first_step = episode_data[0]
print(f"\n📸 First Timestep:")
for key, value in first_step.items():
if hasattr(value, 'shape'):
print(f" {key}: {value.shape} ({value.dtype})")
else:
print(f" {key}: {value}")
if __name__ == "__main__":
import sys
if len(sys.argv) != 2:
print("Usage: python explore_dataset.py <dataset_path>")
sys.exit(1)
explore_dataset(sys.argv[1])
Episode Augmentation Script¶
augment_episode.py
#!/usr/bin/env python3
"""
Augment a specific episode with custom configuration.
"""
from pathlib import Path
from dataphy.dataset.registry import create_dataset_loader
from dataphy.dataset.episode_augmentor import EpisodeAugmentor
def augment_episode(dataset_path: str, episode_id: str, config_path: str):
"""Augment a specific episode."""
# Load dataset
loader = create_dataset_loader(dataset_path)
# Create augmentor
augmentor = EpisodeAugmentor(loader)
# Augment episode
result = augmentor.augment_episode(
episode_id=episode_id,
config_file=config_path
)
print(f"Episode {episode_id} augmented successfully!")
print(f" Output: {result.output_path}")
print(f" Augmented frames: {result.num_frames}")
print(f" Processing time: {result.processing_time:.2f}s")
if __name__ == "__main__":
import sys
if len(sys.argv) != 4:
print("Usage: python augment_episode.py <dataset_path> <episode_id> <config_path>")
sys.exit(1)
augment_episode(sys.argv[1], sys.argv[2], sys.argv[3])
Comprehensive Examples¶
For more advanced examples and complete workflows, see:
- Configuration Files - Detailed configuration examples
- Python Scripts - Complete Python implementation examples
- Comprehensive Augmentation - Full production configuration
Next Steps¶
After exploring these examples:
- Try the basic examples to understand the workflow
- Customize configurations for your specific use case
- Use the Python scripts as templates for your own code
- Explore the API Reference for programmatic usage
- Check the tutorials for step-by-step guidance