Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
직접 명령은 검토 Prompt를 거치지 않습니다. 실행하기 전에 소스를 확인하세요.
npx skills add https://github.com/MIUAV/vibe-coding-ros2 --skill tl-cross-robot-transfer명령은 한 줄로 유지됩니다. 복사하기 전에 가로로 스크롤해 전체 내용을 확인하세요.
로컬 사본을 원하시나요? SkillsMP에서 현재 제공할 수 있는 파일을 다운로드하세요.
SKILL.md 표시 중
SOC 직업 분류 기준
| name | tl-cross-robot-transfer |
| description | 跨机器人知识迁移技能 - 形态无关特征、领域泛化、策略蒸馏 |
| argument-hint | 跨机器人迁移 OR robot transfer OR 形态迁移 OR policy distillation |
| user-invocable | true |
将一个机器人的技能迁移到不同形态的机器人
当需要以下帮助时使用此技能:
import torch
import torch.nn as nn
class MorphologyAgnosticFeature(nn.Module):
def __init__(self, state_dim, hidden_dim=128):
super().__init__()
# 规范化状态输入
self.normalizer = nn.LayerNorm(state_dim)
# 形态无关特征提取
self.feature_net = nn.Sequential(
nn.Linear(state_dim, hidden_dim),
nn.ReLU(),
nn.Linear(hidden_dim, hidden_dim),
nn.ReLU(),
nn.Linear(hidden_dim, hidden_dim)
)
def forward(self, state, morphology_encoding=None):
# 归一化状态
norm_state = self.normalizer(state)
# 融合形态编码
if morphology_encoding is not None:
norm_state = torch.cat([norm_state, morphology_encoding], dim=-1)
features = self.feature_net(norm_state)
return features
class CrossRobotTransfer:
def __init__(self, source_robot, target_robot):
self.source = source_robot
self.target = target_robot
# 形态编码器
self.morphology_encoder = MorphologyEncoder()
def extract_morphology(self, robot):
"""提取机器人形态特征"""
return torch.tensor([
robot.dof, # 自由度
robot.link_count, # 连杆数
robot.weight, # 重量
robot.height, # 高度
robot.reach, # 臂展
])
def transfer_policy(self, policy, source_state, target_state):
"""迁移策略到目标机器人"""
source_morph = self.extract_morphology(self.source)
target_morph = self.extract_morphology(self.target)
# 提取形态无关特征
features = policy.extract_features(source_state, source_morph)
# 调整到目标形态
adapted_features = self.morphology_adapter(features, source_morph, target_morph)
# 生成目标机器人策略
target_policy = policy.generate_policy(adapted_features, target_morph)
return target_policy
class PolicyDistillation:
def __init__(self, teacher_policy, student_policy, temperature=2.0):
self.teacher = teacher_policy
self.student = student_policy
self.temperature = temperature
def distill(self, states, optimizer, alpha=0.5):
"""
知识蒸馏
alpha: 教师信号的权重
"""
with torch.no_grad():
teacher_q = self.teacher(states)
student_logits = self.student(states)
# KL 散度损失
soft_loss = nn.functional.kl_div(
student_logits / self.temperature,
teacher_q / self.temperature,
reduction='batchmean'
) * (self.temperature ** 2)
# 硬标签损失
hard_loss = nn.functional.cross_entropy(student_logits, teacher_q.argmax(dim=-1))
# 联合损失
loss = alpha * hard_loss + (1 - alpha) * soft_loss
optimizer.zero_grad()
loss.backward()
optimizer.step()
return loss.item()