-
Notifications
You must be signed in to change notification settings - Fork 5
Eval GR00T N1 model #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Eval GR00T N1 model #106
Changes from 8 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
0417a21
add eval n1 policy
KumoLiu a59ba39
add readme
KumoLiu 66b0f89
Merge branch 'main' into yunl/n1-policy-eval
KumoLiu 99e712b
add n1 policy and enhance readme
KumoLiu 695f70b
minor fix
KumoLiu a5ec425
remove action in the data point
KumoLiu 4f2df07
update test file
KumoLiu 24f0546
address comments
KumoLiu db7c9f5
combine run policy and update readme
KumoLiu c12aedd
rename test_pi0 to test_policy
KumoLiu 42c9004
update dead links
KumoLiu aa6ed30
add utils and runners for each policy
KumoLiu 47f1c6e
fix format
KumoLiu eacdddd
update env setup support gr00t
KumoLiu bef6357
Merge remote-tracking branch 'origin/main' into yunl/n1-policy-eval
KumoLiu 61df915
remove both and update core to base
KumoLiu b12693c
update use gr00tn1
KumoLiu bd19171
update readme
KumoLiu c274512
update readme
KumoLiu 4d73b0a
address comments
KumoLiu 8701387
update readme
KumoLiu 5556bc2
replace all the GR00TN1 with GR00T N1
KumoLiu cd1fb54
exit if third party exist
KumoLiu 9e3929f
update README
KumoLiu f5a98ea
update import
KumoLiu e9c1952
update for check
KumoLiu a13429c
strip policy
KumoLiu 2e08398
update import
KumoLiu c39057e
Merge branch 'main' into yunl/n1-policy-eval
mingxin-zheng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 178 additions & 0 deletions
178
workflows/robotic_ultrasound/scripts/policy_runner/run_n1_policy.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
KumoLiu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
|
|
||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import argparse | ||
| import os | ||
|
|
||
| import numpy as np | ||
| import torch | ||
| from dds.publisher import Publisher | ||
| from dds.schemas.camera_info import CameraInfo | ||
| from dds.schemas.franka_ctrl import FrankaCtrlInput | ||
| from dds.schemas.franka_info import FrankaInfo | ||
| from dds.subscriber import SubscriberWithCallback | ||
| from gr00t.model.policy import BasePolicy, Gr00tPolicy | ||
KumoLiu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| from policy_runner.utils import DATA_CONFIG_MAP | ||
|
|
||
| current_state = { | ||
| "room_cam": None, | ||
| "wrist_cam": None, | ||
| "joint_pos": None, | ||
| } | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser(description="Run the openpi0 policy runner") | ||
| parser.add_argument( | ||
| "--ckpt_path", | ||
| type=str, | ||
| help="checkpoint path. Default to use policy checkpoint in the latest assets.", | ||
| ) | ||
| parser.add_argument( | ||
| "--rti_license_file", type=str, default=os.getenv("RTI_LICENSE_FILE"), help="the path of rti_license_file." | ||
| ) | ||
| parser.add_argument("--domain_id", type=int, default=0, help="domain id.") | ||
| parser.add_argument("--height", type=int, default=224, help="input image height.") | ||
| parser.add_argument("--width", type=int, default=224, help="input image width.") | ||
| parser.add_argument( | ||
| "--topic_in_room_camera", | ||
| type=str, | ||
| default="topic_room_camera_data_rgb", | ||
| help="topic name to consume room camera rgb.", | ||
| ) | ||
| parser.add_argument( | ||
| "--topic_in_wrist_camera", | ||
| type=str, | ||
| default="topic_wrist_camera_data_rgb", | ||
| help="topic name to consume wrist camera rgb.", | ||
| ) | ||
| parser.add_argument( | ||
| "--topic_in_franka_pos", | ||
| type=str, | ||
| default="topic_franka_info", | ||
| help="topic name to consume franka pos.", | ||
| ) | ||
| parser.add_argument( | ||
| "--topic_out", | ||
| type=str, | ||
| default="topic_franka_ctrl", | ||
| help="topic name to publish generated franka actions.", | ||
| ) | ||
| parser.add_argument("--verbose", type=bool, default=False, help="whether to print the log.") | ||
| parser.add_argument( | ||
| "--data_config", | ||
| type=str, | ||
| default="single_panda_us", | ||
| choices=list(DATA_CONFIG_MAP.keys()), | ||
| help="data config name", | ||
| ) | ||
| # parser.add_argument("--modality_keys", nargs="+", type=str, default=["panda_hand"]) | ||
| parser.add_argument( | ||
| "--embodiment_tag", | ||
| type=str, | ||
| help="The embodiment tag for the model.", | ||
| default="new_embodiment", | ||
| ) | ||
| args = parser.parse_args() | ||
|
|
||
| data_config = DATA_CONFIG_MAP[args.data_config] | ||
| modality_config = data_config.modality_config() | ||
| modality_transform = data_config.transform() | ||
|
|
||
| policy: BasePolicy = Gr00tPolicy( | ||
| model_path=args.ckpt_path, | ||
| modality_config=modality_config, | ||
| modality_transform=modality_transform, | ||
| embodiment_tag=args.embodiment_tag, | ||
| device="cuda" if torch.cuda.is_available() else "cpu", | ||
| ) | ||
|
|
||
| if args.rti_license_file is not None: | ||
| if not os.path.isabs(args.rti_license_file): | ||
| raise ValueError("RTI license file must be an existing absolute path.") | ||
| os.environ["RTI_LICENSE_FILE"] = args.rti_license_file | ||
|
|
||
| hz = 30 | ||
|
|
||
| class PolicyPublisher(Publisher): | ||
| def __init__(self, topic: str, domain_id: int): | ||
| super().__init__(topic, FrankaCtrlInput, 1 / hz, domain_id) | ||
|
|
||
| def produce(self, dt: float, sim_time: float): | ||
| # Process camera images directly to numpy arrays | ||
| def _process_camera_image(buffer, height, width): | ||
| img_buffer = np.frombuffer(buffer, dtype=np.uint8) | ||
| return img_buffer.reshape(height, width, 3) | ||
|
|
||
| # Get images from camera buffers | ||
| room_img = _process_camera_image(current_state["room_cam"], args.height, args.width) | ||
| wrist_img = _process_camera_image(current_state["wrist_cam"], args.height, args.width) | ||
| joint_pos = current_state["joint_pos"] | ||
|
|
||
| # Prepare input data with batch dimension for model | ||
| data_point = { | ||
| "video.room": np.expand_dims(room_img, axis=0), | ||
| "video.wrist": np.expand_dims(wrist_img, axis=0), | ||
| "state.panda_hand": np.expand_dims(np.array(joint_pos), axis=0), | ||
| "annotation.human.task_description": "Perform a liver ultrasound.", | ||
| } | ||
| actions = policy.get_action(data_point) | ||
| i = FrankaCtrlInput() | ||
| # actions are relative positions, if run with absolute positions, need to add the current joint positions | ||
| # actions shape is (16, 6), must reshape to (96,) | ||
| i.joint_positions = ( | ||
| np.array(actions["action.panda_hand"]) | ||
| .astype(np.float32) | ||
| .reshape( | ||
| 16 * 6, | ||
| ) | ||
| .tolist() | ||
| ) | ||
| return i | ||
|
|
||
| writer = PolicyPublisher(args.topic_out, args.domain_id) | ||
|
|
||
| def dds_callback(topic, data): | ||
| if args.verbose: | ||
| print(f"[INFO]: Received data from {topic}") | ||
| if topic == args.topic_in_room_camera: | ||
| o: CameraInfo = data | ||
| current_state["room_cam"] = o.data | ||
|
|
||
| if topic == args.topic_in_wrist_camera: | ||
| o: CameraInfo = data | ||
| current_state["wrist_cam"] = o.data | ||
|
|
||
| if topic == args.topic_in_franka_pos: | ||
| o: FrankaInfo = data | ||
| current_state["joint_pos"] = o.joints_state_positions | ||
| if ( | ||
| current_state["room_cam"] is not None | ||
| and current_state["wrist_cam"] is not None | ||
| and current_state["joint_pos"] is not None | ||
| ): | ||
| writer.write() | ||
| if args.verbose: | ||
| print(f"[INFO]: Published joint position to {args.topic_out}") | ||
| # clean the buffer | ||
| current_state["room_cam"] = current_state["wrist_cam"] = current_state["joint_pos"] = None | ||
|
|
||
| SubscriberWithCallback(dds_callback, args.domain_id, args.topic_in_room_camera, CameraInfo, 1 / hz).start() | ||
| SubscriberWithCallback(dds_callback, args.domain_id, args.topic_in_wrist_camera, CameraInfo, 1 / hz).start() | ||
| SubscriberWithCallback(dds_callback, args.domain_id, args.topic_in_franka_pos, FrankaInfo, 1 / hz).start() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
workflows/robotic_ultrasound/tests/test_policy_runner/test_data/pos.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0.2685, -0.2822, -0.1428, 0.5501, -0.0998, -0.6649, 0.1716 | ||
| 0.2284, -0.7496, -0.2118, -2.4747, -0.1321, 1.7308, 0.0885 | ||
yiheng-wang-nv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Binary file modified
BIN
-213 KB
(12%)
workflows/robotic_ultrasound/tests/test_policy_runner/test_data/room_cam.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-196 KB
(17%)
workflows/robotic_ultrasound/tests/test_policy_runner/test_data/wrist_cam.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.