bear-official66 commited on
Commit
6c33912
·
1 Parent(s): 8aa2acf

Add original pairwise ManiSkill evaluation interfaces

Browse files
README.md CHANGED
@@ -13,6 +13,7 @@ ManiSkill 仿真上对多个 VLA 模型做的 **pairwise-OOD / all-factor / conf
13
  README.md ← 本文件:总览 + 结果 + 导航
14
  REPRODUCE.md ← 怎么跑每一类评测(环境/ckpt/命令)
15
  code/ ← 全部评测代码(client / runner / dispatcher)
 
16
  results/
17
  ├─ gr00t/
18
  │ ├─ pairgrid_hard/ 6 实验 × 9 ckpt,硬口径(同色同形干扰项)
 
13
  README.md ← 本文件:总览 + 结果 + 导航
14
  REPRODUCE.md ← 怎么跑每一类评测(环境/ckpt/命令)
15
  code/ ← 全部评测代码(client / runner / dispatcher)
16
+ ├─ pairwise_env.py 四类原始 pairwise 环境统一接口
17
  results/
18
  ├─ gr00t/
19
  │ ├─ pairgrid_hard/ 6 实验 × 9 ckpt,硬口径(同色同形干扰项)
REPRODUCE.md CHANGED
@@ -25,6 +25,46 @@ all-factor、conflict、VLM 评测的**可复现全集**(除 checkpoint 权重
25
 
26
  ## 0. 准备
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  ### 0.1 仿真就位(代码已是文件夹,可在线浏览;仅二进制 3D 资源是 tar)
29
  ```bash
30
  # 代码已在 simulation/eval_simulation/ 与 simulation/Maniskill_gen_new/(文件夹,可直接看)
 
25
 
26
  ## 0. 准备
27
 
28
+ ### 0.0 四类原始 pairwise ManiSkill 环境接口
29
+
30
+ `code/pairwise_env.py` 是不依赖具体模型的统一入口,覆盖:
31
+
32
+ - `verb_color`: 6 verbs × 6 colors,shape 从 `cube/sphere/cup` 采样;
33
+ - `color_object`: 6 colors × 6 shapes,verb 从 `lift/grasp/push` 采样;
34
+ - `verb_object`: 6 verbs × 6 shapes,color 从 `red/yellow/blue` 采样;
35
+ - `verb_size`: 6 verbs × 6 size labels,固定 red cube。
36
+
37
+ 列出某类实验的全部 36 个 cell:
38
+
39
+ ```bash
40
+ python code/pairwise_env.py verb_color --seed 42 --third-pool-size 2
41
+ python code/pairwise_env.py color_object --seed 42 --third-pool-size 2
42
+ python code/pairwise_env.py verb_object --seed 42 --third-pool-size 2
43
+ python code/pairwise_env.py verb_size --seed 42
44
+ ```
45
+
46
+ 额外创建环境并执行一次 reset(验证 `VerbObjectColor-v1` 注册、资源和参数):
47
+
48
+ ```bash
49
+ python code/pairwise_env.py verb_color --smoke-reset --sim-backend cpu
50
+ ```
51
+
52
+ 模型 runner 可直接 import:
53
+
54
+ ```python
55
+ from pairwise_env import build_cell, make_env
56
+
57
+ cell = build_cell("verb_color", "lift", "red", seed=42)
58
+ env = make_env(cell)
59
+ obs, info = env.reset(seed=42, options=cell.reset_options)
60
+ instruction = cell.instruction
61
+ ```
62
+
63
+ 环境实现位于
64
+ `simulation/eval_simulation/simulation/mani_skill/envs/tasks/tabletop/verb_object_color_env.py`;
65
+ factor vocab 和原始采集定义位于
66
+ `simulation/Maniskill_gen_new/collection_strategy/`。
67
+
68
  ### 0.1 仿真就位(代码已是文件夹,可在线浏览;仅二进制 3D 资源是 tar)
69
  ```bash
70
  # 代码已在 simulation/eval_simulation/ 与 simulation/Maniskill_gen_new/(文件夹,可直接看)
code/pairwise_env.py ADDED
@@ -0,0 +1,217 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Unified ManiSkill interface for the four original pairwise evaluation grids.
3
+
4
+ This module contains no model-specific code. A policy evaluator can call
5
+ ``build_cell`` and receive a registered ``VerbObjectColor-v1`` environment,
6
+ the reset options, and the natural-language instruction.
7
+
8
+ Grids:
9
+ verb_color: verb(6) x color(6), shape sampled from cube/sphere/cup
10
+ color_object: color(6) x shape(6), verb sampled from lift/grasp/push
11
+ verb_object: verb(6) x shape(6), color sampled from red/yellow/blue
12
+ verb_size: verb(6) x size(6), fixed red cube
13
+ """
14
+ from __future__ import annotations
15
+
16
+ import argparse
17
+ import dataclasses
18
+ import os
19
+ import pathlib
20
+ import random
21
+ import sys
22
+ from typing import Any
23
+
24
+
25
+ REPO_ROOT = pathlib.Path(__file__).resolve().parents[1]
26
+ SIM_ROOT = pathlib.Path(
27
+ os.environ.get(
28
+ "SIM_ROOT", REPO_ROOT / "simulation/eval_simulation/simulation"
29
+ )
30
+ )
31
+ MGEN_ROOT = pathlib.Path(
32
+ os.environ.get("MGEN_ROOT", REPO_ROOT / "simulation/Maniskill_gen_new")
33
+ )
34
+ for _path in (SIM_ROOT, MGEN_ROOT):
35
+ if str(_path) not in sys.path:
36
+ sys.path.insert(0, str(_path))
37
+
38
+ import gymnasium as gym # noqa: E402
39
+ import mani_skill.envs # noqa: E402,F401 - registers VerbObjectColor-v1
40
+
41
+ from collection_strategy.lib.pairwise_task_language import VERB_TO_EN # noqa: E402
42
+ from collection_strategy.lib.training_vocab import ( # noqa: E402
43
+ THIRD_COLORS_FOR_VERB_OBJECT,
44
+ THIRD_OBJECTS_FOR_VERB_COLOR,
45
+ THIRD_VERBS_FOR_COLOR_OBJECT,
46
+ TRAINING_COLORS,
47
+ TRAINING_SHAPES,
48
+ TRAINING_VERBS,
49
+ )
50
+
51
+
52
+ EXPERIMENTS = ("verb_color", "color_object", "verb_object", "verb_size")
53
+ SIZES = ("small", "large", "smaller", "larger", "smallest", "largest")
54
+ COLOR_TO_ID = {color: i for i, color in enumerate(TRAINING_COLORS)}
55
+ SIZE_CONFIG = {
56
+ "small": (0.72, [], 0),
57
+ "large": (1.34, [], 0),
58
+ "smaller": (0.82, [1.08], 1),
59
+ "larger": (1.18, [0.92], 1),
60
+ "smallest": (0.78, [1.00, 1.24], 2),
61
+ "largest": (1.26, [1.00, 0.80], 2),
62
+ }
63
+
64
+
65
+ @dataclasses.dataclass(frozen=True)
66
+ class Cell:
67
+ experiment: str
68
+ factor_a: str
69
+ factor_b: str
70
+ verb: str
71
+ color: str
72
+ shape: str
73
+ instruction: str
74
+ make_kwargs: dict[str, Any]
75
+ reset_options: dict[str, Any]
76
+
77
+
78
+ def factor_values(experiment: str) -> tuple[tuple[str, ...], tuple[str, ...]]:
79
+ """Return the two ordered axes of an evaluation grid."""
80
+ if experiment == "verb_color":
81
+ return TRAINING_VERBS, TRAINING_COLORS
82
+ if experiment == "color_object":
83
+ return TRAINING_COLORS, TRAINING_SHAPES
84
+ if experiment == "verb_object":
85
+ return TRAINING_VERBS, TRAINING_SHAPES
86
+ if experiment == "verb_size":
87
+ return TRAINING_VERBS, SIZES
88
+ raise ValueError(f"unknown experiment {experiment!r}; choose from {EXPERIMENTS}")
89
+
90
+
91
+ def build_cell(
92
+ experiment: str,
93
+ factor_a: str,
94
+ factor_b: str,
95
+ *,
96
+ seed: int = 42,
97
+ third_pool_size: int = 2,
98
+ sim_backend: str = "cpu",
99
+ max_episode_steps: int = 200,
100
+ task_difficulty: float = 1.0,
101
+ ) -> Cell:
102
+ """Materialize one grid cell using the original evaluation conventions."""
103
+ rng = random.Random(seed)
104
+ pool_n = max(1, int(third_pool_size))
105
+ reset_options: dict[str, Any] = {}
106
+
107
+ if experiment == "verb_color":
108
+ verb, color = factor_a, factor_b
109
+ shape = rng.choice(THIRD_OBJECTS_FOR_VERB_COLOR[:pool_n])
110
+ elif experiment == "color_object":
111
+ color, shape = factor_a, factor_b
112
+ verb = rng.choice(THIRD_VERBS_FOR_COLOR_OBJECT[:pool_n])
113
+ elif experiment == "verb_object":
114
+ verb, shape = factor_a, factor_b
115
+ color = rng.choice(THIRD_COLORS_FOR_VERB_OBJECT[:pool_n])
116
+ elif experiment == "verb_size":
117
+ verb, size = factor_a, factor_b
118
+ color, shape = "red", "cube"
119
+ target_scale, distractor_scales, num_distractors = SIZE_CONFIG[size]
120
+ reset_options = {
121
+ "num_distractors": num_distractors,
122
+ "target_size_scale": target_scale,
123
+ "distractor_size_scales": distractor_scales,
124
+ }
125
+ else:
126
+ raise ValueError(f"unknown experiment {experiment!r}; choose from {EXPERIMENTS}")
127
+
128
+ axes = factor_values(experiment)
129
+ if factor_a not in axes[0] or factor_b not in axes[1]:
130
+ raise ValueError(
131
+ f"invalid {experiment} cell ({factor_a!r}, {factor_b!r}); axes={axes}"
132
+ )
133
+
134
+ instruction = VERB_TO_EN[verb].format(color=color, shape=shape)
135
+ if experiment == "verb_size":
136
+ instruction = f"{verb.capitalize()} the {factor_b} {color} {shape}."
137
+
138
+ distractor_max = max(2, int(reset_options.get("num_distractors", 0)))
139
+ make_kwargs = {
140
+ "obs_mode": "rgb",
141
+ "control_mode": "pd_joint_pos",
142
+ "sim_backend": sim_backend,
143
+ "render_backend": sim_backend,
144
+ "max_episode_steps": max_episode_steps,
145
+ "task_difficulty": task_difficulty,
146
+ "verb": verb,
147
+ "object_shape": shape,
148
+ "object_color_id": COLOR_TO_ID[color],
149
+ "distractor_max": distractor_max,
150
+ }
151
+ if experiment == "verb_size":
152
+ make_kwargs.update(
153
+ object_size_jiggle=0.0,
154
+ target_size_scale=target_scale,
155
+ distractor_size_scales=distractor_scales,
156
+ distractor_specs=[("cube", COLOR_TO_ID[color])] * num_distractors
157
+ + [None] * (3 - num_distractors),
158
+ )
159
+ return Cell(
160
+ experiment=experiment,
161
+ factor_a=factor_a,
162
+ factor_b=factor_b,
163
+ verb=verb,
164
+ color=color,
165
+ shape=shape,
166
+ instruction=instruction,
167
+ make_kwargs=make_kwargs,
168
+ reset_options=reset_options,
169
+ )
170
+
171
+
172
+ def make_env(cell: Cell) -> gym.Env:
173
+ """Construct the registered environment for a materialized cell."""
174
+ return gym.make("VerbObjectColor-v1", **cell.make_kwargs)
175
+
176
+
177
+ def iter_grid(experiment: str, **kwargs: Any):
178
+ """Yield all 36 cells in stable row-major order."""
179
+ axis_a, axis_b = factor_values(experiment)
180
+ for a in axis_a:
181
+ for b in axis_b:
182
+ yield build_cell(experiment, a, b, **kwargs)
183
+
184
+
185
+ def main() -> None:
186
+ parser = argparse.ArgumentParser(description=__doc__)
187
+ parser.add_argument("experiment", choices=EXPERIMENTS)
188
+ parser.add_argument("--seed", type=int, default=42)
189
+ parser.add_argument("--third-pool-size", type=int, default=2)
190
+ parser.add_argument("--smoke-reset", action="store_true")
191
+ parser.add_argument("--sim-backend", default="cpu", choices=("cpu", "gpu"))
192
+ args = parser.parse_args()
193
+
194
+ cells = list(
195
+ iter_grid(
196
+ args.experiment,
197
+ seed=args.seed,
198
+ third_pool_size=args.third_pool_size,
199
+ sim_backend=args.sim_backend,
200
+ )
201
+ )
202
+ print(f"{args.experiment}: {len(cells)} cells")
203
+ for index, cell in enumerate(cells, 1):
204
+ print(index, cell.factor_a, cell.factor_b, "->", cell.instruction)
205
+
206
+ if args.smoke_reset:
207
+ cell = cells[0]
208
+ env = make_env(cell)
209
+ try:
210
+ obs, info = env.reset(seed=args.seed, options=cell.reset_options)
211
+ print("SMOKE_RESET_OK", sorted(obs), sorted(info))
212
+ finally:
213
+ env.close()
214
+
215
+
216
+ if __name__ == "__main__":
217
+ main()
simulation/eval_simulation/simulation/mani_skill/envs/tasks/tabletop/verb_object_color_env.py CHANGED
@@ -139,6 +139,8 @@ class VerbObjectColorEnv(BaseEnv):
139
  object_color_id: int = 0,
140
  distractor_max: int = 3,
141
  object_size_jiggle: float = 0.2,
 
 
142
  task_difficulty: float = 1.0,
143
  show_goal_site: bool = False,
144
  reconfiguration_freq: Optional[int] = None,
@@ -161,6 +163,14 @@ class VerbObjectColorEnv(BaseEnv):
161
  )
162
  self.distractor_max = max(0, min(3, int(distractor_max)))
163
  self.object_size_jiggle = max(0.0, float(object_size_jiggle))
 
 
 
 
 
 
 
 
164
  self.task_difficulty = float(np.clip(float(task_difficulty), 0.5, 3.0))
165
  self.show_goal_site = show_goal_site
166
  self.object_color = OBJECT_COLORS_VERB[self.object_color_id]
@@ -257,7 +267,11 @@ class VerbObjectColorEnv(BaseEnv):
257
  self.object_shape,
258
  self.object_color,
259
  name="target_obj",
260
- size_scale=self._sample_tabletop_size_scale(),
 
 
 
 
261
  )
262
  # Alias for motion-planning code that expects ``cube``
263
  self.cube = self.obj
@@ -301,12 +315,16 @@ class VerbObjectColorEnv(BaseEnv):
301
  else:
302
  sh, cid = self._sample_distractor_shape_color_id()
303
  col = OBJECT_COLORS_VERB[cid]
 
 
 
 
304
  act, rz = build_tabletop_object(
305
  self.scene,
306
  sh,
307
  col,
308
  name=f"distractor_{i}",
309
- size_scale=self._sample_tabletop_size_scale(),
310
  )
311
  self.distractor_actors.append(act)
312
  self._distractor_rest_z.append(rz)
 
139
  object_color_id: int = 0,
140
  distractor_max: int = 3,
141
  object_size_jiggle: float = 0.2,
142
+ target_size_scale: float | None = None,
143
+ distractor_size_scales: list[float] | tuple[float, ...] | None = None,
144
  task_difficulty: float = 1.0,
145
  show_goal_site: bool = False,
146
  reconfiguration_freq: Optional[int] = None,
 
163
  )
164
  self.distractor_max = max(0, min(3, int(distractor_max)))
165
  self.object_size_jiggle = max(0.0, float(object_size_jiggle))
166
+ self.target_size_scale = (
167
+ None if target_size_scale is None else max(0.2, float(target_size_scale))
168
+ )
169
+ self.distractor_size_scales = (
170
+ None
171
+ if distractor_size_scales is None
172
+ else [max(0.2, float(x)) for x in distractor_size_scales]
173
+ )
174
  self.task_difficulty = float(np.clip(float(task_difficulty), 0.5, 3.0))
175
  self.show_goal_site = show_goal_site
176
  self.object_color = OBJECT_COLORS_VERB[self.object_color_id]
 
267
  self.object_shape,
268
  self.object_color,
269
  name="target_obj",
270
+ size_scale=(
271
+ self.target_size_scale
272
+ if self.target_size_scale is not None
273
+ else self._sample_tabletop_size_scale()
274
+ ),
275
  )
276
  # Alias for motion-planning code that expects ``cube``
277
  self.cube = self.obj
 
315
  else:
316
  sh, cid = self._sample_distractor_shape_color_id()
317
  col = OBJECT_COLORS_VERB[cid]
318
+ if self.distractor_size_scales is not None and i < len(self.distractor_size_scales):
319
+ d_scale = self.distractor_size_scales[i]
320
+ else:
321
+ d_scale = self._sample_tabletop_size_scale()
322
  act, rz = build_tabletop_object(
323
  self.scene,
324
  sh,
325
  col,
326
  name=f"distractor_{i}",
327
+ size_scale=d_scale,
328
  )
329
  self.distractor_actors.append(act)
330
  self._distractor_rest_z.append(rz)