forked from longtao.wu/droboticflow
✨ Add GraspNet dataset validator
This commit is contained in:
parent
4da6713556
commit
b2ec48ce8a
@ -52,6 +52,7 @@ from backend.operators.builtin.dexycb_dataset_validate import operator as dexycb
|
||||
from backend.operators.builtin.embodiment_metadata_validate import operator as embodiment_metadata_validate_operator
|
||||
from backend.operators.builtin.force_torque_sensor_validate import operator as force_torque_sensor_validate_operator
|
||||
from backend.operators.builtin.furniturebench_pkl_demonstration_validate import operator as furniturebench_pkl_demonstration_validate_operator
|
||||
from backend.operators.builtin.graspnet_dataset_validate import operator as graspnet_dataset_validate_operator
|
||||
from backend.operators.builtin.human_review import operator as human_review_operator
|
||||
from backend.operators.builtin.hdf5_demonstration_summary import operator as hdf5_demonstration_summary_operator
|
||||
from backend.operators.builtin.hf_dataset_probe import operator as hf_dataset_probe_operator
|
||||
@ -5014,6 +5015,7 @@ BUILTIN_HANDLER_RULES: tuple[tuple[str, tuple[str, ...]], ...] = (
|
||||
("camera_calibration_validate", ("相机标定校验", "camera calibration", "intrinsics", "extrinsics")),
|
||||
("tf_transform_tree_validate", ("tf 坐标树", "transform tree", "tf tree", "坐标树校验", "frametree")),
|
||||
("ros_joint_state_validate", ("ros jointstate", "jointstate", "joint state", "joint_states", "ros 关节状态")),
|
||||
("graspnet_dataset_validate", ("graspnet", "graspnet-1billion", "抓取数据集", "6d grasp", "general object grasping")),
|
||||
("bop_dataset_validate", ("bop 6d", "bop 数据集", "bop dataset", "6d姿态", "6d pose", "object pose benchmark")),
|
||||
("dexycb_dataset_validate", ("dexycb 数据集", "dex-ycb", "dexycb", "ycb hand", "hand grasping object")),
|
||||
("ho3d_dataset_validate", ("ho3d 数据集", "ho-3d", "ho3d", "h2o3d", "h2o-3d", "honnotate")),
|
||||
@ -5109,6 +5111,7 @@ BUILTIN_HANDLERS: dict[str, BuiltinHandler] = {
|
||||
"mcap_topic_summary": operator_handler(mcap_topic_summary_operator),
|
||||
"tfrecord_structural_validate": operator_handler(tfrecord_structural_validate_operator),
|
||||
"dataset_provenance_audit": operator_handler(dataset_provenance_audit_operator),
|
||||
"graspnet_dataset_validate": operator_handler(graspnet_dataset_validate_operator),
|
||||
"bop_dataset_validate": operator_handler(bop_dataset_validate_operator),
|
||||
"dexycb_dataset_validate": operator_handler(dexycb_dataset_validate_operator),
|
||||
"ho3d_dataset_validate": operator_handler(ho3d_dataset_validate_operator),
|
||||
|
||||
@ -267,6 +267,7 @@ class RuntimeFileContractTests(unittest.TestCase):
|
||||
self.assertEqual(MODULE.select_handler("TF 坐标树校验"), "tf_transform_tree_validate")
|
||||
self.assertEqual(MODULE.select_handler("LeRobot 视频对齐校验"), "lerobot_video_alignment_validate")
|
||||
self.assertEqual(MODULE.select_handler("ROS JointState 校验"), "ros_joint_state_validate")
|
||||
self.assertEqual(MODULE.select_handler("GraspNet 抓取数据集校验"), "graspnet_dataset_validate")
|
||||
self.assertEqual(MODULE.select_handler("BOP 6D姿态数据集校验"), "bop_dataset_validate")
|
||||
self.assertEqual(MODULE.select_handler("DexYCB 数据集校验"), "dexycb_dataset_validate")
|
||||
self.assertEqual(MODULE.select_handler("HO3D/H2O3D 数据集校验"), "ho3d_dataset_validate")
|
||||
@ -4982,6 +4983,90 @@ class EmbodiedDatasetOperatorTests(unittest.TestCase):
|
||||
self.assertEqual(image["depthPath"], "train_pbr/000000/depth/000000.png")
|
||||
self.assertEqual(image["annotationCount"], 1)
|
||||
|
||||
def test_graspnet_dataset_validate_reads_scene_grasp_and_collision_labels(self):
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
import numpy as np
|
||||
|
||||
root = pathlib.Path(temp_dir) / "graspnet"
|
||||
scene_dir = root / "scenes" / "scene_0000"
|
||||
camera_dir = scene_dir / "kinect"
|
||||
for folder in ("rgb", "depth", "label", "meta", "annotations", "rect"):
|
||||
(camera_dir / folder).mkdir(parents=True)
|
||||
(root / "models" / "001").mkdir(parents=True)
|
||||
(root / "grasp_label").mkdir(parents=True)
|
||||
(root / "collision_label" / "scene_0000").mkdir(parents=True)
|
||||
|
||||
(scene_dir / "object_id_list.txt").write_text("1\n", encoding="utf-8")
|
||||
np.save(scene_dir / "rs_wrt_kn.npy", np.eye(4, dtype=np.float32))
|
||||
np.save(camera_dir / "camK.npy", np.eye(3, dtype=np.float32))
|
||||
np.save(camera_dir / "cam0_wrt_table.npy", np.eye(4, dtype=np.float32))
|
||||
np.save(camera_dir / "camera_poses.npy", np.eye(4, dtype=np.float32)[None, :, :])
|
||||
for name in ("nontextured.ply", "textured.obj", "textured.sdf"):
|
||||
(root / "models" / "001" / name).write_text("real-graspnet-model-file\n", encoding="utf-8")
|
||||
points = np.zeros((2, 3), dtype=np.float32)
|
||||
offsets = np.zeros((2, 300, 12, 4, 3), dtype=np.float32)
|
||||
scores = np.ones((2, 300, 12, 4), dtype=np.float32)
|
||||
collision = np.zeros((2, 300, 12, 4), dtype=bool)
|
||||
np.savez(root / "grasp_label" / "001_labels.npz", points=points, offsets=offsets, scores=scores, collision=collision)
|
||||
np.savez(root / "collision_label" / "scene_0000" / "collision_labels.npz", arr_0=collision)
|
||||
np.save(camera_dir / "rect" / "0000.npy", np.zeros((1, 8), dtype=np.float32))
|
||||
png = b"\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x04\x00\x00\x00\x03\x08\x02"
|
||||
for relative in ("rgb/0000.png", "depth/0000.png", "label/0000.png"):
|
||||
(camera_dir / relative).write_bytes(png)
|
||||
(camera_dir / "meta" / "0000.mat").write_bytes(b"MATLAB 5.0 MAT-file, Platform: test")
|
||||
(camera_dir / "annotations" / "0000.xml").write_text(
|
||||
"<annotation><object><id>1</id><pose>1 0 0 0 0 1 0 0 0 0 1 0</pose></object></annotation>",
|
||||
encoding="utf-8",
|
||||
)
|
||||
node_data = {
|
||||
"label": "GraspNet 抓取数据集校验",
|
||||
"hyperparams": [
|
||||
{"key": "SOURCE_PATH", "value": str(root)},
|
||||
{"key": "CAMERA", "value": "kinect"},
|
||||
{"key": "MAX_SCENES", "value": "2"},
|
||||
{"key": "MAX_FRAMES_PER_CAMERA", "value": "4"},
|
||||
{"key": "REQUIRE_RECT_LABELS", "value": "true"},
|
||||
],
|
||||
}
|
||||
|
||||
artifacts = MODULE.BUILTIN_HANDLERS["graspnet_dataset_validate"](
|
||||
"run-1", "graspnet", root / "out", node_data, []
|
||||
)
|
||||
|
||||
payload = MODULE.load_artifact_payload(artifacts[0])
|
||||
self.assertEqual(payload["datasetType"], "graspnet-dataset-validation")
|
||||
self.assertTrue(payload["valid"])
|
||||
self.assertEqual(payload["issueCount"], 0)
|
||||
self.assertEqual(payload["sceneCount"], 1)
|
||||
self.assertEqual(payload["validSceneCount"], 1)
|
||||
self.assertEqual(payload["cameraCount"], 1)
|
||||
self.assertEqual(payload["frameCount"], 1)
|
||||
self.assertEqual(payload["validFrameCount"], 1)
|
||||
self.assertEqual(payload["objectCount"], 1)
|
||||
self.assertEqual(payload["objectCounts"], {"1": 1})
|
||||
self.assertEqual(payload["splitCounts"], {"train": 1})
|
||||
self.assertTrue(payload["assets"]["hasScenesDir"])
|
||||
self.assertTrue(payload["assets"]["hasModelsDir"])
|
||||
self.assertTrue(payload["assets"]["hasGraspLabelDir"])
|
||||
self.assertTrue(payload["assets"]["hasCollisionLabelDir"])
|
||||
self.assertEqual(payload["assets"]["modelObjectCount"], 1)
|
||||
self.assertEqual(payload["assets"]["graspLabelObjectCount"], 1)
|
||||
scene = payload["scenes"][0]
|
||||
self.assertEqual(scene["sceneId"], "scene_0000")
|
||||
self.assertEqual(scene["objectIds"], [1])
|
||||
self.assertEqual(scene["collisionLabel"]["path"], "collision_label/scene_0000/collision_labels.npz")
|
||||
camera = scene["cameras"][0]
|
||||
self.assertEqual(camera["camera"], "kinect")
|
||||
self.assertEqual(camera["camK"]["shape"], [3, 3])
|
||||
self.assertEqual(camera["cameraPoses"]["shape"], [1, 4, 4])
|
||||
frame = camera["frames"][0]
|
||||
self.assertEqual(frame["annId"], 0)
|
||||
self.assertEqual(frame["rgb"]["path"], "scenes/scene_0000/kinect/rgb/0000.png")
|
||||
self.assertEqual(frame["depth"]["width"], 4)
|
||||
self.assertEqual(frame["label"]["height"], 3)
|
||||
self.assertEqual(frame["annotation"]["objectLikeElementCount"], 2)
|
||||
self.assertEqual(frame["rect"]["shape"], [1, 8])
|
||||
|
||||
def test_ho3d_dataset_validate_reads_meta_pickle_and_media_pairs(self):
|
||||
try:
|
||||
import cv2 # type: ignore
|
||||
|
||||
@ -0,0 +1 @@
|
||||
"""GraspNet-1Billion dataset validation operator."""
|
||||
@ -0,0 +1,16 @@
|
||||
{
|
||||
"id": "operator-builtin-graspnet-dataset-validate",
|
||||
"name": "GraspNet 抓取数据集校验",
|
||||
"category": "ROBOTICS",
|
||||
"type": "builtin",
|
||||
"runtimeHandler": "builtin_graspnet_dataset_validate",
|
||||
"runtimeSource": "backend/operators/builtin/graspnet_dataset_validate/operator.py",
|
||||
"migrationStatus": "migrated",
|
||||
"acceptance": {
|
||||
"requiresRealInputs": true,
|
||||
"mockOnlyAccepted": false,
|
||||
"simulationOnlyAccepted": false,
|
||||
"hardcodedOutputAccepted": false,
|
||||
"shallowOnlyAccepted": false
|
||||
}
|
||||
}
|
||||
591
backend/operators/builtin/graspnet_dataset_validate/operator.py
Normal file
591
backend/operators/builtin/graspnet_dataset_validate/operator.py
Normal file
@ -0,0 +1,591 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import io
|
||||
import pathlib
|
||||
import struct
|
||||
import xml.etree.ElementTree as ET
|
||||
import zipfile
|
||||
from typing import Any, Callable
|
||||
|
||||
try:
|
||||
import numpy as np
|
||||
except Exception as exc: # pragma: no cover - exercised when runtime dependency is missing.
|
||||
raise RuntimeError("GraspNet 抓取数据集校验需要 numpy 读取真实 .npy/.npz 标注文件") from exc
|
||||
|
||||
|
||||
HelperMap = dict[str, Callable[..., Any]]
|
||||
CAMERA_NAMES = ("kinect", "realsense")
|
||||
PNG_SIGNATURE = b"\x89PNG\r\n\x1a\n"
|
||||
|
||||
|
||||
def _positive_int(params: dict[str, str], key: str, default: int) -> int:
|
||||
raw = str(params.get(key, str(default)) or str(default)).strip()
|
||||
try:
|
||||
value = int(raw)
|
||||
except ValueError as exc:
|
||||
raise RuntimeError(f"{key} must be an integer") from exc
|
||||
if value <= 0:
|
||||
raise RuntimeError(f"{key} must be > 0")
|
||||
return value
|
||||
|
||||
|
||||
def _bool_param(helpers: HelperMap, params: dict[str, str], key: str, default: bool) -> bool:
|
||||
return bool(helpers["parse_bool_param"](params, key, default))
|
||||
|
||||
|
||||
def _relative(path: pathlib.Path | None, root: pathlib.Path) -> str:
|
||||
if path is None:
|
||||
return ""
|
||||
try:
|
||||
return path.relative_to(root).as_posix()
|
||||
except ValueError:
|
||||
return str(path)
|
||||
|
||||
|
||||
def _camera_filter(params: dict[str, str]) -> tuple[str, ...]:
|
||||
value = str(params.get("CAMERA", "any") or "any").strip().lower()
|
||||
if value in {"", "any", "all", "*"}:
|
||||
return CAMERA_NAMES
|
||||
requested = tuple(item.strip() for item in value.split(",") if item.strip())
|
||||
invalid = [item for item in requested if item not in CAMERA_NAMES]
|
||||
if invalid:
|
||||
raise RuntimeError("CAMERA must be any, kinect, realsense, or a comma-separated subset")
|
||||
return requested or CAMERA_NAMES
|
||||
|
||||
|
||||
def _is_scene_dir(path: pathlib.Path) -> bool:
|
||||
if not path.is_dir() or not path.name.startswith("scene_"):
|
||||
return False
|
||||
return (path / "object_id_list.txt").is_file() or any((path / camera).is_dir() for camera in CAMERA_NAMES)
|
||||
|
||||
|
||||
def _source_scene_dir(path: pathlib.Path) -> pathlib.Path | None:
|
||||
if _is_scene_dir(path):
|
||||
return path
|
||||
if path.name in CAMERA_NAMES and _is_scene_dir(path.parent):
|
||||
return path.parent
|
||||
if path.is_file() and _is_scene_dir(path.parent):
|
||||
return path.parent
|
||||
if path.is_file() and path.parent.name in CAMERA_NAMES and _is_scene_dir(path.parent.parent):
|
||||
return path.parent.parent
|
||||
return None
|
||||
|
||||
|
||||
def _find_scene_dirs(source_path: pathlib.Path, max_scenes: int) -> list[pathlib.Path]:
|
||||
scene_dir = _source_scene_dir(source_path)
|
||||
if scene_dir is not None:
|
||||
return [scene_dir]
|
||||
if source_path.is_file():
|
||||
return []
|
||||
scenes_root = source_path / "scenes"
|
||||
if scenes_root.is_dir():
|
||||
return [path for path in sorted(scenes_root.iterdir()) if _is_scene_dir(path)][:max_scenes]
|
||||
return [path for path in sorted(source_path.rglob("scene_*")) if _is_scene_dir(path)][:max_scenes]
|
||||
|
||||
|
||||
def _dataset_root(source_path: pathlib.Path, scene_dirs: list[pathlib.Path]) -> pathlib.Path:
|
||||
base = source_path if source_path.is_dir() else source_path.parent
|
||||
for candidate in [base, *base.parents]:
|
||||
if (candidate / "scenes").is_dir() or (candidate / "models").is_dir() or (candidate / "grasp_label").is_dir():
|
||||
return candidate
|
||||
if scene_dirs:
|
||||
for parent in scene_dirs[0].parents:
|
||||
if parent.name == "scenes":
|
||||
return parent.parent
|
||||
return base
|
||||
|
||||
|
||||
def _scene_id(scene_dir: pathlib.Path) -> int | None:
|
||||
try:
|
||||
return int(scene_dir.name.removeprefix("scene_"))
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
|
||||
def _scene_split(scene_id: int | None) -> str:
|
||||
if scene_id is None:
|
||||
return "custom"
|
||||
if 0 <= scene_id < 100:
|
||||
return "train"
|
||||
if 100 <= scene_id < 130:
|
||||
return "test_seen"
|
||||
if 130 <= scene_id < 160:
|
||||
return "test_similar"
|
||||
if 160 <= scene_id < 190:
|
||||
return "test_novel"
|
||||
return "custom"
|
||||
|
||||
|
||||
def _read_object_ids(path: pathlib.Path, root: pathlib.Path, required: bool) -> tuple[list[int], list[dict[str, Any]]]:
|
||||
if not path.is_file():
|
||||
return [], ([{"code": "missing_object_id_list", "path": _relative(path, root)}] if required else [])
|
||||
issues: list[dict[str, Any]] = []
|
||||
object_ids: list[int] = []
|
||||
for line_number, raw in enumerate(path.read_text(encoding="utf-8", errors="replace").splitlines(), start=1):
|
||||
value = raw.strip()
|
||||
if not value:
|
||||
continue
|
||||
try:
|
||||
object_id = int(value)
|
||||
except ValueError:
|
||||
issues.append({"code": "object_id_not_integer", "line": line_number, "value": value})
|
||||
continue
|
||||
if object_id < 0:
|
||||
issues.append({"code": "object_id_negative", "line": line_number, "value": object_id})
|
||||
continue
|
||||
object_ids.append(object_id)
|
||||
if not object_ids:
|
||||
issues.append({"code": "object_id_list_empty", "path": _relative(path, root)})
|
||||
return object_ids, issues
|
||||
|
||||
|
||||
def _read_npy_header(handle: Any) -> dict[str, Any]:
|
||||
version = np.lib.format.read_magic(handle)
|
||||
if version == (1, 0):
|
||||
shape, fortran_order, dtype = np.lib.format.read_array_header_1_0(handle)
|
||||
elif version == (2, 0):
|
||||
shape, fortran_order, dtype = np.lib.format.read_array_header_2_0(handle)
|
||||
else:
|
||||
shape, fortran_order, dtype = np.lib.format._read_array_header(handle, version, max_header_size=100000)
|
||||
return {"shape": list(shape), "fortranOrder": bool(fortran_order), "dtype": str(dtype)}
|
||||
|
||||
|
||||
def _npy_header_from_file(path: pathlib.Path) -> dict[str, Any]:
|
||||
with path.open("rb") as handle:
|
||||
return _read_npy_header(handle)
|
||||
|
||||
|
||||
def _npz_headers(path: pathlib.Path) -> dict[str, dict[str, Any]]:
|
||||
result: dict[str, dict[str, Any]] = {}
|
||||
with zipfile.ZipFile(path) as archive:
|
||||
for info in archive.infolist():
|
||||
if info.is_dir() or not info.filename.endswith(".npy"):
|
||||
continue
|
||||
key = pathlib.PurePosixPath(info.filename).name.removesuffix(".npy")
|
||||
with archive.open(info) as handle:
|
||||
result[key] = _read_npy_header(handle)
|
||||
return result
|
||||
|
||||
|
||||
def _npy_array_summary(path: pathlib.Path, root: pathlib.Path, expected_shape: tuple[int, ...] | None = None) -> tuple[dict[str, Any], list[dict[str, Any]]]:
|
||||
if not path.is_file():
|
||||
return {}, [{"code": "missing_npy_file", "path": _relative(path, root)}]
|
||||
try:
|
||||
array = np.load(path, allow_pickle=False)
|
||||
except Exception as exc:
|
||||
return {}, [{"code": "npy_load_failed", "path": _relative(path, root), "message": str(exc)}]
|
||||
issues: list[dict[str, Any]] = []
|
||||
summary = {"path": _relative(path, root), "shape": list(array.shape), "dtype": str(array.dtype)}
|
||||
if expected_shape and tuple(array.shape) != expected_shape:
|
||||
issues.append({"code": "npy_shape_mismatch", "path": _relative(path, root), "expected": list(expected_shape), "actual": list(array.shape)})
|
||||
if array.dtype.kind in {"f", "i", "u"} and array.size and not np.isfinite(array.reshape(-1)[: min(array.size, 10000)]).all():
|
||||
issues.append({"code": "npy_non_finite_values", "path": _relative(path, root)})
|
||||
return summary, issues
|
||||
|
||||
|
||||
def _png_summary(path: pathlib.Path, root: pathlib.Path, required: bool, code: str) -> tuple[dict[str, Any], list[dict[str, Any]]]:
|
||||
if not path.is_file():
|
||||
return {}, ([{"code": code, "path": _relative(path, root)}] if required else [])
|
||||
try:
|
||||
header = path.read_bytes()[:24]
|
||||
except OSError as exc:
|
||||
return {}, [{"code": "png_read_failed", "path": _relative(path, root), "message": str(exc)}]
|
||||
if len(header) < 24 or not header.startswith(PNG_SIGNATURE):
|
||||
return {"path": _relative(path, root)}, [{"code": "png_signature_invalid", "path": _relative(path, root)}]
|
||||
width, height = struct.unpack(">II", header[16:24])
|
||||
if width <= 0 or height <= 0:
|
||||
return {"path": _relative(path, root), "width": width, "height": height}, [{"code": "png_dimensions_invalid", "path": _relative(path, root)}]
|
||||
return {"path": _relative(path, root), "width": width, "height": height}, []
|
||||
|
||||
|
||||
def _nonempty_file(path: pathlib.Path, root: pathlib.Path, required: bool, code: str) -> tuple[dict[str, Any], list[dict[str, Any]]]:
|
||||
if not path.is_file():
|
||||
return {}, ([{"code": code, "path": _relative(path, root)}] if required else [])
|
||||
try:
|
||||
size = path.stat().st_size
|
||||
except OSError as exc:
|
||||
return {}, [{"code": "file_stat_failed", "path": _relative(path, root), "message": str(exc)}]
|
||||
if size <= 0:
|
||||
return {"path": _relative(path, root), "sizeBytes": size}, [{"code": "file_empty", "path": _relative(path, root)}]
|
||||
return {"path": _relative(path, root), "sizeBytes": size}, []
|
||||
|
||||
|
||||
def _xml_summary(path: pathlib.Path, root: pathlib.Path, required: bool) -> tuple[dict[str, Any], list[dict[str, Any]]]:
|
||||
if not path.is_file():
|
||||
return {}, ([{"code": "missing_annotation_xml", "path": _relative(path, root)}] if required else [])
|
||||
try:
|
||||
tree = ET.parse(path)
|
||||
except Exception as exc:
|
||||
return {"path": _relative(path, root)}, [{"code": "annotation_xml_invalid", "path": _relative(path, root), "message": str(exc)}]
|
||||
root_elem = tree.getroot()
|
||||
object_like = 0
|
||||
for element in root_elem.iter():
|
||||
tag = str(element.tag).lower()
|
||||
if tag in {"object", "posevector", "pose", "obj"}:
|
||||
object_like += 1
|
||||
return {"path": _relative(path, root), "rootTag": str(root_elem.tag), "objectLikeElementCount": object_like}, []
|
||||
|
||||
|
||||
def _rect_npy_summary(path: pathlib.Path, root: pathlib.Path, required: bool) -> tuple[dict[str, Any], list[dict[str, Any]]]:
|
||||
if not path.is_file():
|
||||
return {}, ([{"code": "missing_rect_label", "path": _relative(path, root)}] if required else [])
|
||||
try:
|
||||
summary = _npy_header_from_file(path)
|
||||
except Exception as exc:
|
||||
return {"path": _relative(path, root)}, [{"code": "rect_label_npy_invalid", "path": _relative(path, root), "message": str(exc)}]
|
||||
shape = summary.get("shape", [])
|
||||
issues = []
|
||||
if not isinstance(shape, list) or len(shape) < 2:
|
||||
issues.append({"code": "rect_label_shape_invalid", "path": _relative(path, root), "shape": shape})
|
||||
return {"path": _relative(path, root), **summary}, issues
|
||||
|
||||
|
||||
def _validate_grasp_label(path: pathlib.Path, root: pathlib.Path, object_id: int, required: bool) -> tuple[dict[str, Any], list[dict[str, Any]]]:
|
||||
if not path.is_file():
|
||||
return {}, ([{"code": "missing_grasp_label", "objectId": object_id, "path": _relative(path, root)}] if required else [])
|
||||
try:
|
||||
headers = _npz_headers(path)
|
||||
except Exception as exc:
|
||||
return {"path": _relative(path, root), "objectId": object_id}, [{"code": "grasp_label_npz_invalid", "objectId": object_id, "message": str(exc)}]
|
||||
issues: list[dict[str, Any]] = []
|
||||
for key in ("points", "offsets", "scores", "collision"):
|
||||
if key not in headers:
|
||||
issues.append({"code": "grasp_label_key_missing", "objectId": object_id, "key": key})
|
||||
points_shape = headers.get("points", {}).get("shape", [])
|
||||
offsets_shape = headers.get("offsets", {}).get("shape", [])
|
||||
scores_shape = headers.get("scores", {}).get("shape", [])
|
||||
collision_shape = headers.get("collision", {}).get("shape", [])
|
||||
if points_shape and (len(points_shape) != 2 or points_shape[-1] != 3):
|
||||
issues.append({"code": "grasp_points_shape_invalid", "objectId": object_id, "shape": points_shape})
|
||||
if offsets_shape and (len(offsets_shape) != 5 or offsets_shape[-1] != 3):
|
||||
issues.append({"code": "grasp_offsets_shape_invalid", "objectId": object_id, "shape": offsets_shape})
|
||||
if offsets_shape and scores_shape and scores_shape != offsets_shape[:-1]:
|
||||
issues.append({"code": "grasp_scores_shape_mismatch", "objectId": object_id, "scoresShape": scores_shape, "offsetsShape": offsets_shape})
|
||||
if offsets_shape and collision_shape and collision_shape != offsets_shape[:-1]:
|
||||
issues.append({"code": "grasp_collision_shape_mismatch", "objectId": object_id, "collisionShape": collision_shape, "offsetsShape": offsets_shape})
|
||||
if headers.get("collision", {}).get("dtype") not in {None, "bool"}:
|
||||
issues.append({"code": "grasp_collision_dtype_invalid", "objectId": object_id, "dtype": headers["collision"].get("dtype")})
|
||||
return {"path": _relative(path, root), "objectId": object_id, "arrays": headers}, issues
|
||||
|
||||
|
||||
def _validate_collision_label(path: pathlib.Path, root: pathlib.Path, scene_name: str, required: bool) -> tuple[dict[str, Any], list[dict[str, Any]]]:
|
||||
if not path.is_file():
|
||||
return {}, ([{"code": "missing_collision_label", "scene": scene_name, "path": _relative(path, root)}] if required else [])
|
||||
try:
|
||||
headers = _npz_headers(path)
|
||||
except Exception as exc:
|
||||
return {"path": _relative(path, root), "scene": scene_name}, [{"code": "collision_label_npz_invalid", "scene": scene_name, "message": str(exc)}]
|
||||
issues: list[dict[str, Any]] = []
|
||||
if not headers:
|
||||
issues.append({"code": "collision_label_empty", "scene": scene_name})
|
||||
for key, summary in headers.items():
|
||||
shape = summary.get("shape", [])
|
||||
if len(shape) != 4 or shape[1:] != [300, 12, 4]:
|
||||
issues.append({"code": "collision_label_shape_invalid", "scene": scene_name, "key": key, "shape": shape})
|
||||
if summary.get("dtype") != "bool":
|
||||
issues.append({"code": "collision_label_dtype_invalid", "scene": scene_name, "key": key, "dtype": summary.get("dtype")})
|
||||
return {"path": _relative(path, root), "scene": scene_name, "arrays": headers}, issues
|
||||
|
||||
|
||||
def _validate_model(root: pathlib.Path, object_id: int, require_models: bool) -> tuple[dict[str, Any], list[dict[str, Any]]]:
|
||||
model_dir = root / "models" / f"{object_id:03d}"
|
||||
files: dict[str, Any] = {}
|
||||
issues: list[dict[str, Any]] = []
|
||||
for name in ("nontextured.ply", "textured.obj", "textured.sdf"):
|
||||
summary, file_issues = _nonempty_file(model_dir / name, root, require_models, f"missing_model_{name.replace('.', '_')}")
|
||||
if summary:
|
||||
files[name] = summary
|
||||
issues.extend({**issue, "objectId": object_id} for issue in file_issues)
|
||||
return {"objectId": object_id, "modelDir": _relative(model_dir, root), "files": files}, issues
|
||||
|
||||
|
||||
def _camera_ann_ids(camera_dir: pathlib.Path, max_frames: int) -> list[int]:
|
||||
ids: set[int] = set()
|
||||
for subdir, suffix in (("rgb", ".png"), ("depth", ".png"), ("label", ".png"), ("meta", ".mat"), ("annotations", ".xml"), ("rect", ".npy")):
|
||||
directory = camera_dir / subdir
|
||||
if not directory.is_dir():
|
||||
continue
|
||||
for path in sorted(directory.glob(f"*{suffix}")):
|
||||
try:
|
||||
ids.add(int(path.stem))
|
||||
except ValueError:
|
||||
continue
|
||||
return sorted(ids)[:max_frames]
|
||||
|
||||
|
||||
def _validate_frame(
|
||||
camera_dir: pathlib.Path,
|
||||
root: pathlib.Path,
|
||||
ann_id: int,
|
||||
*,
|
||||
require_meta: bool,
|
||||
require_annotation_xml: bool,
|
||||
require_rect_labels: bool,
|
||||
) -> dict[str, Any]:
|
||||
stem = f"{ann_id:04d}"
|
||||
issues: list[dict[str, Any]] = []
|
||||
rgb, new_issues = _png_summary(camera_dir / "rgb" / f"{stem}.png", root, True, "missing_rgb")
|
||||
issues.extend(new_issues)
|
||||
depth, new_issues = _png_summary(camera_dir / "depth" / f"{stem}.png", root, True, "missing_depth")
|
||||
issues.extend(new_issues)
|
||||
label, new_issues = _png_summary(camera_dir / "label" / f"{stem}.png", root, True, "missing_label")
|
||||
issues.extend(new_issues)
|
||||
meta, new_issues = _nonempty_file(camera_dir / "meta" / f"{stem}.mat", root, require_meta, "missing_meta_mat")
|
||||
issues.extend(new_issues)
|
||||
annotation, new_issues = _xml_summary(camera_dir / "annotations" / f"{stem}.xml", root, require_annotation_xml)
|
||||
issues.extend(new_issues)
|
||||
rect, new_issues = _rect_npy_summary(camera_dir / "rect" / f"{stem}.npy", root, require_rect_labels)
|
||||
issues.extend(new_issues)
|
||||
return {
|
||||
"annId": ann_id,
|
||||
"frameStem": stem,
|
||||
"valid": not issues,
|
||||
"issueCount": len(issues),
|
||||
"issues": issues,
|
||||
"rgb": rgb,
|
||||
"depth": depth,
|
||||
"label": label,
|
||||
"meta": meta,
|
||||
"annotation": annotation,
|
||||
"rect": rect,
|
||||
}
|
||||
|
||||
|
||||
def _validate_camera(
|
||||
camera_dir: pathlib.Path,
|
||||
root: pathlib.Path,
|
||||
*,
|
||||
max_frames_per_camera: int,
|
||||
require_camera_poses: bool,
|
||||
require_meta: bool,
|
||||
require_annotation_xml: bool,
|
||||
require_rect_labels: bool,
|
||||
) -> dict[str, Any]:
|
||||
issues: list[dict[str, Any]] = []
|
||||
cam_k, new_issues = _npy_array_summary(camera_dir / "camK.npy", root, (3, 3))
|
||||
issues.extend({**issue, "camera": camera_dir.name} for issue in new_issues)
|
||||
cam0_wrt_table, new_issues = _npy_array_summary(camera_dir / "cam0_wrt_table.npy", root, (4, 4))
|
||||
if require_camera_poses:
|
||||
issues.extend({**issue, "camera": camera_dir.name} for issue in new_issues)
|
||||
camera_poses, new_issues = _npy_array_summary(camera_dir / "camera_poses.npy", root)
|
||||
if require_camera_poses:
|
||||
issues.extend({**issue, "camera": camera_dir.name} for issue in new_issues)
|
||||
if camera_poses and len(camera_poses.get("shape", [])) != 3:
|
||||
issues.append({"code": "camera_poses_shape_invalid", "camera": camera_dir.name, "shape": camera_poses.get("shape")})
|
||||
ann_ids = _camera_ann_ids(camera_dir, max_frames_per_camera)
|
||||
if not ann_ids:
|
||||
issues.append({"code": "camera_has_no_frames", "camera": camera_dir.name, "path": _relative(camera_dir, root)})
|
||||
frames = [
|
||||
_validate_frame(
|
||||
camera_dir,
|
||||
root,
|
||||
ann_id,
|
||||
require_meta=require_meta,
|
||||
require_annotation_xml=require_annotation_xml,
|
||||
require_rect_labels=require_rect_labels,
|
||||
)
|
||||
for ann_id in ann_ids
|
||||
]
|
||||
return {
|
||||
"camera": camera_dir.name,
|
||||
"cameraPath": _relative(camera_dir, root),
|
||||
"valid": not issues and all(frame["valid"] for frame in frames),
|
||||
"issueCount": len(issues) + sum(int(frame["issueCount"]) for frame in frames),
|
||||
"issues": issues,
|
||||
"frameCount": len(frames),
|
||||
"validFrameCount": sum(1 for frame in frames if frame["valid"]),
|
||||
"camK": cam_k,
|
||||
"cam0WrtTable": cam0_wrt_table,
|
||||
"cameraPoses": camera_poses,
|
||||
"frames": frames,
|
||||
}
|
||||
|
||||
|
||||
def _validate_scene(
|
||||
scene_dir: pathlib.Path,
|
||||
root: pathlib.Path,
|
||||
cameras: tuple[str, ...],
|
||||
*,
|
||||
max_frames_per_camera: int,
|
||||
require_object_ids: bool,
|
||||
require_collision_labels: bool,
|
||||
require_camera_poses: bool,
|
||||
require_meta: bool,
|
||||
require_annotation_xml: bool,
|
||||
require_rect_labels: bool,
|
||||
) -> dict[str, Any]:
|
||||
issues: list[dict[str, Any]] = []
|
||||
scene_id = _scene_id(scene_dir)
|
||||
object_ids, object_issues = _read_object_ids(scene_dir / "object_id_list.txt", root, require_object_ids)
|
||||
issues.extend(object_issues)
|
||||
rs_wrt_kn, new_issues = _npy_array_summary(scene_dir / "rs_wrt_kn.npy", root, (4, 4))
|
||||
issues.extend(new_issues)
|
||||
collision, new_issues = _validate_collision_label(root / "collision_label" / scene_dir.name / "collision_labels.npz", root, scene_dir.name, require_collision_labels)
|
||||
issues.extend(new_issues)
|
||||
camera_summaries: list[dict[str, Any]] = []
|
||||
for camera in cameras:
|
||||
camera_dir = scene_dir / camera
|
||||
if not camera_dir.is_dir():
|
||||
issues.append({"code": "missing_camera_dir", "camera": camera, "path": _relative(camera_dir, root)})
|
||||
continue
|
||||
camera_summaries.append(
|
||||
_validate_camera(
|
||||
camera_dir,
|
||||
root,
|
||||
max_frames_per_camera=max_frames_per_camera,
|
||||
require_camera_poses=require_camera_poses,
|
||||
require_meta=require_meta,
|
||||
require_annotation_xml=require_annotation_xml,
|
||||
require_rect_labels=require_rect_labels,
|
||||
)
|
||||
)
|
||||
return {
|
||||
"sceneId": scene_dir.name,
|
||||
"numericSceneId": scene_id,
|
||||
"split": _scene_split(scene_id),
|
||||
"scenePath": _relative(scene_dir, root),
|
||||
"objectIds": object_ids,
|
||||
"objectCount": len(object_ids),
|
||||
"rsWrtKn": rs_wrt_kn,
|
||||
"collisionLabel": collision,
|
||||
"valid": not issues and all(camera["valid"] for camera in camera_summaries),
|
||||
"issueCount": len(issues) + sum(int(camera["issueCount"]) for camera in camera_summaries),
|
||||
"issues": issues,
|
||||
"cameraCount": len(camera_summaries),
|
||||
"frameCount": sum(int(camera.get("frameCount") or 0) for camera in camera_summaries),
|
||||
"validFrameCount": sum(int(camera.get("validFrameCount") or 0) for camera in camera_summaries),
|
||||
"cameras": camera_summaries,
|
||||
}
|
||||
|
||||
|
||||
def _merge_object_counts(scenes: list[dict[str, Any]]) -> dict[str, int]:
|
||||
counts: dict[str, int] = {}
|
||||
for scene in scenes:
|
||||
for object_id in scene.get("objectIds", []):
|
||||
key = str(object_id)
|
||||
counts[key] = counts.get(key, 0) + 1
|
||||
return counts
|
||||
|
||||
|
||||
def _merge_split_counts(scenes: list[dict[str, Any]]) -> dict[str, int]:
|
||||
counts: dict[str, int] = {}
|
||||
for scene in scenes:
|
||||
split = str(scene.get("split") or "custom")
|
||||
counts[split] = counts.get(split, 0) + 1
|
||||
return counts
|
||||
|
||||
|
||||
def _validate_global_assets(
|
||||
root: pathlib.Path,
|
||||
object_ids: set[int],
|
||||
*,
|
||||
require_models: bool,
|
||||
require_grasp_labels: bool,
|
||||
) -> tuple[dict[str, Any], list[dict[str, Any]]]:
|
||||
issues: list[dict[str, Any]] = []
|
||||
models: list[dict[str, Any]] = []
|
||||
grasp_labels: list[dict[str, Any]] = []
|
||||
for object_id in sorted(object_ids):
|
||||
model, new_issues = _validate_model(root, object_id, require_models)
|
||||
models.append(model)
|
||||
issues.extend(new_issues)
|
||||
label, new_issues = _validate_grasp_label(root / "grasp_label" / f"{object_id:03d}_labels.npz", root, object_id, require_grasp_labels)
|
||||
if label:
|
||||
grasp_labels.append(label)
|
||||
issues.extend(new_issues)
|
||||
return {
|
||||
"modelObjectCount": len([model for model in models if model.get("files")]),
|
||||
"graspLabelObjectCount": len(grasp_labels),
|
||||
"objectIds": [str(object_id) for object_id in sorted(object_ids)[:200]],
|
||||
"models": models[:50],
|
||||
"graspLabels": grasp_labels[:50],
|
||||
}, issues
|
||||
|
||||
|
||||
def run(
|
||||
run_id: str,
|
||||
node_id: str,
|
||||
output_dir: Any,
|
||||
node_data: dict[str, Any],
|
||||
inputs: list[dict[str, Any]],
|
||||
helpers: HelperMap,
|
||||
) -> list[dict[str, Any]]:
|
||||
params = helpers["hyperparams"](node_data)
|
||||
source_path = helpers["resolve_source_path"](params, inputs)
|
||||
if source_path is None:
|
||||
raise RuntimeError("GraspNet 抓取数据集校验需要 SOURCE_PATH 指向真实 GraspNet 根目录、scene 目录或 camera 目录")
|
||||
|
||||
max_scenes = _positive_int(params, "MAX_SCENES", 20)
|
||||
max_frames_per_camera = _positive_int(params, "MAX_FRAMES_PER_CAMERA", 32)
|
||||
cameras = _camera_filter(params)
|
||||
require_models = _bool_param(helpers, params, "REQUIRE_MODELS", True)
|
||||
require_grasp_labels = _bool_param(helpers, params, "REQUIRE_GRASP_LABELS", True)
|
||||
require_collision_labels = _bool_param(helpers, params, "REQUIRE_COLLISION_LABELS", True)
|
||||
require_rect_labels = _bool_param(helpers, params, "REQUIRE_RECT_LABELS", False)
|
||||
require_object_ids = _bool_param(helpers, params, "REQUIRE_OBJECT_IDS", True)
|
||||
require_camera_poses = _bool_param(helpers, params, "REQUIRE_CAMERA_POSES", True)
|
||||
require_meta = _bool_param(helpers, params, "REQUIRE_META_MAT", True)
|
||||
require_annotation_xml = _bool_param(helpers, params, "REQUIRE_ANNOTATION_XML", True)
|
||||
|
||||
scene_dirs = _find_scene_dirs(source_path, max_scenes)
|
||||
if not scene_dirs:
|
||||
raise RuntimeError(f"{source_path} does not contain GraspNet scenes/scene_XXXX directories")
|
||||
root = _dataset_root(source_path, scene_dirs)
|
||||
scenes = [
|
||||
_validate_scene(
|
||||
scene_dir,
|
||||
root,
|
||||
cameras,
|
||||
max_frames_per_camera=max_frames_per_camera,
|
||||
require_object_ids=require_object_ids,
|
||||
require_collision_labels=require_collision_labels,
|
||||
require_camera_poses=require_camera_poses,
|
||||
require_meta=require_meta,
|
||||
require_annotation_xml=require_annotation_xml,
|
||||
require_rect_labels=require_rect_labels,
|
||||
)
|
||||
for scene_dir in scene_dirs
|
||||
]
|
||||
object_ids = {int(object_id) for scene in scenes for object_id in scene.get("objectIds", [])}
|
||||
assets, asset_issues = _validate_global_assets(root, object_ids, require_models=require_models, require_grasp_labels=require_grasp_labels)
|
||||
scene_issues = [
|
||||
{"code": "invalid_scene", "scenePath": scene["scenePath"], "issues": scene["issues"], "cameras": [camera for camera in scene["cameras"] if not camera["valid"]]}
|
||||
for scene in scenes
|
||||
if not scene.get("valid")
|
||||
]
|
||||
issues = [*asset_issues, *scene_issues]
|
||||
payload = {
|
||||
"datasetType": "graspnet-dataset-validation",
|
||||
"sourcePath": str(source_path),
|
||||
"datasetRoot": str(root),
|
||||
"valid": not issues,
|
||||
"issueCount": len(issues),
|
||||
"issues": issues,
|
||||
"sceneCount": len(scenes),
|
||||
"validSceneCount": sum(1 for scene in scenes if scene.get("valid")),
|
||||
"invalidSceneCount": sum(1 for scene in scenes if not scene.get("valid")),
|
||||
"cameraCount": sum(int(scene.get("cameraCount") or 0) for scene in scenes),
|
||||
"frameCount": sum(int(scene.get("frameCount") or 0) for scene in scenes),
|
||||
"validFrameCount": sum(int(scene.get("validFrameCount") or 0) for scene in scenes),
|
||||
"objectCount": len(object_ids),
|
||||
"objectCounts": _merge_object_counts(scenes),
|
||||
"splitCounts": _merge_split_counts(scenes),
|
||||
"assets": {
|
||||
"hasScenesDir": (root / "scenes").is_dir(),
|
||||
"hasModelsDir": (root / "models").is_dir(),
|
||||
"hasGraspLabelDir": (root / "grasp_label").is_dir(),
|
||||
"hasCollisionLabelDir": (root / "collision_label").is_dir(),
|
||||
**assets,
|
||||
},
|
||||
"scenes": scenes,
|
||||
}
|
||||
return [
|
||||
helpers["write_json_artifact"](
|
||||
run_id,
|
||||
node_id,
|
||||
pathlib.Path(output_dir),
|
||||
"graspnet-dataset-validation.json",
|
||||
payload,
|
||||
output=helpers["output_binding"](node_data),
|
||||
)
|
||||
]
|
||||
@ -0,0 +1,34 @@
|
||||
{
|
||||
"acceptance": {
|
||||
"hardcodedOutputAccepted": false,
|
||||
"mockOnlyAccepted": false,
|
||||
"pocFullAcceptanceScript": "scripts/poc-operator-full-acceptance.sh",
|
||||
"requiresPersistentWorkspaceEvidence": true,
|
||||
"requiresRealInputs": true,
|
||||
"shallowOnlyAccepted": false,
|
||||
"simulationOnlyAccepted": false
|
||||
},
|
||||
"category": "ROBOTICS",
|
||||
"containerEntrypoint": "backend/operator-runner/main.py",
|
||||
"entrypoint": "operator.py",
|
||||
"metadata": "operator.json",
|
||||
"name": "GraspNet 抓取数据集校验",
|
||||
"operatorId": "operator-builtin-graspnet-dataset-validate",
|
||||
"operatorSlug": "graspnet_dataset_validate",
|
||||
"preferredSlug": "graspnet_dataset_validate",
|
||||
"pythonImport": "backend.operators.builtin.graspnet_dataset_validate.operator:run",
|
||||
"repositoryId": "builtin/graspnet_dataset_validate",
|
||||
"runtimeDependencies": [
|
||||
"graspnet-1billion-dataset-files",
|
||||
"numpy",
|
||||
"npz-npy-files",
|
||||
"rgb-depth-mask-png-files",
|
||||
"xml-annotations"
|
||||
],
|
||||
"runtimeHandler": "builtin_graspnet_dataset_validate",
|
||||
"runtimeSource": "backend/operators/builtin/graspnet_dataset_validate/operator.py",
|
||||
"schemaVersion": "droboticflow.operator.repository/v1",
|
||||
"sourceRoot": "backend/operators/builtin/graspnet_dataset_validate",
|
||||
"strictPocAcceptanceExternals": [],
|
||||
"type": "builtin"
|
||||
}
|
||||
129
docs/operators/GraspNet-抓取数据集校验.md
Normal file
129
docs/operators/GraspNet-抓取数据集校验.md
Normal file
@ -0,0 +1,129 @@
|
||||
# GraspNet 抓取数据集校验
|
||||
|
||||
- 算子 ID:`operator-builtin-graspnet-dataset-validate`
|
||||
- 类别:`ROBOTICS`
|
||||
- 类型:`builtin`
|
||||
|
||||
## 作用
|
||||
|
||||
读取真实 GraspNet-1Billion 数据根目录、scene 目录或 camera 目录,校验 scenes/scene_XXXX、RGB-D、mask、MAT/XML/rect 标注、object models、grasp_label 和 collision_label。
|
||||
|
||||
## 定位与职责边界
|
||||
|
||||
- 该算子属于 `ROBOTICS` 类,当前登记类型是 `builtin`。
|
||||
- 平台会在 `/api/operators` 中自动提供该算子元数据,运行时由 operator-runner 委派到独立算子入口。
|
||||
|
||||
## 平台语义
|
||||
|
||||
面向 GraspNet-1Billion、AnyGrasp、SuctionNet 和通用物体抓取训练数据,真实读取 models/%03d/nontextured.ply|textured.obj|textured.sdf、grasp_label/%03d_labels.npz、collision_label/scene_XXXX/collision_labels.npz、scenes/scene_XXXX/object_id_list.txt、rs_wrt_kn.npy、kinect|realsense/camK.npy、camera_poses.npy、cam0_wrt_table.npy、rgb/depth/label PNG、meta MAT、annotations XML 和 rect NPY,校验 6DoF grasp label、碰撞标签、相机内外参、RGB-D 帧和实例 mask 是否可用于真实抓取模型训练。
|
||||
|
||||
## 运行时契约
|
||||
|
||||
- Worker 会先把上游 artifact 汇总到 `INPUT_ARTIFACTS_PATH`,再把节点配置通过 `NODE_DATA_JSON` 注入运行容器。
|
||||
- 节点执行结果会写入 `OUTPUT_DIR`、`RESULT_OUTPUT_PATH` 和 `STAGE_MANIFEST_PATH` 对应的文件,再由 worker 汇总进运行记录。
|
||||
- 大文件和大 JSON 不应依赖 API 内联传输,应该通过 `artifact.path`、`dataRef.payloadPath`、共享 PVC 或对象存储引用传递。
|
||||
- 当前独立实现入口是 `backend/operators/builtin/graspnet_dataset_validate/operator.py` 中的 `run(...)`,平台 runtimeHandler 为 `builtin_graspnet_dataset_validate`。
|
||||
|
||||
## 设计边界
|
||||
|
||||
- 该算子应该只承担单一职责,不应在一个节点里同时混合索引、筛选、上传、审核等多个阶段性行为。
|
||||
- 如果一个节点要消费多个语义不同的结果,优先通过多节点拆分,而不是把所有逻辑塞进一个超大脚本。
|
||||
|
||||
## 数据流示意
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
A[上游输入或运行时注入] --> B[GraspNet 抓取数据集校验]
|
||||
B --> C[artifact / stage manifest / 外部副作用]
|
||||
```
|
||||
|
||||
## 输入端口详解
|
||||
|
||||
- `in-1` / **input** / `json` / `bus`:GraspNet 根目录、scenes/scene_XXXX 目录或 kinect/realsense camera 目录 作为输入端口时,适合结构化清单、规则结果、摘要对象等可直接序列化的数据。 通过统一 artifact 契约传递;大 payload 会外置到 stage manifest / payloadPath。
|
||||
|
||||
## 输出端口详解
|
||||
|
||||
- `out-1` / **validation** / `json` / `bus`:GraspNet RGB-D 抓取数据集结构与标注校验结果 作为输出端口时,适合结构化清单、规则结果、摘要对象等可直接序列化的数据。 通过统一 artifact 契约传递;大 payload 会外置到 stage manifest / payloadPath。
|
||||
|
||||
## 关键超参数
|
||||
|
||||
- `SOURCE_PATH`:类型 `string`,默认值 空字符串或由工作流显式填写。GraspNet 根目录、scene 目录或 camera 目录 通常建议在工作流中显式配置。
|
||||
- `CAMERA`:类型 `string`,默认值 `any`。校验 camera:any、kinect、realsense 或逗号分隔子集 可直接使用默认值,也可在节点级覆盖。
|
||||
- `MAX_SCENES`:类型 `string`,默认值 `20`。最多校验多少个 scene_XXXX 目录,必须为正整数 可直接使用默认值,也可在节点级覆盖。
|
||||
- `MAX_FRAMES_PER_CAMERA`:类型 `string`,默认值 `32`。每个 camera 最多校验多少帧,必须为正整数 可直接使用默认值,也可在节点级覆盖。
|
||||
- `REQUIRE_MODELS`:类型 `boolean`,默认值 `true`。是否要求 object_id_list 中每个对象存在 nontextured.ply、textured.obj、textured.sdf 可直接使用默认值,也可在节点级覆盖。
|
||||
- `REQUIRE_GRASP_LABELS`:类型 `boolean`,默认值 `true`。是否要求每个 object id 存在 grasp_label/%03d_labels.npz 且包含 points/offsets/scores/collision 可直接使用默认值,也可在节点级覆盖。
|
||||
- `REQUIRE_COLLISION_LABELS`:类型 `boolean`,默认值 `true`。是否要求每个 scene 存在 collision_label/scene_XXXX/collision_labels.npz 可直接使用默认值,也可在节点级覆盖。
|
||||
- `REQUIRE_RECT_LABELS`:类型 `boolean`,默认值 `false`。是否要求每帧存在 rect/%04d.npy 矩形抓取标签 可直接使用默认值,也可在节点级覆盖。
|
||||
- `REQUIRE_OBJECT_IDS`:类型 `boolean`,默认值 `true`。是否要求 scene 目录存在 object_id_list.txt 可直接使用默认值,也可在节点级覆盖。
|
||||
- `REQUIRE_CAMERA_POSES`:类型 `boolean`,默认值 `true`。是否要求 camera 目录存在 camK.npy、camera_poses.npy、cam0_wrt_table.npy 可直接使用默认值,也可在节点级覆盖。
|
||||
- `REQUIRE_META_MAT`:类型 `boolean`,默认值 `true`。是否要求每帧存在 meta/%04d.mat 可直接使用默认值,也可在节点级覆盖。
|
||||
- `REQUIRE_ANNOTATION_XML`:类型 `boolean`,默认值 `true`。是否要求每帧存在 annotations/%04d.xml 且可解析 可直接使用默认值,也可在节点级覆盖。
|
||||
|
||||
## 执行前准备
|
||||
|
||||
- 先确认上下游端口类型兼容,特别是 `json`、`file`、`video` 等端口不要混接。
|
||||
- 为每个关键超参数补齐明确值,避免依赖隐式默认值进入生产工作流。
|
||||
- 对需要跨节点长期保留的产物,提前规划对象存储前缀或外部落库集合,而不是只写临时目录。
|
||||
|
||||
## 数据通信与存储路径
|
||||
|
||||
- 标准输入来自 `INPUT_ARTIFACTS_PATH` 指向的 artifact 列表文件,artifact 可同时包含 `data`、`path`、`metadata` 与 `dataRef`。
|
||||
- 标准输出写入 `OUTPUT_DIR`,并通过 `stage-manifest.json` 对外暴露产物路径、payload 引用和摘要元数据。
|
||||
|
||||
## 典型上下游编排
|
||||
|
||||
- 该算子通常位于同类数据处理节点之间,承担结构化中间层职责。
|
||||
|
||||
## 节点配置示例
|
||||
|
||||
```json
|
||||
{
|
||||
"label": "GraspNet 抓取数据集校验",
|
||||
"operatorId": "operator-builtin-graspnet-dataset-validate",
|
||||
"type": "builtin",
|
||||
"category": "ROBOTICS",
|
||||
"hyperparams": {
|
||||
"SOURCE_PATH": "<按节点填写>",
|
||||
"CAMERA": "any",
|
||||
"MAX_SCENES": "20",
|
||||
"MAX_FRAMES_PER_CAMERA": "32",
|
||||
"REQUIRE_MODELS": "true",
|
||||
"REQUIRE_GRASP_LABELS": "true",
|
||||
"REQUIRE_COLLISION_LABELS": "true",
|
||||
"REQUIRE_RECT_LABELS": "false",
|
||||
"REQUIRE_OBJECT_IDS": "true",
|
||||
"REQUIRE_CAMERA_POSES": "true",
|
||||
"REQUIRE_META_MAT": "true",
|
||||
"REQUIRE_ANNOTATION_XML": "true"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 输入输出示例
|
||||
|
||||
- 典型输入:worker 会把上游 artifact 序列化为 `INPUT_ARTIFACTS_PATH` 文件供节点读取。
|
||||
- 典型输出:节点会在 `OUTPUT_DIR` 下写业务文件,并在 `stage-manifest.json` 里登记对外可消费的结果。
|
||||
|
||||
## 成功判定
|
||||
|
||||
- 节点 execution 状态为 `completed`,且日志中没有隐藏的回退错误或重试未果记录。
|
||||
- `stage-manifest.json` 中能看到期望的 artifact 条目,且下游节点可以正常消费这些结果。
|
||||
|
||||
## 常见失败与排查
|
||||
|
||||
- 如果看不到预期结果,先检查 `OUTPUT_DIR`、`RESULT_OUTPUT_PATH` 和 `STAGE_MANIFEST_PATH` 是否真实写出。
|
||||
- 如果下游收不到数据,先检查当前节点输出 artifact 是否设置了正确的 `portId`、`portName` 和 `type`。
|
||||
- 如果日志中只有摘要没有大 payload,优先排查 `dataRef.payloadPath` 或外置文件是否存在,而不是误以为结果丢失。
|
||||
|
||||
## 验收检查清单
|
||||
|
||||
- 至少在一条真实工作流中跑通该算子,而不是只验证单元测试或空输入。
|
||||
- 确认该节点输出被下游节点实际消费,避免出现“本节点成功但链路无效”的假阳性。
|
||||
- 保留一次成功运行的示例日志、stage manifest 和关键产物路径,便于后续回归对照。
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [ROBOTICS 类索引](README.md)
|
||||
- [算子开发文档](../operator-authoring.md)
|
||||
- [内建算子总手册](../builtin-operators-manual.zh-CN.md)
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
当前目录按“每个内建算子一份 Markdown”组织,内容基于当前平台真实算子定义按算子名称去重生成。
|
||||
|
||||
- 当前收录数量:`85`
|
||||
- 当前收录数量:`86`
|
||||
- 文档定位:单算子详细手册,重点覆盖输入输出契约、运行时路径、配置示例、排障与验收。
|
||||
- 配套总览:[`../builtin-operators-manual.zh-CN.md`](../builtin-operators-manual.zh-CN.md)
|
||||
|
||||
@ -77,6 +77,7 @@
|
||||
- [DexYCB 数据集校验](DexYCB-数据集校验.md)
|
||||
- [Episode 边界校验](Episode-边界校验.md)
|
||||
- [FurnitureBench PKL示教校验](FurnitureBench-PKL示教校验.md)
|
||||
- [GraspNet 抓取数据集校验](GraspNet-抓取数据集校验.md)
|
||||
- [HDF5 示教数据概览](HDF5-示教数据概览.md)
|
||||
- [HO3D/H2O3D 数据集校验](HO3D-H2O3D-数据集校验.md)
|
||||
- [LIBERO HDF5任务校验](LIBERO-HDF5任务校验.md)
|
||||
|
||||
@ -3620,6 +3620,108 @@
|
||||
"runtimeSource": "backend/operators/builtin/ros_joint_state_validate/operator.py",
|
||||
"runtimeHandler": "builtin_ros_joint_state_validate"
|
||||
},
|
||||
{
|
||||
"id": "operator-builtin-graspnet-dataset-validate",
|
||||
"name": "GraspNet 抓取数据集校验",
|
||||
"type": "builtin",
|
||||
"category": "ROBOTICS",
|
||||
"description": "读取真实 GraspNet-1Billion 数据根目录、scene 目录或 camera 目录,校验 scenes/scene_XXXX、RGB-D、mask、MAT/XML/rect 标注、object models、grasp_label 和 collision_label。",
|
||||
"inputs": [
|
||||
{
|
||||
"id": "in-1",
|
||||
"name": "input",
|
||||
"type": "json",
|
||||
"description": "GraspNet 根目录、scenes/scene_XXXX 目录或 kinect/realsense camera 目录",
|
||||
"transmission": "bus"
|
||||
}
|
||||
],
|
||||
"outputs": [
|
||||
{
|
||||
"id": "out-1",
|
||||
"name": "validation",
|
||||
"type": "json",
|
||||
"description": "GraspNet RGB-D 抓取数据集结构与标注校验结果",
|
||||
"transmission": "bus"
|
||||
}
|
||||
],
|
||||
"skillDefinition": "面向 GraspNet-1Billion、AnyGrasp、SuctionNet 和通用物体抓取训练数据,真实读取 models/%03d/nontextured.ply|textured.obj|textured.sdf、grasp_label/%03d_labels.npz、collision_label/scene_XXXX/collision_labels.npz、scenes/scene_XXXX/object_id_list.txt、rs_wrt_kn.npy、kinect|realsense/camK.npy、camera_poses.npy、cam0_wrt_table.npy、rgb/depth/label PNG、meta MAT、annotations XML 和 rect NPY,校验 6DoF grasp label、碰撞标签、相机内外参、RGB-D 帧和实例 mask 是否可用于真实抓取模型训练。",
|
||||
"hyperparams": [
|
||||
{
|
||||
"key": "SOURCE_PATH",
|
||||
"value": "",
|
||||
"description": "GraspNet 根目录、scene 目录或 camera 目录",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"key": "CAMERA",
|
||||
"value": "any",
|
||||
"description": "校验 camera:any、kinect、realsense 或逗号分隔子集",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"key": "MAX_SCENES",
|
||||
"value": "20",
|
||||
"description": "最多校验多少个 scene_XXXX 目录,必须为正整数",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"key": "MAX_FRAMES_PER_CAMERA",
|
||||
"value": "32",
|
||||
"description": "每个 camera 最多校验多少帧,必须为正整数",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"key": "REQUIRE_MODELS",
|
||||
"value": "true",
|
||||
"description": "是否要求 object_id_list 中每个对象存在 nontextured.ply、textured.obj、textured.sdf",
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
"key": "REQUIRE_GRASP_LABELS",
|
||||
"value": "true",
|
||||
"description": "是否要求每个 object id 存在 grasp_label/%03d_labels.npz 且包含 points/offsets/scores/collision",
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
"key": "REQUIRE_COLLISION_LABELS",
|
||||
"value": "true",
|
||||
"description": "是否要求每个 scene 存在 collision_label/scene_XXXX/collision_labels.npz",
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
"key": "REQUIRE_RECT_LABELS",
|
||||
"value": "false",
|
||||
"description": "是否要求每帧存在 rect/%04d.npy 矩形抓取标签",
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
"key": "REQUIRE_OBJECT_IDS",
|
||||
"value": "true",
|
||||
"description": "是否要求 scene 目录存在 object_id_list.txt",
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
"key": "REQUIRE_CAMERA_POSES",
|
||||
"value": "true",
|
||||
"description": "是否要求 camera 目录存在 camK.npy、camera_poses.npy、cam0_wrt_table.npy",
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
"key": "REQUIRE_META_MAT",
|
||||
"value": "true",
|
||||
"description": "是否要求每帧存在 meta/%04d.mat",
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
"key": "REQUIRE_ANNOTATION_XML",
|
||||
"value": "true",
|
||||
"description": "是否要求每帧存在 annotations/%04d.xml 且可解析",
|
||||
"type": "boolean"
|
||||
}
|
||||
],
|
||||
"runtimeSource": "backend/operators/builtin/graspnet_dataset_validate/operator.py",
|
||||
"runtimeHandler": "builtin_graspnet_dataset_validate"
|
||||
},
|
||||
{
|
||||
"id": "operator-builtin-bop-dataset-validate",
|
||||
"name": "BOP 6D姿态数据集校验",
|
||||
|
||||
@ -38,6 +38,7 @@ RUNTIME_DEPENDENCIES: dict[str, list[str]] = {
|
||||
"episode_boundary_validate": ["json-jsonl-parquet-files", "pyarrow"],
|
||||
"force_torque_sensor_validate": ["csv-json-jsonl-parquet-hdf5-force-torque-files", "pyarrow", "h5py", "numpy"],
|
||||
"furniturebench_pkl_demonstration_validate": ["furniturebench-pkl-files", "pickle", "numpy"],
|
||||
"graspnet_dataset_validate": ["graspnet-1billion-dataset-files", "numpy", "npz-npy-files", "rgb-depth-mask-png-files", "xml-annotations"],
|
||||
"hdf5_demonstration_summary": ["hdf5-files", "h5py"],
|
||||
"hf_dataset_probe": ["huggingface-dataset-viewer-api"],
|
||||
"hand_object_pose_validate": ["json-jsonl-csv-parquet-files", "image-files", "mask-files", "pyarrow"],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user