Upload so101_stage2_act_005000 folder
Browse files- so101_stage2_act_005000/config.json +71 -0
- so101_stage2_act_005000/inference.json +6 -0
- so101_stage2_act_005000/model.safetensors +3 -0
- so101_stage2_act_005000/policy.py +94 -0
- so101_stage2_act_005000/policy_postprocessor.json +32 -0
- so101_stage2_act_005000/policy_postprocessor_step_0_unnormalizer_processor.safetensors +3 -0
- so101_stage2_act_005000/policy_preprocessor.json +64 -0
- so101_stage2_act_005000/policy_preprocessor_step_3_normalizer_processor.safetensors +3 -0
so101_stage2_act_005000/config.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"type": "act",
|
| 3 |
+
"n_obs_steps": 1,
|
| 4 |
+
"input_features": {
|
| 5 |
+
"observation.state": {
|
| 6 |
+
"type": "STATE",
|
| 7 |
+
"shape": [
|
| 8 |
+
6
|
| 9 |
+
]
|
| 10 |
+
},
|
| 11 |
+
"observation.images.scene": {
|
| 12 |
+
"type": "VISUAL",
|
| 13 |
+
"shape": [
|
| 14 |
+
3,
|
| 15 |
+
480,
|
| 16 |
+
640
|
| 17 |
+
]
|
| 18 |
+
},
|
| 19 |
+
"observation.images.wrist": {
|
| 20 |
+
"type": "VISUAL",
|
| 21 |
+
"shape": [
|
| 22 |
+
3,
|
| 23 |
+
480,
|
| 24 |
+
640
|
| 25 |
+
]
|
| 26 |
+
}
|
| 27 |
+
},
|
| 28 |
+
"output_features": {
|
| 29 |
+
"action": {
|
| 30 |
+
"type": "ACTION",
|
| 31 |
+
"shape": [
|
| 32 |
+
6
|
| 33 |
+
]
|
| 34 |
+
}
|
| 35 |
+
},
|
| 36 |
+
"device": "cuda",
|
| 37 |
+
"use_amp": false,
|
| 38 |
+
"use_peft": false,
|
| 39 |
+
"push_to_hub": false,
|
| 40 |
+
"repo_id": null,
|
| 41 |
+
"private": null,
|
| 42 |
+
"tags": null,
|
| 43 |
+
"license": null,
|
| 44 |
+
"pretrained_path": null,
|
| 45 |
+
"chunk_size": 30,
|
| 46 |
+
"n_action_steps": 30,
|
| 47 |
+
"normalization_mapping": {
|
| 48 |
+
"VISUAL": "MEAN_STD",
|
| 49 |
+
"STATE": "MEAN_STD",
|
| 50 |
+
"ACTION": "MEAN_STD"
|
| 51 |
+
},
|
| 52 |
+
"vision_backbone": "resnet18",
|
| 53 |
+
"pretrained_backbone_weights": "ResNet18_Weights.IMAGENET1K_V1",
|
| 54 |
+
"replace_final_stride_with_dilation": 0,
|
| 55 |
+
"pre_norm": false,
|
| 56 |
+
"dim_model": 512,
|
| 57 |
+
"n_heads": 8,
|
| 58 |
+
"dim_feedforward": 3200,
|
| 59 |
+
"feedforward_activation": "relu",
|
| 60 |
+
"n_encoder_layers": 4,
|
| 61 |
+
"n_decoder_layers": 1,
|
| 62 |
+
"use_vae": true,
|
| 63 |
+
"latent_dim": 32,
|
| 64 |
+
"n_vae_encoder_layers": 4,
|
| 65 |
+
"temporal_ensemble_coeff": null,
|
| 66 |
+
"dropout": 0.1,
|
| 67 |
+
"kl_weight": 10.0,
|
| 68 |
+
"optimizer_lr": 1e-05,
|
| 69 |
+
"optimizer_weight_decay": 0.0001,
|
| 70 |
+
"optimizer_lr_backbone": 1e-05
|
| 71 |
+
}
|
so101_stage2_act_005000/inference.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"n_action_steps": 25,
|
| 3 |
+
"gripper_min": 6.0,
|
| 4 |
+
"gripper_max": 58.0,
|
| 5 |
+
"snap_gripper": false
|
| 6 |
+
}
|
so101_stage2_act_005000/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:213e2eb471c6f6ab9c0020ab7a28a0565c1a3128032ac13886c4aabdb078d758
|
| 3 |
+
size 206413008
|
so101_stage2_act_005000/policy.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
|
| 4 |
+
import numpy as np
|
| 5 |
+
import torch
|
| 6 |
+
|
| 7 |
+
from lerobot.configs.policies import PreTrainedConfig
|
| 8 |
+
from lerobot.policies.factory import get_policy_class, make_pre_post_processors
|
| 9 |
+
|
| 10 |
+
ACCEPTED = ("act",)
|
| 11 |
+
CAMERAS = ("scene", "wrist")
|
| 12 |
+
|
| 13 |
+
JAW_CLOSED_UNITS = 6.49
|
| 14 |
+
JAW_OPEN_UNITS = 42.0
|
| 15 |
+
GRIPPER_MIN_SAFE = 6.0
|
| 16 |
+
GRIPPER_MAX_SAFE = 58.0
|
| 17 |
+
ARM_ABS_LIMIT_DEG = 175.0
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def _select_device() -> str:
|
| 21 |
+
if torch.cuda.is_available():
|
| 22 |
+
return "cuda"
|
| 23 |
+
if hasattr(torch.backends, "mps") and torch.backends.mps.is_available():
|
| 24 |
+
return "mps"
|
| 25 |
+
return "cpu"
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
class Policy:
|
| 29 |
+
def __init__(self, model_dir: str):
|
| 30 |
+
self.device = _select_device()
|
| 31 |
+
settings_path = Path(model_dir) / "inference.json"
|
| 32 |
+
settings = json.loads(settings_path.read_text()) if settings_path.is_file() else {}
|
| 33 |
+
self.chunk_steps = int(settings.get("n_action_steps", 25))
|
| 34 |
+
self.snap_gripper = bool(settings.get("snap_gripper", False))
|
| 35 |
+
self.gripper_min = float(settings.get("gripper_min", GRIPPER_MIN_SAFE))
|
| 36 |
+
self.gripper_max = float(settings.get("gripper_max", GRIPPER_MAX_SAFE))
|
| 37 |
+
|
| 38 |
+
config = PreTrainedConfig.from_pretrained(model_dir)
|
| 39 |
+
if config.type not in ACCEPTED:
|
| 40 |
+
raise ValueError(f"Only ACT is accepted, got {config.type}")
|
| 41 |
+
config.device = self.device
|
| 42 |
+
self.model_type = config.type
|
| 43 |
+
self.policy = get_policy_class(config.type).from_pretrained(model_dir, config=config)
|
| 44 |
+
self.policy.to(self.device)
|
| 45 |
+
self.policy.eval()
|
| 46 |
+
self.pre, self.post = make_pre_post_processors(
|
| 47 |
+
policy_cfg=config,
|
| 48 |
+
pretrained_path=model_dir,
|
| 49 |
+
preprocessor_overrides={"device_processor": {"device": self.device}},
|
| 50 |
+
)
|
| 51 |
+
self.instruction = ""
|
| 52 |
+
if self.device in ("cuda", "mps"):
|
| 53 |
+
dummy_obs = {
|
| 54 |
+
"scene": np.zeros((480, 640, 3), dtype=np.uint8),
|
| 55 |
+
"wrist": np.zeros((480, 640, 3), dtype=np.uint8),
|
| 56 |
+
"joint_state": np.zeros((6,), dtype=np.float32),
|
| 57 |
+
}
|
| 58 |
+
for _ in range(3):
|
| 59 |
+
self.act(dummy_obs)
|
| 60 |
+
if self.device == "cuda":
|
| 61 |
+
torch.cuda.synchronize()
|
| 62 |
+
|
| 63 |
+
def reset(self, task: str = "", instruction: str = ""):
|
| 64 |
+
self.policy.reset()
|
| 65 |
+
self.instruction = instruction
|
| 66 |
+
|
| 67 |
+
def _guard_actions(self, actions: np.ndarray) -> np.ndarray:
|
| 68 |
+
arr = np.asarray(actions, dtype=np.float32).copy()
|
| 69 |
+
arr[..., :5] = np.clip(arr[..., :5], -ARM_ABS_LIMIT_DEG, ARM_ABS_LIMIT_DEG)
|
| 70 |
+
arr[..., 5] = np.clip(arr[..., 5], self.gripper_min, self.gripper_max)
|
| 71 |
+
if self.snap_gripper:
|
| 72 |
+
open_mask = arr[..., 5] > 28.0
|
| 73 |
+
close_mask = arr[..., 5] < 11.0
|
| 74 |
+
arr[..., 5] = np.where(open_mask, np.maximum(arr[..., 5], JAW_OPEN_UNITS), arr[..., 5])
|
| 75 |
+
arr[..., 5] = np.where(close_mask, np.minimum(arr[..., 5], JAW_CLOSED_UNITS), arr[..., 5])
|
| 76 |
+
return arr
|
| 77 |
+
|
| 78 |
+
def act(self, obs: dict) -> np.ndarray:
|
| 79 |
+
batch = {
|
| 80 |
+
"observation.state": torch.as_tensor(obs["joint_state"], dtype=torch.float32, device=self.device).view(1, 6),
|
| 81 |
+
"task": [self.instruction],
|
| 82 |
+
}
|
| 83 |
+
non_blocking = self.device == "cuda"
|
| 84 |
+
for name in CAMERAS:
|
| 85 |
+
rgb = np.ascontiguousarray(obs[name])
|
| 86 |
+
t = torch.from_numpy(rgb).to(device=self.device, non_blocking=non_blocking)
|
| 87 |
+
batch[f"observation.images.{name}"] = t.permute(2, 0, 1).float().mul_(1.0 / 255.0).unsqueeze(0)
|
| 88 |
+
batch = self.pre(batch)
|
| 89 |
+
use_amp = self.device == "cuda"
|
| 90 |
+
with torch.inference_mode(), torch.autocast(device_type="cuda" if use_amp else "cpu", dtype=torch.float16, enabled=use_amp):
|
| 91 |
+
chunk_t = self.policy.predict_action_chunk(batch)
|
| 92 |
+
chunk_np = self.post(chunk_t).detach().cpu().numpy().reshape(-1, 6)
|
| 93 |
+
out = self._guard_actions(chunk_np[: self.chunk_steps])
|
| 94 |
+
return out[0] if self.chunk_steps == 1 else out
|
so101_stage2_act_005000/policy_postprocessor.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "policy_postprocessor",
|
| 3 |
+
"steps": [
|
| 4 |
+
{
|
| 5 |
+
"registry_name": "unnormalizer_processor",
|
| 6 |
+
"config": {
|
| 7 |
+
"eps": 1e-08,
|
| 8 |
+
"features": {
|
| 9 |
+
"action": {
|
| 10 |
+
"type": "ACTION",
|
| 11 |
+
"shape": [
|
| 12 |
+
6
|
| 13 |
+
]
|
| 14 |
+
}
|
| 15 |
+
},
|
| 16 |
+
"norm_map": {
|
| 17 |
+
"VISUAL": "MEAN_STD",
|
| 18 |
+
"STATE": "MEAN_STD",
|
| 19 |
+
"ACTION": "MEAN_STD"
|
| 20 |
+
}
|
| 21 |
+
},
|
| 22 |
+
"state_file": "policy_postprocessor_step_0_unnormalizer_processor.safetensors"
|
| 23 |
+
},
|
| 24 |
+
{
|
| 25 |
+
"registry_name": "device_processor",
|
| 26 |
+
"config": {
|
| 27 |
+
"device": "cpu",
|
| 28 |
+
"float_dtype": null
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
]
|
| 32 |
+
}
|
so101_stage2_act_005000/policy_postprocessor_step_0_unnormalizer_processor.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1354673f9f82c8f9281048fe51dae8f140e99f2305fdb61410668313c007b079
|
| 3 |
+
size 7552
|
so101_stage2_act_005000/policy_preprocessor.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "policy_preprocessor",
|
| 3 |
+
"steps": [
|
| 4 |
+
{
|
| 5 |
+
"registry_name": "rename_observations_processor",
|
| 6 |
+
"config": {
|
| 7 |
+
"rename_map": {}
|
| 8 |
+
}
|
| 9 |
+
},
|
| 10 |
+
{
|
| 11 |
+
"registry_name": "to_batch_processor",
|
| 12 |
+
"config": {}
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"registry_name": "device_processor",
|
| 16 |
+
"config": {
|
| 17 |
+
"device": "cuda",
|
| 18 |
+
"float_dtype": null
|
| 19 |
+
}
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"registry_name": "normalizer_processor",
|
| 23 |
+
"config": {
|
| 24 |
+
"eps": 1e-08,
|
| 25 |
+
"features": {
|
| 26 |
+
"observation.state": {
|
| 27 |
+
"type": "STATE",
|
| 28 |
+
"shape": [
|
| 29 |
+
6
|
| 30 |
+
]
|
| 31 |
+
},
|
| 32 |
+
"observation.images.scene": {
|
| 33 |
+
"type": "VISUAL",
|
| 34 |
+
"shape": [
|
| 35 |
+
3,
|
| 36 |
+
480,
|
| 37 |
+
640
|
| 38 |
+
]
|
| 39 |
+
},
|
| 40 |
+
"observation.images.wrist": {
|
| 41 |
+
"type": "VISUAL",
|
| 42 |
+
"shape": [
|
| 43 |
+
3,
|
| 44 |
+
480,
|
| 45 |
+
640
|
| 46 |
+
]
|
| 47 |
+
},
|
| 48 |
+
"action": {
|
| 49 |
+
"type": "ACTION",
|
| 50 |
+
"shape": [
|
| 51 |
+
6
|
| 52 |
+
]
|
| 53 |
+
}
|
| 54 |
+
},
|
| 55 |
+
"norm_map": {
|
| 56 |
+
"VISUAL": "MEAN_STD",
|
| 57 |
+
"STATE": "MEAN_STD",
|
| 58 |
+
"ACTION": "MEAN_STD"
|
| 59 |
+
}
|
| 60 |
+
},
|
| 61 |
+
"state_file": "policy_preprocessor_step_3_normalizer_processor.safetensors"
|
| 62 |
+
}
|
| 63 |
+
]
|
| 64 |
+
}
|
so101_stage2_act_005000/policy_preprocessor_step_3_normalizer_processor.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1354673f9f82c8f9281048fe51dae8f140e99f2305fdb61410668313c007b079
|
| 3 |
+
size 7552
|