rosetta_port
rosetta_port turns a directory of bags into a training dataset through a
contract. It is a console script in rosetta_ros.
ros2 run rosetta_ros rosetta_port --raw-dir <bags> --contract <robot.yaml> [options]
<bags> is the directory to search for bags, and <robot.yaml> is the
contract to decode them with. python3 -m rosetta_ros.offline.port runs the
same entry point.
Options
Option |
Default |
Meaning |
|---|---|---|
|
required |
Directory searched recursively for bag directories. |
|
required |
Contract YAML. It decodes every bag and is the copy embedded in the dataset. |
|
the |
Dataset repo ID, such as |
|
the writer’s default |
Parent directory. The LeRobot writer puts the dataset at |
|
|
Dataset writer, by its name in the |
|
none |
Total shards for a parallel run. |
|
none |
This run’s shard, from 0 to |
|
embed |
Skip copying |
LeRobot writer options:
Option |
Default |
Meaning |
|---|---|---|
|
off |
Upload to the Hugging Face Hub after the last episode. |
|
private |
Make the uploaded dataset public. |
|
|
Comma-separated Hub tags. |
|
|
Video codec for image keys. |
|
off |
Encode video frames as they arrive instead of through intermediate PNG files. |
Writer-specific options, passed to the writer only when given:
--past-steps, --future-steps, --image-indices (a comma list such as
-1,0) and --samples-per-shard. The LeRobot writer ignores all four.
Behavior
A bag directory is any directory under
--raw-dirholding ametadata.yaml. One bag is one episode. Episodes are ported in sorted path order.No bag directory under
--raw-diris an error:RuntimeError: No bag directories found in <raw-dir>.A
--contractthat is not a file, a--raw-dirthat is not a directory, a--formatthat is not installed, and a--shard-indexmissing or outside0to--num-shards - 1are usage errors: argparse’s message and exit 2.The bag’s
storage_identifierpicks the rosbag2 storage plugin,mcapwhen the metadata names none.Shard
iofntakes every nth bag in sorted order, starting at bagi. An empty shard logsNo bags to process in this shard, writes nothing and exits 0.Every shard writes its own dataset, so shards that share
--rootand--repo-idcollide. The later shard fails withFileExistsError.Tick
kis at the bag’s start time plusk / fpsseconds, rounded down to the nanosecond, so the grid does not drift when1e9 / fpsis not a whole number. The last tick is the last one at or before the bag’s end. Ticks before every observation source has a sample are skipped.When the first bag’s embedded contract differs from
--contractafter parsing, the porter logs this warning and carries on:Bag was recorded with a different contract than --contract; using --contract for decoding and embedding.
A bag missing an observation topic fails that episode with
observation topics missing from bag. A present observation topic that never yields a sample fails it withno frames emitted.A bag missing an action, reward, signal, info or teleop topic ports with that key zero-filled and a warning:
<bag>: topic <topic> not in bag, <key> will be zero-filled.A bag whose action topic is recorded but has no messages ports with that key zero-filled and a warning:
<bag>: <topic> has no messages, <key> is all zeros.A source whose type has no decoder fails every episode at open. A topic the contract declares with two different types fails every episode too.
A failed episode is discarded, logged, and the run continues. The run ends with a
Completed: <ok>/<total> episodes (<failed> failed) in <seconds>sline and one warning per failed episode.If some episodes fail, the dataset is written with the rest and the run exits 1 with
rosetta_port: <n> bags failed to port: <bags>. The dataset holds the rest., naming the first five failed bags.If every episode fails, the run exits non-zero with
RuntimeError: All <n> bags failed to convert. The dataset directory and itsmeta/already exist by then.The LeRobot writer refuses a dataset directory that already exists, with
FileExistsError. Delete it, or pick another--rootor--repo-id, before running again.The task string per frame is the newest
tasksmessage at or before the tick, or else the prompt stored in the bag’s metadata. See Tasks.
Output
With the LeRobot writer, a LeRobot v3.0 dataset at <root>/<repo-id>.
Features are the contract’s recorded keys (observations, actions, the four record-only sections, and any
teleop.input.*andteleop.feedback.*keys) plusis_first,is_lastandis_terminal, and LeRobot’s owntimestamp,frame_index,episode_index,indexandtask_index.is_firstmarks the first frame after warmup.is_terminalequalsis_last.robot_typeandfpscome from the contract.meta/rosetta_contract.yamlholds a copy of--contractunless--no-embed-contractis given.policy_runner_nodecan find its contract there. See Nodes.