镜像自地址
https://github.com/MINT-SJTU/Evo-RL.git
已同步 2026-11-20 18:17:06 +00:00
chore(ci): make quality checks pass across repo
- fix ruff violations in dataset, recording, and value modules - fix typos findings and markdown/workflow lint issues - update pages workflow checkout to disable credential persistence - apply pre-commit auto-formatting and EOF normalization - include requested repo housekeeping updates (.gitignore and README)
这个提交包含在:
@ -41,7 +41,9 @@ class ValueTargetsConfig:
|
||||
if self.c_fail_coef < 0:
|
||||
raise ValueError("'targets.c_fail_coef' must be non-negative.")
|
||||
if not self.target_field.startswith("observation."):
|
||||
raise ValueError("'targets.target_field' must start with 'observation.' to survive processor conversion.")
|
||||
raise ValueError(
|
||||
"'targets.target_field' must start with 'observation.' to survive processor conversion."
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
@ -113,7 +115,7 @@ class ValueTrainPipelineConfig(HubMixin):
|
||||
self.targets.validate()
|
||||
|
||||
if hasattr(self.value, "target_key"):
|
||||
setattr(self.value, "target_key", self.targets.target_field)
|
||||
self.value.target_key = self.targets.target_field
|
||||
|
||||
if not self.job_name:
|
||||
self.job_name = f"{self.value.type}_value"
|
||||
@ -136,7 +138,9 @@ class ValueTrainPipelineConfig(HubMixin):
|
||||
self.scheduler = self.value.get_scheduler_preset()
|
||||
|
||||
if self.value.push_to_hub and not self.value.repo_id:
|
||||
raise ValueError("'value.repo_id' argument missing. Please specify it to push the model to the hub.")
|
||||
raise ValueError(
|
||||
"'value.repo_id' argument missing. Please specify it to push the model to the hub."
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def __get_path_fields__(cls) -> list[str]:
|
||||
|
||||
@ -836,7 +836,11 @@ def _copy_and_reindex_episodes_metadata(
|
||||
for key in schema.names:
|
||||
if key in {"episode_index", "tasks", "length"}:
|
||||
continue
|
||||
if key.startswith("stats/") or key.startswith("__index_level_") or key.startswith("meta/episodes/"):
|
||||
if (
|
||||
key.startswith("stats/")
|
||||
or key.startswith("__index_level_")
|
||||
or key.startswith("meta/episodes/")
|
||||
):
|
||||
continue
|
||||
if key not in seen_preserved_keys:
|
||||
seen_preserved_keys.add(key)
|
||||
|
||||
@ -729,15 +729,14 @@ class LeRobotDataset(torch.utils.data.Dataset):
|
||||
# Check if cached dataset contains all requested episodes
|
||||
if not self._check_cached_episodes_sufficient():
|
||||
raise FileNotFoundError("Cached dataset doesn't contain all requested episodes")
|
||||
except (AssertionError, FileNotFoundError, NotADirectoryError):
|
||||
except (AssertionError, FileNotFoundError, NotADirectoryError) as err:
|
||||
if is_valid_version(self.revision):
|
||||
self.revision = get_safe_version(self.repo_id, self.revision)
|
||||
self.download(download_videos)
|
||||
self.hf_dataset = self.load_hf_dataset()
|
||||
if not self._check_cached_episodes_sufficient():
|
||||
missing_videos_hint = (
|
||||
" Missing video files are required by this dataset. "
|
||||
"Retry with `download_videos=True`."
|
||||
" Missing video files are required by this dataset. Retry with `download_videos=True`."
|
||||
if len(self.meta.video_keys) > 0 and not download_videos
|
||||
else ""
|
||||
)
|
||||
@ -745,7 +744,7 @@ class LeRobotDataset(torch.utils.data.Dataset):
|
||||
"Cached dataset is incomplete after download. "
|
||||
"Some requested episodes or files are missing."
|
||||
f"{missing_videos_hint}"
|
||||
)
|
||||
) from err
|
||||
|
||||
# Create mapping from absolute indices to relative indices when only a subset of the episodes are loaded
|
||||
# Build a mapping: absolute_index -> relative_index_in_filtered_dataset
|
||||
|
||||
@ -60,10 +60,7 @@ def _from_meta_stats(dataset: Any, indicator_field: str) -> ACPIndicatorStats |
|
||||
|
||||
count_raw = _stats_entry_to_scalar(field_stats, "count")
|
||||
total_count = int(round(count_raw)) if count_raw is not None else -1
|
||||
if total_count >= 0:
|
||||
positive_count = int(round(ratio * total_count))
|
||||
else:
|
||||
positive_count = -1
|
||||
positive_count = int(round(ratio * total_count)) if total_count >= 0 else -1
|
||||
|
||||
return ACPIndicatorStats(
|
||||
indicator_field=indicator_field,
|
||||
|
||||
@ -136,7 +136,9 @@ def build_report(dataset_root: Path) -> dict[str, Any]:
|
||||
episodes_df = episodes_ds.to_pandas()
|
||||
|
||||
actual_episode_count = int(len(episodes_df))
|
||||
episode_success_labels = episodes_df["episode_success"].tolist() if "episode_success" in episodes_df else []
|
||||
episode_success_labels = (
|
||||
episodes_df["episode_success"].tolist() if "episode_success" in episodes_df else []
|
||||
)
|
||||
normalized_labels = [_normalize_label(v) for v in episode_success_labels]
|
||||
|
||||
success_count = sum(1 for v in normalized_labels if v == "success")
|
||||
@ -153,7 +155,11 @@ def build_report(dataset_root: Path) -> dict[str, Any]:
|
||||
intervention_frames = 0
|
||||
intervention_episode_count = 0
|
||||
|
||||
if intervention_col in data_schema_names and episode_index_col in data_schema_names and actual_frame_count > 0:
|
||||
if (
|
||||
intervention_col in data_schema_names
|
||||
and episode_index_col in data_schema_names
|
||||
and actual_frame_count > 0
|
||||
):
|
||||
table = data_dataset.to_table(columns=[episode_index_col, intervention_col])
|
||||
episode_indices = table[episode_index_col].to_pylist()
|
||||
intervention_values = table[intervention_col].to_pylist()
|
||||
@ -190,10 +196,14 @@ def build_report(dataset_root: Path) -> dict[str, Any]:
|
||||
|
||||
fps = float(info.get("fps", 0) or 0)
|
||||
episode_lengths_frames = (
|
||||
episodes_df["length"].astype(int).tolist() if "length" in episodes_df and actual_episode_count > 0 else []
|
||||
episodes_df["length"].astype(int).tolist()
|
||||
if "length" in episodes_df and actual_episode_count > 0
|
||||
else []
|
||||
)
|
||||
episode_lengths_seconds = [frames / fps for frames in episode_lengths_frames] if fps > 0 else []
|
||||
length_mean = float(sum(episode_lengths_seconds) / len(episode_lengths_seconds)) if episode_lengths_seconds else 0.0
|
||||
length_mean = (
|
||||
float(sum(episode_lengths_seconds) / len(episode_lengths_seconds)) if episode_lengths_seconds else 0.0
|
||||
)
|
||||
length_min = float(min(episode_lengths_seconds)) if episode_lengths_seconds else 0.0
|
||||
length_max = float(max(episode_lengths_seconds)) if episode_lengths_seconds else 0.0
|
||||
length_histogram = _build_episode_length_histogram(episode_lengths_seconds, bins=20)
|
||||
|
||||
@ -22,16 +22,16 @@ Phase A/B goals:
|
||||
- Keyboard-toggled intervention lets teleop temporarily take over execution.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import json
|
||||
import logging
|
||||
import time
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from lerobot.configs import parser
|
||||
from lerobot.scripts.lerobot_record import RecordConfig, record
|
||||
from lerobot.utils.import_utils import register_third_party_plugins
|
||||
from lerobot.utils.constants import HF_LEROBOT_HOME
|
||||
from lerobot.utils.import_utils import register_third_party_plugins
|
||||
from lerobot.utils.recording_annotations import EPISODE_FAILURE, infer_collector_policy_version
|
||||
|
||||
|
||||
@ -64,7 +64,9 @@ def _load_failure_reset_pose(pose_path: Path) -> dict[str, float]:
|
||||
payload = json.load(f)
|
||||
joint_pos_raw = payload["joint_pos"] if isinstance(payload, dict) and "joint_pos" in payload else payload
|
||||
if not isinstance(joint_pos_raw, dict):
|
||||
raise ValueError(f"Invalid failure reset pose payload in {pose_path}: expected dict, got {type(joint_pos_raw)}")
|
||||
raise ValueError(
|
||||
f"Invalid failure reset pose payload in {pose_path}: expected dict, got {type(joint_pos_raw)}"
|
||||
)
|
||||
joint_pos = {str(key): float(value) for key, value in joint_pos_raw.items() if str(key).endswith(".pos")}
|
||||
if not joint_pos:
|
||||
raise ValueError(f"Invalid failure reset pose payload in {pose_path}: no '.pos' joints found.")
|
||||
|
||||
@ -97,6 +97,13 @@ from lerobot.robots import ( # noqa: F401
|
||||
so_follower,
|
||||
unitree_g1 as unitree_g1_robot,
|
||||
)
|
||||
from lerobot.scripts.recording_hil import (
|
||||
ACPInferenceConfig,
|
||||
PolicySyncDualArmExecutor,
|
||||
_capture_policy_runtime_state, # noqa: F401
|
||||
_predict_policy_action_with_acp_inference, # noqa: F401
|
||||
)
|
||||
from lerobot.scripts.recording_loop import record_loop
|
||||
from lerobot.teleoperators import ( # noqa: F401
|
||||
TeleoperatorConfig,
|
||||
bi_openarm_leader,
|
||||
@ -110,13 +117,6 @@ from lerobot.teleoperators import ( # noqa: F401
|
||||
so_leader,
|
||||
unitree_g1,
|
||||
)
|
||||
from lerobot.scripts.recording_hil import (
|
||||
ACPInferenceConfig,
|
||||
PolicySyncDualArmExecutor,
|
||||
_capture_policy_runtime_state, # noqa: F401
|
||||
_predict_policy_action_with_acp_inference, # noqa: F401
|
||||
)
|
||||
from lerobot.scripts.recording_loop import record_loop
|
||||
from lerobot.utils.constants import ACTION
|
||||
from lerobot.utils.control_utils import (
|
||||
init_keyboard_listener,
|
||||
@ -288,6 +288,7 @@ class RecordConfig:
|
||||
"""This enables the parser to load config from the policy using `--policy.path=local/dir`"""
|
||||
return ["policy"]
|
||||
|
||||
|
||||
@parser.wrap()
|
||||
def record(cfg: RecordConfig) -> LeRobotDataset:
|
||||
init_logging()
|
||||
@ -325,10 +326,7 @@ def record(cfg: RecordConfig) -> LeRobotDataset:
|
||||
)
|
||||
if cfg.intervention_state_machine_enabled and cfg.policy is not None and cfg.teleop is not None:
|
||||
action_names = dataset_features[ACTION]["names"]
|
||||
if action_names is None:
|
||||
action_names = list(robot.action_features)
|
||||
else:
|
||||
action_names = list(action_names)
|
||||
action_names = list(robot.action_features) if action_names is None else list(action_names)
|
||||
dataset_features["complementary_info.policy_action"] = {
|
||||
"dtype": "float32",
|
||||
"shape": (len(action_names),),
|
||||
@ -524,9 +522,7 @@ def record(cfg: RecordConfig) -> LeRobotDataset:
|
||||
continue
|
||||
|
||||
extra_episode_metadata = (
|
||||
{"episode_success": episode_success}
|
||||
if cfg.enable_episode_outcome_labeling
|
||||
else None
|
||||
{"episode_success": episode_success} if cfg.enable_episode_outcome_labeling else None
|
||||
)
|
||||
dataset.save_episode(extra_episode_metadata=extra_episode_metadata)
|
||||
recorded_episodes += 1
|
||||
|
||||
@ -35,6 +35,9 @@ from lerobot.configs.value import ValueInferencePipelineConfig
|
||||
from lerobot.datasets.lerobot_dataset import LeRobotDataset
|
||||
from lerobot.datasets.utils import load_info, write_info
|
||||
from lerobot.policies.factory import make_policy, make_pre_post_processors
|
||||
from lerobot.scripts.value_infer_viz import (
|
||||
_export_overlay_videos,
|
||||
)
|
||||
from lerobot.utils.constants import (
|
||||
CHECKPOINTS_DIR,
|
||||
LAST_CHECKPOINT_LINK,
|
||||
@ -44,11 +47,6 @@ from lerobot.utils.import_utils import register_third_party_plugins
|
||||
from lerobot.utils.random_utils import set_seed
|
||||
from lerobot.utils.recording_annotations import EPISODE_SUCCESS, resolve_episode_success_label
|
||||
from lerobot.utils.utils import init_logging, inside_slurm
|
||||
from lerobot.scripts.value_infer_viz import (
|
||||
_export_overlay_videos,
|
||||
_get_episode_value_bounds,
|
||||
_get_video_encode_options,
|
||||
)
|
||||
from lerobot.values.pistar06.configuration_pistar06 import Pistar06Config
|
||||
from lerobot.values.pistar06.modeling_pistar06 import (
|
||||
EpisodeTargetInfo,
|
||||
@ -310,8 +308,8 @@ def _binarize_advantages(
|
||||
|
||||
for i in range(advantages.shape[0]):
|
||||
task_idx = int(task_indices[i])
|
||||
thr = thresholds[task_idx]
|
||||
indicators[i] = 1 if float(advantages[i]) >= thr else 0
|
||||
threshold = thresholds[task_idx]
|
||||
indicators[i] = 1 if float(advantages[i]) >= threshold else 0
|
||||
|
||||
if force_intervention_positive:
|
||||
intervention_mask = interventions.astype(np.float32) > 0.5
|
||||
|
||||
@ -52,7 +52,9 @@ def update_policy(
|
||||
if grad_clip_norm > 0:
|
||||
grad_norm = accelerator.clip_grad_norm_(policy.parameters(), grad_clip_norm)
|
||||
else:
|
||||
grad_norm = torch.nn.utils.clip_grad_norm_(policy.parameters(), float("inf"), error_if_nonfinite=False)
|
||||
grad_norm = torch.nn.utils.clip_grad_norm_(
|
||||
policy.parameters(), float("inf"), error_if_nonfinite=False
|
||||
)
|
||||
|
||||
with lock if lock is not None else nullcontext():
|
||||
optimizer.step()
|
||||
|
||||
@ -14,7 +14,6 @@
|
||||
|
||||
"""Human-in-loop recording helpers used by `lerobot_record.py`."""
|
||||
|
||||
import logging
|
||||
from collections import deque
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from copy import deepcopy
|
||||
@ -53,7 +52,9 @@ def _get_torch_rng_state(device: torch.device) -> tuple[torch.Tensor, torch.Tens
|
||||
return cpu_state, cuda_state
|
||||
|
||||
|
||||
def _set_torch_rng_state(device: torch.device, cpu_state: torch.Tensor, cuda_state: torch.Tensor | None) -> None:
|
||||
def _set_torch_rng_state(
|
||||
device: torch.device, cpu_state: torch.Tensor, cuda_state: torch.Tensor | None
|
||||
) -> None:
|
||||
torch.set_rng_state(cpu_state)
|
||||
if device.type == "cuda" and cuda_state is not None:
|
||||
torch.cuda.set_rng_state(cuda_state, device)
|
||||
|
||||
@ -35,10 +35,10 @@ from lerobot.processor import (
|
||||
)
|
||||
from lerobot.robots import Robot
|
||||
from lerobot.scripts.recording_hil import (
|
||||
ACPInferenceConfig,
|
||||
INTERVENTION_STATE_ACTIVE,
|
||||
INTERVENTION_STATE_POLICY,
|
||||
INTERVENTION_STATE_RELEASE,
|
||||
ACPInferenceConfig,
|
||||
PolicySyncDualArmExecutor,
|
||||
_capture_policy_runtime_state,
|
||||
_predict_policy_action_with_acp_inference,
|
||||
@ -155,8 +155,8 @@ def record_loop(
|
||||
action_feature_names = list(robot.action_features.keys())
|
||||
else:
|
||||
action_feature_names = list(robot.action_features)
|
||||
zero_policy_action = {name: 0.0 for name in action_feature_names}
|
||||
has_teleop = isinstance(teleop, Teleoperator) or isinstance(teleop, list)
|
||||
zero_policy_action = dict.fromkeys(action_feature_names, 0.0)
|
||||
has_teleop = isinstance(teleop, (Teleoperator, list))
|
||||
intervention_enabled = intervention_state_machine_enabled and policy is not None and has_teleop
|
||||
intervention_state = INTERVENTION_STATE_POLICY
|
||||
last_teleop_action: RobotAction | None = None
|
||||
@ -282,22 +282,26 @@ def record_loop(
|
||||
# Get action from policy and/or teleop
|
||||
act_processed_policy: RobotAction | None = None
|
||||
act_processed_teleop: RobotAction | None = None
|
||||
if policy is not None and preprocessor is not None and postprocessor is not None:
|
||||
if not (intervention_enabled and intervention_state == INTERVENTION_STATE_ACTIVE):
|
||||
policy_action = _predict_policy_action_with_acp_inference(
|
||||
observation_frame=observation_frame,
|
||||
policy=policy,
|
||||
device=get_safe_torch_device(policy.config.device),
|
||||
preprocessor=preprocessor,
|
||||
postprocessor=postprocessor,
|
||||
use_amp=policy.config.use_amp,
|
||||
task=single_task,
|
||||
robot_type=robot.robot_type,
|
||||
acp_inference=acp_inference,
|
||||
cond_runtime_state=cond_policy_runtime_state,
|
||||
uncond_runtime_state=uncond_policy_runtime_state,
|
||||
)
|
||||
act_processed_policy = make_robot_action(policy_action, dataset.features)
|
||||
if (
|
||||
policy is not None
|
||||
and preprocessor is not None
|
||||
and postprocessor is not None
|
||||
and not (intervention_enabled and intervention_state == INTERVENTION_STATE_ACTIVE)
|
||||
):
|
||||
policy_action = _predict_policy_action_with_acp_inference(
|
||||
observation_frame=observation_frame,
|
||||
policy=policy,
|
||||
device=get_safe_torch_device(policy.config.device),
|
||||
preprocessor=preprocessor,
|
||||
postprocessor=postprocessor,
|
||||
use_amp=policy.config.use_amp,
|
||||
task=single_task,
|
||||
robot_type=robot.robot_type,
|
||||
acp_inference=acp_inference,
|
||||
cond_runtime_state=cond_policy_runtime_state,
|
||||
uncond_runtime_state=uncond_policy_runtime_state,
|
||||
)
|
||||
act_processed_policy = make_robot_action(policy_action, dataset.features)
|
||||
|
||||
if isinstance(teleop, Teleoperator):
|
||||
act = run_with_connection_retry("teleop.get_action", teleop.get_action)
|
||||
@ -325,7 +329,9 @@ def record_loop(
|
||||
last_teleop_action = act_processed_teleop
|
||||
teleop_fallback_warned = False
|
||||
|
||||
policy_action_for_storage = act_processed_policy if act_processed_policy is not None else zero_policy_action
|
||||
policy_action_for_storage = (
|
||||
act_processed_policy if act_processed_policy is not None else zero_policy_action
|
||||
)
|
||||
|
||||
is_intervention = 0.0
|
||||
if intervention_enabled and intervention_state == INTERVENTION_STATE_ACTIVE:
|
||||
@ -367,12 +373,14 @@ def record_loop(
|
||||
if policy_sync_executor is not None and selected_from_policy:
|
||||
_sent_action = run_with_connection_retry(
|
||||
"policy_sync_executor.send_action",
|
||||
lambda: policy_sync_executor.send_action(robot_action_to_send),
|
||||
lambda robot_action_to_send=robot_action_to_send: policy_sync_executor.send_action(
|
||||
robot_action_to_send
|
||||
),
|
||||
)
|
||||
else:
|
||||
_sent_action = run_with_connection_retry(
|
||||
"robot.send_action",
|
||||
lambda: robot.send_action(robot_action_to_send),
|
||||
lambda robot_action_to_send=robot_action_to_send: robot.send_action(robot_action_to_send),
|
||||
)
|
||||
|
||||
# Write to dataset
|
||||
|
||||
@ -116,15 +116,11 @@ class BiSOLeader(Teleoperator):
|
||||
def send_feedback(self, feedback: dict[str, float]) -> None:
|
||||
# Remove "left_" prefix
|
||||
left_feedback = {
|
||||
key.removeprefix("left_"): value
|
||||
for key, value in feedback.items()
|
||||
if key.startswith("left_")
|
||||
key.removeprefix("left_"): value for key, value in feedback.items() if key.startswith("left_")
|
||||
}
|
||||
# Remove "right_" prefix
|
||||
right_feedback = {
|
||||
key.removeprefix("right_"): value
|
||||
for key, value in feedback.items()
|
||||
if key.startswith("right_")
|
||||
key.removeprefix("right_"): value for key, value in feedback.items() if key.startswith("right_")
|
||||
}
|
||||
|
||||
self.left_arm.send_feedback(left_feedback)
|
||||
|
||||
@ -165,9 +165,7 @@ class SOLeader(Teleoperator):
|
||||
# For phase-A dual-arm execution, reuse leader as a commanded arm by
|
||||
# mapping `{joint}.pos` to motor goal positions.
|
||||
self.set_manual_control(False)
|
||||
goal_pos = {
|
||||
key.removesuffix(".pos"): val for key, val in feedback.items() if key.endswith(".pos")
|
||||
}
|
||||
goal_pos = {key.removesuffix(".pos"): val for key, val in feedback.items() if key.endswith(".pos")}
|
||||
if not goal_pos:
|
||||
return
|
||||
self.bus.sync_write("Goal_Position", goal_pos)
|
||||
|
||||
@ -103,4 +103,3 @@ def resolve_collector_policy_id(
|
||||
if intervention_enabled:
|
||||
return human_id if is_intervention else policy_id
|
||||
return policy_id if selected_from_policy else human_id
|
||||
|
||||
|
||||
@ -1 +1 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python
|
||||
|
||||
@ -12,7 +12,7 @@ from typing import TYPE_CHECKING, Any
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
import torch.nn.functional as F
|
||||
import torch.nn.functional as functional
|
||||
from huggingface_hub import hf_hub_download
|
||||
from huggingface_hub.constants import SAFETENSORS_SINGLE_FILE
|
||||
from huggingface_hub.errors import HfHubHTTPError
|
||||
@ -78,7 +78,7 @@ def project_values_to_bins(values: torch.Tensor, bin_centers: torch.Tensor) -> t
|
||||
|
||||
|
||||
def expected_value_from_logits(logits: torch.Tensor, bin_centers: torch.Tensor) -> torch.Tensor:
|
||||
probs = F.softmax(logits, dim=-1)
|
||||
probs = functional.softmax(logits, dim=-1)
|
||||
return (probs * bin_centers).sum(dim=-1)
|
||||
|
||||
|
||||
@ -198,13 +198,13 @@ def _resolve_image_size(image_processor: Any) -> tuple[int, int]:
|
||||
return 384, 384
|
||||
|
||||
|
||||
def _resolve_norm_stats(image_processor: Any) -> tuple[tuple[float, float, float], tuple[float, float, float]]:
|
||||
def _resolve_norm_stats(
|
||||
image_processor: Any,
|
||||
) -> tuple[tuple[float, float, float], tuple[float, float, float]]:
|
||||
mean_raw = getattr(image_processor, "image_mean", [0.5, 0.5, 0.5])
|
||||
std_raw = getattr(image_processor, "image_std", [0.5, 0.5, 0.5])
|
||||
if len(mean_raw) != 3 or len(std_raw) != 3:
|
||||
raise ValueError(
|
||||
f"Expected RGB normalization stats of len=3, got mean={mean_raw} std={std_raw}."
|
||||
)
|
||||
raise ValueError(f"Expected RGB normalization stats of len=3, got mean={mean_raw} std={std_raw}.")
|
||||
mean = (float(mean_raw[0]), float(mean_raw[1]), float(mean_raw[2]))
|
||||
std = (float(std_raw[0]), float(std_raw[1]), float(std_raw[2]))
|
||||
if any(v <= 0 for v in std):
|
||||
@ -367,7 +367,7 @@ class Pistar06Model(nn.Module):
|
||||
|
||||
flat_images = images.view(bsize * num_cameras, *images.shape[2:])
|
||||
if flat_images.shape[-2:] != self.image_resolution:
|
||||
flat_images = F.interpolate(
|
||||
flat_images = functional.interpolate(
|
||||
flat_images,
|
||||
size=self.image_resolution,
|
||||
mode="bilinear",
|
||||
@ -435,7 +435,9 @@ class Pistar06Model(nn.Module):
|
||||
|
||||
language_context = torch.no_grad() if self.cfg.freeze_language_model else nullcontext()
|
||||
with language_context:
|
||||
language_features = self._encode_language(input_ids=input_ids, attention_mask=language_mask.long())
|
||||
language_features = self._encode_language(
|
||||
input_ids=input_ids, attention_mask=language_mask.long()
|
||||
)
|
||||
|
||||
feature_dtype = torch.float32
|
||||
image_features = image_features.to(dtype=feature_dtype)
|
||||
@ -445,7 +447,9 @@ class Pistar06Model(nn.Module):
|
||||
camera_token_mask = image_attention_mask.unsqueeze(-1).to(dtype=image_tokens.dtype)
|
||||
image_tokens = image_tokens * camera_token_mask
|
||||
|
||||
camera_denominator = image_attention_mask.sum(dim=1, keepdim=True).to(dtype=image_tokens.dtype).clamp_min(1.0)
|
||||
camera_denominator = (
|
||||
image_attention_mask.sum(dim=1, keepdim=True).to(dtype=image_tokens.dtype).clamp_min(1.0)
|
||||
)
|
||||
image_pooled = image_tokens.sum(dim=1) / camera_denominator
|
||||
language_token = self.language_projector(language_features)
|
||||
|
||||
@ -743,7 +747,7 @@ class Pistar06Policy(PreTrainedPolicy):
|
||||
|
||||
bin_centers = self.bin_centers.to(device=device)
|
||||
soft_target = project_values_to_bins(value_target, bin_centers)
|
||||
log_probs = F.log_softmax(logits, dim=-1)
|
||||
log_probs = functional.log_softmax(logits, dim=-1)
|
||||
per_sample_loss = -(soft_target * log_probs).sum(dim=-1)
|
||||
|
||||
sample_weight = None
|
||||
@ -769,13 +773,12 @@ class Pistar06Policy(PreTrainedPolicy):
|
||||
pred_value = expected_value_from_logits(logits, bin_centers)
|
||||
value_mae = (pred_value - value_target).abs().mean()
|
||||
|
||||
if reduction == "none":
|
||||
loss = per_sample_loss
|
||||
else:
|
||||
loss = per_sample_loss.mean()
|
||||
loss = per_sample_loss if reduction == "none" else per_sample_loss.mean()
|
||||
|
||||
loss_dict = {
|
||||
"loss": float(loss.mean().detach().item()) if reduction == "none" else float(loss.detach().item()),
|
||||
"loss": float(loss.mean().detach().item())
|
||||
if reduction == "none"
|
||||
else float(loss.detach().item()),
|
||||
"value_mae": float(value_mae.detach().item()),
|
||||
}
|
||||
if sample_weight is not None:
|
||||
|
||||
@ -8,7 +8,7 @@ from typing import Any
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
import torch.nn.functional as F
|
||||
import torch.nn.functional as functional
|
||||
from torch import Tensor
|
||||
|
||||
from lerobot.configs.types import PipelineFeatureType, PolicyFeature
|
||||
@ -39,7 +39,7 @@ PISTAR06_IMAGE_MASK_KEY = "observation.pistar06.image_attention_mask"
|
||||
def _pad_last_dim(vector: Tensor, new_dim: int) -> Tensor:
|
||||
if vector.shape[-1] >= new_dim:
|
||||
return vector
|
||||
return F.pad(vector, (0, new_dim - vector.shape[-1]))
|
||||
return functional.pad(vector, (0, new_dim - vector.shape[-1]))
|
||||
|
||||
|
||||
@ProcessorStepRegistry.register(name="pistar06_prepare_task_prompt")
|
||||
@ -216,7 +216,7 @@ def make_pistar06_pre_post_processors(
|
||||
]:
|
||||
camera_features = list(config.camera_features)
|
||||
if not camera_features:
|
||||
camera_features = [k for k in (config.input_features or {}).keys() if k.startswith(OBS_IMAGES)]
|
||||
camera_features = [k for k in (config.input_features or {}) if k.startswith(OBS_IMAGES)]
|
||||
|
||||
input_steps: list[ProcessorStep] = [
|
||||
RenameObservationsProcessorStep(rename_map={}),
|
||||
|
||||
在新工单中引用
屏蔽一个用户