sim2real
Sim2Real 迁移技能 - 域随机化、域适应、系统识别、现实差距弥合、ROS2 部署
от MIUAV★ 30 звёзд на GitHub
Установить sim2real в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Sim2Real 迁移技能
用于缩小仿真与现实之间差距的技能,涵盖域随机化、域适应、系统识别和现实部署
何时使用
当需要以下帮助时使用此技能:
- 在仿真中训练,在现实机器人上部署
- 配置域随机化参数
- 补偿物理参数差异
- 在线适应现实环境
- 减少 sim-to-real 迁移的性能下降
快速参考
Sim2Real 挑战
现实差距主要来源:
├── 视觉差异 → 纹理、光照、噪声
├── 物理差异 → 摩擦、延迟、关节柔性
├── 传感器差异 → 噪声、漂移、校准
└── 控制差异 → 采样延迟、执行机构非线性
核心策略
1. 域随机化 (Domain Randomization)
→ 在仿真中随机化所有参数,强制策略对随机化鲁棒
2. 域适应 (Domain Adaptation)
→ 学习 domain-invariant 特征
3. 系统识别 (System Identification)
→ 精确测量现实机器人参数
4. 在线适应 (Online Adaptation)
→ 部署后持续调整策略
域随机化 (Domain Randomization)
RGB 图像域随机化
import numpy as np
from dataclasses import dataclass
from typing import Tuple, List
import cv2
@dataclass
class VisualRandomizationConfig:
"""视觉域随机化配置"""
# 光照
light_intensity_range: Tuple[float, float] = (0.5, 1.5)
light_position_range: Tuple[float, float] = (-1.0, 1.0)
# 纹理
texture_noise_std: float = 0.02
texture_patterns: List[str] = None # 可选背景图案
# 相机
camera_noise_std: float = 0.01
camera_resolution: Tuple[int, int] = (640, 480)
distortion_k: Tuple[float, float] = (0.0, 0.01)
# 物体颜色
obj_color_hsv_range: Tuple = ((0, 150, 150), (180, 255, 255))
class VisualDomainRandomizer:
"""视觉域随机化"""
def __init__(self, config: VisualRandomizationConfig):
self.cfg = config
def randomize_image(self, image: np.ndarray) -> np.ndarray:
"""对图像应用随机化"""
img = image.copy()
# 1. 亮度/对比度随机
alpha = np.random.uniform(*self.cfg.light_intensity_range)
img = cv2.convertScaleAbs(img, alpha=alpha, beta=0)
# 2. 添加噪声
noise = np.random.randn(*img.shape) * self.cfg.texture_noise_std * 255
img = np.clip(img + noise, 0, 255).astype(np.uint8)
# 3. 模糊(模拟对焦不准)
if np.random.rand() < 0.2:
ksize = np.random.choice([3, 5, 7])
img = cv2.GaussianBlur(img, (ksize, ksize), 0)
# 4. 模拟相机畸变
if np.random.rand() < 0.3:
k1, k2 = np.random.uniform(*self.cfg.distortion_k, 2)
img = self._apply_distortion(img, k1, k2)
return img
def _apply_distortion(self, img, k1, k2) -> np.ndarray:
"""应用桶形/枕形畸变"""
h, w = img.shape[:2]
k = np.random.randn(6) * 0.001
# 生成畸变映射
map_x = np.zeros((h, w), dtype=np.float32)
map_y = np.zeros((h, w), dtype=np.float32)
cx, cy = w / 2, h / 2
for y in range(h):
for x in range(w):
dx = (x - cx) / cx
dy = (y - cy) / cy
r2 = dx**2 + dy**2
distortion = 1 + k1 * r2 + k2 * r2**2
map_x[y, x] = cx + distortion * (x - cx)
map_y[y, x] = cy + distortion * (y - cy)
return cv2.remap(img, map_x, map_y, cv2.INTER_LINEAR)
class TextureRandomizer:
"""背景纹理随机化"""
def __init__(self, texture_dir: str = None):
self.textures = self._load_textures(texture_dir) if texture_dir else []
# 默认图案
self.default_patterns = [
self._checkerboard,
self._stripes,
self._noise,
]
def apply_random_texture(self, image: np.ndarray) -> np.ndarray:
"""应用随机背景纹理"""
if not self.textures and not self.default_patterns:
return image
h, w = image.shape[:2]
if self.textures and np.random.rand() < 0.3:
# 使用真实纹理图像
tex = np.random.choice(self.textures)
tex = cv2.resize(tex, (w, h))
return cv2.addWeighted(image, 0.7, tex, 0.3, 0)
else:
# 使用程序生成图案
pattern = np.random.choice(self.default_patterns)
bg = pattern(h, w)
return cv2.addWeighted(image, 0.8, bg, 0.2, 0)
def _checkerboard(self, h, w):
size = np.random.randint(20, 80)
board = np.indices((h, w))
pattern = ((board[0] // size) + (board[1] // size)) % 2
bg = (pattern * 255).astype(np.uint8)
return cv2.cvtColor(bg, cv2.COLOR_GRAY2BGR)
def _stripes(self, h, w):
angle = np.random.uniform(0, 180)
lines = h // np.random.randint(10, 50)
bg = np.zeros((h, w), dtype=np.uint8)
for i in range(0, h + w, lines):
cv2.line(bg, (i, 0), (i - h, h), 255, 2)
return cv2.cvtColor(bg, cv2.COLOR_GRAY2BGR)
def _noise(self, h, w):
bg = np.random.randint(100, 200, (h, w), dtype=np.uint8)
return cv2.cvtColor(bg, cv2.COLOR_GRAY2BGR)
物理域随机化
MuJoCo 物理参数随机化
import numpy as np
import mujoco
class PhysicsDomainRandomizer:
"""物理域随机化"""
def __init__(self, model: mujoco.Model):
self.model = model
# 参数范围(百分比)
self.param_ranges = {
# 摩擦系数
'friction': (0.5, 1.5), # 0.5x ~ 1.5x
# 质量
'mass': (0.8, 1.2), # 0.8x ~ 1.2x
# 关节阻尼
'damping': (0.5, 2.0), # 0.5x ~ 2.0x
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл sim2real?
Sim2Real 迁移技能 - 域随机化、域适应、系统识别、现实差距弥合、ROS2 部署
Как установить скилл sim2real?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл sim2real запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
AnthropicToolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
access
AnthropicManage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
configure
AnthropicSet up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
access
AnthropicManage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…