mirror of
https://github.com/huggingface/lerobot.git
synced 2026-07-25 02:36:11 +00:00
fix(examples): wrap all of them into a main function (#2524)
This commit is contained in:
@@ -196,7 +196,7 @@ client_cfg = RobotClientConfig(
|
|||||||
server_address="localhost:8080",
|
server_address="localhost:8080",
|
||||||
policy_device="mps",
|
policy_device="mps",
|
||||||
policy_type="smolvla",
|
policy_type="smolvla",
|
||||||
pretrained_name_or_path="fracapuano/smolvla_async",
|
pretrained_name_or_path="<user>/smolvla_async",
|
||||||
chunk_size_threshold=0.5,
|
chunk_size_threshold=0.5,
|
||||||
actions_per_chunk=50, # make sure this is less than the max actions of the policy
|
actions_per_chunk=50, # make sure this is less than the max actions of the policy
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ from huggingface_hub import HfApi
|
|||||||
import lerobot
|
import lerobot
|
||||||
from lerobot.datasets.lerobot_dataset import LeRobotDataset, LeRobotDatasetMetadata
|
from lerobot.datasets.lerobot_dataset import LeRobotDataset, LeRobotDatasetMetadata
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
# We ported a number of existing datasets ourselves, use this to see the list:
|
# We ported a number of existing datasets ourselves, use this to see the list:
|
||||||
print("List of available datasets:")
|
print("List of available datasets:")
|
||||||
pprint(lerobot.available_datasets)
|
pprint(lerobot.available_datasets)
|
||||||
@@ -132,7 +134,6 @@ print(f"\n{dataset[0][camera_key].shape=}") # (4, c, h, w)
|
|||||||
print(f"{dataset[0]['observation.state'].shape=}") # (6, c)
|
print(f"{dataset[0]['observation.state'].shape=}") # (6, c)
|
||||||
print(f"{dataset[0]['action'].shape=}\n") # (64, c)
|
print(f"{dataset[0]['action'].shape=}\n") # (64, c)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
dataloader = torch.utils.data.DataLoader(
|
dataloader = torch.utils.data.DataLoader(
|
||||||
dataset,
|
dataset,
|
||||||
num_workers=4,
|
num_workers=4,
|
||||||
@@ -144,3 +145,7 @@ if __name__ == "__main__":
|
|||||||
print(f"{batch['observation.state'].shape=}") # (32, 6, c)
|
print(f"{batch['observation.state'].shape=}") # (32, 6, c)
|
||||||
print(f"{batch['action'].shape=}") # (32, 64, c)
|
print(f"{batch['action'].shape=}") # (32, 64, c)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ TASK_DESCRIPTION = "My task description"
|
|||||||
HF_MODEL_ID = "<hf_username>/<model_repo_id>"
|
HF_MODEL_ID = "<hf_username>/<model_repo_id>"
|
||||||
HF_DATASET_ID = "<hf_username>/<eval_dataset_repo_id>"
|
HF_DATASET_ID = "<hf_username>/<eval_dataset_repo_id>"
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
# Create the robot configuration & robot
|
# Create the robot configuration & robot
|
||||||
robot_config = LeKiwiClientConfig(remote_ip="172.18.134.136", id="lekiwi")
|
robot_config = LeKiwiClientConfig(remote_ip="172.18.134.136", id="lekiwi")
|
||||||
|
|
||||||
@@ -136,3 +138,7 @@ listener.stop()
|
|||||||
|
|
||||||
dataset.finalize()
|
dataset.finalize()
|
||||||
dataset.push_to_hub()
|
dataset.push_to_hub()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ RESET_TIME_SEC = 10
|
|||||||
TASK_DESCRIPTION = "My task description"
|
TASK_DESCRIPTION = "My task description"
|
||||||
HF_REPO_ID = "<hf_username>/<dataset_repo_id>"
|
HF_REPO_ID = "<hf_username>/<dataset_repo_id>"
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
# Create the robot and teleoperator configurations
|
# Create the robot and teleoperator configurations
|
||||||
robot_config = LeKiwiClientConfig(remote_ip="172.18.134.136", id="lekiwi")
|
robot_config = LeKiwiClientConfig(remote_ip="172.18.134.136", id="lekiwi")
|
||||||
leader_arm_config = SO100LeaderConfig(port="/dev/tty.usbmodem585A0077581", id="my_awesome_leader_arm")
|
leader_arm_config = SO100LeaderConfig(port="/dev/tty.usbmodem585A0077581", id="my_awesome_leader_arm")
|
||||||
@@ -133,3 +135,7 @@ listener.stop()
|
|||||||
|
|
||||||
dataset.finalize()
|
dataset.finalize()
|
||||||
dataset.push_to_hub()
|
dataset.push_to_hub()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ from lerobot.utils.utils import log_say
|
|||||||
|
|
||||||
EPISODE_IDX = 0
|
EPISODE_IDX = 0
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
# Initialize the robot config
|
# Initialize the robot config
|
||||||
robot_config = LeKiwiClientConfig(remote_ip="172.18.134.136", id="lekiwi")
|
robot_config = LeKiwiClientConfig(remote_ip="172.18.134.136", id="lekiwi")
|
||||||
|
|
||||||
@@ -59,3 +61,7 @@ for idx in range(len(episode_frames)):
|
|||||||
busy_wait(max(1.0 / dataset.fps - (time.perf_counter() - t0), 0.0))
|
busy_wait(max(1.0 / dataset.fps - (time.perf_counter() - t0), 0.0))
|
||||||
|
|
||||||
robot.disconnect()
|
robot.disconnect()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ from lerobot.utils.visualization_utils import init_rerun, log_rerun_data
|
|||||||
|
|
||||||
FPS = 30
|
FPS = 30
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
# Create the robot and teleoperator configurations
|
# Create the robot and teleoperator configurations
|
||||||
robot_config = LeKiwiClientConfig(remote_ip="172.18.134.136", id="my_lekiwi")
|
robot_config = LeKiwiClientConfig(remote_ip="172.18.134.136", id="my_lekiwi")
|
||||||
teleop_arm_config = SO100LeaderConfig(port="/dev/tty.usbmodem585A0077581", id="my_awesome_leader_arm")
|
teleop_arm_config = SO100LeaderConfig(port="/dev/tty.usbmodem585A0077581", id="my_awesome_leader_arm")
|
||||||
@@ -70,3 +72,7 @@ while True:
|
|||||||
log_rerun_data(observation=observation, action=action)
|
log_rerun_data(observation=observation, action=action)
|
||||||
|
|
||||||
busy_wait(max(1.0 / FPS - (time.perf_counter() - t0), 0.0))
|
busy_wait(max(1.0 / FPS - (time.perf_counter() - t0), 0.0))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ TASK_DESCRIPTION = "My task description"
|
|||||||
HF_MODEL_ID = "<hf_username>/<model_repo_id>"
|
HF_MODEL_ID = "<hf_username>/<model_repo_id>"
|
||||||
HF_DATASET_ID = "<hf_username>/<dataset_repo_id>"
|
HF_DATASET_ID = "<hf_username>/<dataset_repo_id>"
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
# Create the robot configuration & robot
|
# Create the robot configuration & robot
|
||||||
camera_config = {"front": OpenCVCameraConfig(index_or_path=0, width=640, height=480, fps=FPS)}
|
camera_config = {"front": OpenCVCameraConfig(index_or_path=0, width=640, height=480, fps=FPS)}
|
||||||
robot_config = SO100FollowerConfig(
|
robot_config = SO100FollowerConfig(
|
||||||
@@ -89,7 +91,9 @@ robot_ee_to_joints_processor = RobotProcessorPipeline[tuple[RobotAction, RobotOb
|
|||||||
# Build pipeline to convert joints observation to EE observation
|
# Build pipeline to convert joints observation to EE observation
|
||||||
robot_joints_to_ee_pose_processor = RobotProcessorPipeline[RobotObservation, RobotObservation](
|
robot_joints_to_ee_pose_processor = RobotProcessorPipeline[RobotObservation, RobotObservation](
|
||||||
steps=[
|
steps=[
|
||||||
ForwardKinematicsJointsToEE(kinematics=kinematics_solver, motor_names=list(robot.bus.motors.keys()))
|
ForwardKinematicsJointsToEE(
|
||||||
|
kinematics=kinematics_solver, motor_names=list(robot.bus.motors.keys())
|
||||||
|
)
|
||||||
],
|
],
|
||||||
to_transition=observation_to_transition,
|
to_transition=observation_to_transition,
|
||||||
to_output=transition_to_observation,
|
to_output=transition_to_observation,
|
||||||
@@ -197,3 +201,7 @@ listener.stop()
|
|||||||
|
|
||||||
dataset.finalize()
|
dataset.finalize()
|
||||||
dataset.push_to_hub()
|
dataset.push_to_hub()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ RESET_TIME_SEC = 30
|
|||||||
TASK_DESCRIPTION = "My task description"
|
TASK_DESCRIPTION = "My task description"
|
||||||
HF_REPO_ID = "<hf_username>/<dataset_repo_id>"
|
HF_REPO_ID = "<hf_username>/<dataset_repo_id>"
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
# Create the robot and teleoperator configurations
|
# Create the robot and teleoperator configurations
|
||||||
camera_config = {"front": OpenCVCameraConfig(index_or_path=0, width=640, height=480, fps=FPS)}
|
camera_config = {"front": OpenCVCameraConfig(index_or_path=0, width=640, height=480, fps=FPS)}
|
||||||
robot_config = SO100FollowerConfig(
|
robot_config = SO100FollowerConfig(
|
||||||
@@ -72,7 +74,9 @@ kinematics_solver = RobotKinematics(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Build pipeline to convert phone action to EE action
|
# Build pipeline to convert phone action to EE action
|
||||||
phone_to_robot_ee_pose_processor = RobotProcessorPipeline[tuple[RobotAction, RobotObservation], RobotAction](
|
phone_to_robot_ee_pose_processor = RobotProcessorPipeline[
|
||||||
|
tuple[RobotAction, RobotObservation], RobotAction
|
||||||
|
](
|
||||||
steps=[
|
steps=[
|
||||||
MapPhoneActionToRobotAction(platform=teleop_config.phone_os),
|
MapPhoneActionToRobotAction(platform=teleop_config.phone_os),
|
||||||
EEReferenceAndDelta(
|
EEReferenceAndDelta(
|
||||||
@@ -107,7 +111,9 @@ robot_ee_to_joints_processor = RobotProcessorPipeline[tuple[RobotAction, RobotOb
|
|||||||
# Build pipeline to convert joint observation to EE observation
|
# Build pipeline to convert joint observation to EE observation
|
||||||
robot_joints_to_ee_pose = RobotProcessorPipeline[RobotObservation, RobotObservation](
|
robot_joints_to_ee_pose = RobotProcessorPipeline[RobotObservation, RobotObservation](
|
||||||
steps=[
|
steps=[
|
||||||
ForwardKinematicsJointsToEE(kinematics=kinematics_solver, motor_names=list(robot.bus.motors.keys()))
|
ForwardKinematicsJointsToEE(
|
||||||
|
kinematics=kinematics_solver, motor_names=list(robot.bus.motors.keys())
|
||||||
|
)
|
||||||
],
|
],
|
||||||
to_transition=observation_to_transition,
|
to_transition=observation_to_transition,
|
||||||
to_output=transition_to_observation,
|
to_output=transition_to_observation,
|
||||||
@@ -147,7 +153,6 @@ init_rerun(session_name="phone_so100_record")
|
|||||||
if not robot.is_connected or not phone.is_connected:
|
if not robot.is_connected or not phone.is_connected:
|
||||||
raise ValueError("Robot or teleop is not connected!")
|
raise ValueError("Robot or teleop is not connected!")
|
||||||
|
|
||||||
|
|
||||||
print("Starting record loop. Move your phone to teleoperate the robot...")
|
print("Starting record loop. Move your phone to teleoperate the robot...")
|
||||||
episode_idx = 0
|
episode_idx = 0
|
||||||
while episode_idx < NUM_EPISODES and not events["stop_recording"]:
|
while episode_idx < NUM_EPISODES and not events["stop_recording"]:
|
||||||
@@ -203,3 +208,7 @@ listener.stop()
|
|||||||
|
|
||||||
dataset.finalize()
|
dataset.finalize()
|
||||||
dataset.push_to_hub()
|
dataset.push_to_hub()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ from lerobot.utils.utils import log_say
|
|||||||
EPISODE_IDX = 0
|
EPISODE_IDX = 0
|
||||||
HF_REPO_ID = "<hf_username>/<dataset_repo_id>"
|
HF_REPO_ID = "<hf_username>/<dataset_repo_id>"
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
# Initialize the robot config
|
# Initialize the robot config
|
||||||
robot_config = SO100FollowerConfig(
|
robot_config = SO100FollowerConfig(
|
||||||
port="/dev/tty.usbmodem5A460814411", id="my_awesome_follower_arm", use_degrees=True
|
port="/dev/tty.usbmodem5A460814411", id="my_awesome_follower_arm", use_degrees=True
|
||||||
@@ -98,3 +100,7 @@ for idx in range(len(episode_frames)):
|
|||||||
|
|
||||||
# Clean up
|
# Clean up
|
||||||
robot.disconnect()
|
robot.disconnect()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ from lerobot.utils.visualization_utils import init_rerun, log_rerun_data
|
|||||||
|
|
||||||
FPS = 30
|
FPS = 30
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
# Initialize the robot and teleoperator
|
# Initialize the robot and teleoperator
|
||||||
robot_config = SO100FollowerConfig(
|
robot_config = SO100FollowerConfig(
|
||||||
port="/dev/tty.usbmodem5A460814411", id="my_awesome_follower_arm", use_degrees=True
|
port="/dev/tty.usbmodem5A460814411", id="my_awesome_follower_arm", use_degrees=True
|
||||||
@@ -55,7 +57,9 @@ kinematics_solver = RobotKinematics(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Build pipeline to convert phone action to ee pose action to joint action
|
# Build pipeline to convert phone action to ee pose action to joint action
|
||||||
phone_to_robot_joints_processor = RobotProcessorPipeline[tuple[RobotAction, RobotObservation], RobotAction](
|
phone_to_robot_joints_processor = RobotProcessorPipeline[
|
||||||
|
tuple[RobotAction, RobotObservation], RobotAction
|
||||||
|
](
|
||||||
steps=[
|
steps=[
|
||||||
MapPhoneActionToRobotAction(platform=teleop_config.phone_os),
|
MapPhoneActionToRobotAction(platform=teleop_config.phone_os),
|
||||||
EEReferenceAndDelta(
|
EEReferenceAndDelta(
|
||||||
@@ -111,3 +115,7 @@ while True:
|
|||||||
log_rerun_data(observation=phone_obs, action=joint_action)
|
log_rerun_data(observation=phone_obs, action=joint_action)
|
||||||
|
|
||||||
busy_wait(max(1.0 / FPS - (time.perf_counter() - t0), 0.0))
|
busy_wait(max(1.0 / FPS - (time.perf_counter() - t0), 0.0))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ TASK_DESCRIPTION = "My task description"
|
|||||||
HF_MODEL_ID = "<hf_username>/<model_repo_id>"
|
HF_MODEL_ID = "<hf_username>/<model_repo_id>"
|
||||||
HF_DATASET_ID = "<hf_username>/<dataset_repo_id>"
|
HF_DATASET_ID = "<hf_username>/<dataset_repo_id>"
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
# Create the robot configuration & robot
|
# Create the robot configuration & robot
|
||||||
camera_config = {"front": OpenCVCameraConfig(index_or_path=0, width=640, height=480, fps=FPS)}
|
camera_config = {"front": OpenCVCameraConfig(index_or_path=0, width=640, height=480, fps=FPS)}
|
||||||
robot_config = SO100FollowerConfig(
|
robot_config = SO100FollowerConfig(
|
||||||
@@ -89,13 +91,14 @@ robot_ee_to_joints_processor = RobotProcessorPipeline[tuple[RobotAction, RobotOb
|
|||||||
# Build pipeline to convert joints observation to EE observation
|
# Build pipeline to convert joints observation to EE observation
|
||||||
robot_joints_to_ee_pose_processor = RobotProcessorPipeline[RobotObservation, RobotObservation](
|
robot_joints_to_ee_pose_processor = RobotProcessorPipeline[RobotObservation, RobotObservation](
|
||||||
steps=[
|
steps=[
|
||||||
ForwardKinematicsJointsToEE(kinematics=kinematics_solver, motor_names=list(robot.bus.motors.keys()))
|
ForwardKinematicsJointsToEE(
|
||||||
|
kinematics=kinematics_solver, motor_names=list(robot.bus.motors.keys())
|
||||||
|
)
|
||||||
],
|
],
|
||||||
to_transition=observation_to_transition,
|
to_transition=observation_to_transition,
|
||||||
to_output=transition_to_observation,
|
to_output=transition_to_observation,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# Create the dataset
|
# Create the dataset
|
||||||
dataset = LeRobotDataset.create(
|
dataset = LeRobotDataset.create(
|
||||||
repo_id=HF_DATASET_ID,
|
repo_id=HF_DATASET_ID,
|
||||||
@@ -198,3 +201,7 @@ listener.stop()
|
|||||||
|
|
||||||
dataset.finalize()
|
dataset.finalize()
|
||||||
dataset.push_to_hub()
|
dataset.push_to_hub()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
@@ -48,10 +48,15 @@ RESET_TIME_SEC = 30
|
|||||||
TASK_DESCRIPTION = "My task description"
|
TASK_DESCRIPTION = "My task description"
|
||||||
HF_REPO_ID = "<hf_username>/<dataset_repo_id>"
|
HF_REPO_ID = "<hf_username>/<dataset_repo_id>"
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
# Create the robot and teleoperator configurations
|
# Create the robot and teleoperator configurations
|
||||||
camera_config = {"front": OpenCVCameraConfig(index_or_path=0, width=640, height=480, fps=FPS)}
|
camera_config = {"front": OpenCVCameraConfig(index_or_path=0, width=640, height=480, fps=FPS)}
|
||||||
follower_config = SO100FollowerConfig(
|
follower_config = SO100FollowerConfig(
|
||||||
port="/dev/tty.usbmodem5A460814411", id="my_awesome_follower_arm", cameras=camera_config, use_degrees=True
|
port="/dev/tty.usbmodem5A460814411",
|
||||||
|
id="my_awesome_follower_arm",
|
||||||
|
cameras=camera_config,
|
||||||
|
use_degrees=True,
|
||||||
)
|
)
|
||||||
leader_config = SO100LeaderConfig(port="/dev/tty.usbmodem5A460819811", id="my_awesome_leader_arm")
|
leader_config = SO100LeaderConfig(port="/dev/tty.usbmodem5A460819811", id="my_awesome_leader_arm")
|
||||||
|
|
||||||
@@ -135,7 +140,6 @@ dataset = LeRobotDataset.create(
|
|||||||
image_writer_threads=4,
|
image_writer_threads=4,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# Connect the robot and teleoperator
|
# Connect the robot and teleoperator
|
||||||
leader.connect()
|
leader.connect()
|
||||||
follower.connect()
|
follower.connect()
|
||||||
@@ -202,3 +206,7 @@ listener.stop()
|
|||||||
|
|
||||||
dataset.finalize()
|
dataset.finalize()
|
||||||
dataset.push_to_hub()
|
dataset.push_to_hub()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ from lerobot.utils.utils import log_say
|
|||||||
EPISODE_IDX = 0
|
EPISODE_IDX = 0
|
||||||
HF_REPO_ID = "<hf_username>/<dataset_repo_id>"
|
HF_REPO_ID = "<hf_username>/<dataset_repo_id>"
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
# Initialize the robot config
|
# Initialize the robot config
|
||||||
robot_config = SO100FollowerConfig(
|
robot_config = SO100FollowerConfig(
|
||||||
port="/dev/tty.usbmodem5A460814411", id="my_awesome_follower_arm", use_degrees=True
|
port="/dev/tty.usbmodem5A460814411", id="my_awesome_follower_arm", use_degrees=True
|
||||||
@@ -99,3 +101,7 @@ for idx in range(len(episode_frames)):
|
|||||||
|
|
||||||
# Clean up
|
# Clean up
|
||||||
robot.disconnect()
|
robot.disconnect()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ from lerobot.utils.visualization_utils import init_rerun, log_rerun_data
|
|||||||
|
|
||||||
FPS = 30
|
FPS = 30
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
# Initialize the robot and teleoperator config
|
# Initialize the robot and teleoperator config
|
||||||
follower_config = SO100FollowerConfig(
|
follower_config = SO100FollowerConfig(
|
||||||
port="/dev/tty.usbmodem5A460814411", id="my_awesome_follower_arm", use_degrees=True
|
port="/dev/tty.usbmodem5A460814411", id="my_awesome_follower_arm", use_degrees=True
|
||||||
@@ -119,3 +121,7 @@ while True:
|
|||||||
log_rerun_data(observation=leader_ee_act, action=follower_joints_act)
|
log_rerun_data(observation=leader_ee_act, action=follower_joints_act)
|
||||||
|
|
||||||
busy_wait(max(1.0 / FPS - (time.perf_counter() - t0), 0.0))
|
busy_wait(max(1.0 / FPS - (time.perf_counter() - t0), 0.0))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ def make_delta_timestamps(delta_indices: list[int] | None, fps: int) -> list[flo
|
|||||||
return [i / fps for i in delta_indices]
|
return [i / fps for i in delta_indices]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
output_directory = Path("outputs/robot_learning_tutorial/act")
|
output_directory = Path("outputs/robot_learning_tutorial/act")
|
||||||
output_directory.mkdir(parents=True, exist_ok=True)
|
output_directory.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
@@ -48,7 +49,8 @@ delta_timestamps = {
|
|||||||
|
|
||||||
# add image features if they are present
|
# add image features if they are present
|
||||||
delta_timestamps |= {
|
delta_timestamps |= {
|
||||||
k: make_delta_timestamps(cfg.observation_delta_indices, dataset_metadata.fps) for k in cfg.image_features
|
k: make_delta_timestamps(cfg.observation_delta_indices, dataset_metadata.fps)
|
||||||
|
for k in cfg.image_features
|
||||||
}
|
}
|
||||||
|
|
||||||
# Instantiate the dataset
|
# Instantiate the dataset
|
||||||
@@ -93,6 +95,10 @@ preprocessor.save_pretrained(output_directory)
|
|||||||
postprocessor.save_pretrained(output_directory)
|
postprocessor.save_pretrained(output_directory)
|
||||||
|
|
||||||
# Save all assets to the Hub
|
# Save all assets to the Hub
|
||||||
policy.push_to_hub("fracapuano/robot_learning_tutorial_act")
|
policy.push_to_hub("<user>/robot_learning_tutorial_act")
|
||||||
preprocessor.push_to_hub("fracapuano/robot_learning_tutorial_act")
|
preprocessor.push_to_hub("<user>/robot_learning_tutorial_act")
|
||||||
postprocessor.push_to_hub("fracapuano/robot_learning_tutorial_act")
|
postprocessor.push_to_hub("<user>/robot_learning_tutorial_act")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
@@ -8,8 +8,13 @@ from lerobot.policies.utils import build_inference_frame, make_robot_action
|
|||||||
from lerobot.robots.so100_follower.config_so100_follower import SO100FollowerConfig
|
from lerobot.robots.so100_follower.config_so100_follower import SO100FollowerConfig
|
||||||
from lerobot.robots.so100_follower.so100_follower import SO100Follower
|
from lerobot.robots.so100_follower.so100_follower import SO100Follower
|
||||||
|
|
||||||
|
MAX_EPISODES = 5
|
||||||
|
MAX_STEPS_PER_EPISODE = 20
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
device = torch.device("mps") # or "cuda" or "cpu"
|
device = torch.device("mps") # or "cuda" or "cpu"
|
||||||
model_id = "fracapuano/robot_learning_tutorial_act"
|
model_id = "<user>/robot_learning_tutorial_act"
|
||||||
model = ACTPolicy.from_pretrained(model_id)
|
model = ACTPolicy.from_pretrained(model_id)
|
||||||
|
|
||||||
dataset_id = "lerobot/svla_so101_pickplace"
|
dataset_id = "lerobot/svla_so101_pickplace"
|
||||||
@@ -23,9 +28,6 @@ follower_port = ... # something like "/dev/tty.usbmodem58760431631"
|
|||||||
# # the robot ids are used the load the right calibration files
|
# # the robot ids are used the load the right calibration files
|
||||||
follower_id = ... # something like "follower_so100"
|
follower_id = ... # something like "follower_so100"
|
||||||
|
|
||||||
MAX_EPISODES = 5
|
|
||||||
MAX_STEPS_PER_EPISODE = 20
|
|
||||||
|
|
||||||
# Robot and environment configuration
|
# Robot and environment configuration
|
||||||
# Camera keys must match the name and resolutions of the ones used for training!
|
# Camera keys must match the name and resolutions of the ones used for training!
|
||||||
# You can check the camera keys expected by a model in the info.json card on the model card on the Hub
|
# You can check the camera keys expected by a model in the info.json card on the model card on the Hub
|
||||||
@@ -55,3 +57,7 @@ for _ in range(MAX_EPISODES):
|
|||||||
robot.send_action(action)
|
robot.send_action(action)
|
||||||
|
|
||||||
print("Episode finished! Starting new episode...")
|
print("Episode finished! Starting new episode...")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
from lerobot.async_inference.configs import PolicyServerConfig
|
from lerobot.async_inference.configs import PolicyServerConfig
|
||||||
from lerobot.async_inference.policy_server import serve
|
from lerobot.async_inference.policy_server import serve
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
host = ... # something like "127.0.0.1" if you're exposing to localhost
|
host = ... # something like "127.0.0.1" if you're exposing to localhost
|
||||||
port = ... # something like 8080
|
port = ... # something like 8080
|
||||||
|
|
||||||
@@ -9,3 +11,7 @@ config = PolicyServerConfig(
|
|||||||
port=port,
|
port=port,
|
||||||
)
|
)
|
||||||
serve(config)
|
serve(config)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ from lerobot.async_inference.robot_client import RobotClient
|
|||||||
from lerobot.cameras.opencv.configuration_opencv import OpenCVCameraConfig
|
from lerobot.cameras.opencv.configuration_opencv import OpenCVCameraConfig
|
||||||
from lerobot.robots.so100_follower import SO100FollowerConfig
|
from lerobot.robots.so100_follower import SO100FollowerConfig
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
# these cameras must match the ones expected by the policy - find your cameras with lerobot-find-cameras
|
# these cameras must match the ones expected by the policy - find your cameras with lerobot-find-cameras
|
||||||
# check the config.json on the Hub for the policy you are using to see the expected camera specs
|
# check the config.json on the Hub for the policy you are using to see the expected camera specs
|
||||||
camera_cfg = {
|
camera_cfg = {
|
||||||
@@ -29,7 +31,7 @@ client_cfg = RobotClientConfig(
|
|||||||
server_address=server_address,
|
server_address=server_address,
|
||||||
policy_device="mps",
|
policy_device="mps",
|
||||||
policy_type="act",
|
policy_type="act",
|
||||||
pretrained_name_or_path="fracapuano/robot_learning_tutorial_act",
|
pretrained_name_or_path="<user>/robot_learning_tutorial_act",
|
||||||
chunk_size_threshold=0.5, # g
|
chunk_size_threshold=0.5, # g
|
||||||
actions_per_chunk=50, # make sure this is less than the max actions of the policy
|
actions_per_chunk=50, # make sure this is less than the max actions of the policy
|
||||||
)
|
)
|
||||||
@@ -53,3 +55,7 @@ if client.start():
|
|||||||
action_receiver_thread.join()
|
action_receiver_thread.join()
|
||||||
# (Optionally) plot the action queue size
|
# (Optionally) plot the action queue size
|
||||||
visualize_action_queue_size(client.action_queue_size)
|
visualize_action_queue_size(client.action_queue_size)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ def make_delta_timestamps(delta_indices: list[int] | None, fps: int) -> list[flo
|
|||||||
return [i / fps for i in delta_indices]
|
return [i / fps for i in delta_indices]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
output_directory = Path("outputs/robot_learning_tutorial/diffusion")
|
output_directory = Path("outputs/robot_learning_tutorial/diffusion")
|
||||||
output_directory.mkdir(parents=True, exist_ok=True)
|
output_directory.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
@@ -49,7 +50,8 @@ delta_timestamps = {
|
|||||||
|
|
||||||
# add image features if they are present
|
# add image features if they are present
|
||||||
delta_timestamps |= {
|
delta_timestamps |= {
|
||||||
k: make_delta_timestamps(cfg.observation_delta_indices, dataset_metadata.fps) for k in cfg.image_features
|
k: make_delta_timestamps(cfg.observation_delta_indices, dataset_metadata.fps)
|
||||||
|
for k in cfg.image_features
|
||||||
}
|
}
|
||||||
|
|
||||||
# Instantiate the dataset
|
# Instantiate the dataset
|
||||||
@@ -94,6 +96,10 @@ preprocessor.save_pretrained(output_directory)
|
|||||||
postprocessor.save_pretrained(output_directory)
|
postprocessor.save_pretrained(output_directory)
|
||||||
|
|
||||||
# Save all assets to the Hub
|
# Save all assets to the Hub
|
||||||
policy.push_to_hub("fracapuano/robot_learning_tutorial_diffusion")
|
policy.push_to_hub("<user>/robot_learning_tutorial_diffusion")
|
||||||
preprocessor.push_to_hub("fracapuano/robot_learning_tutorial_diffusion")
|
preprocessor.push_to_hub("<user>/robot_learning_tutorial_diffusion")
|
||||||
postprocessor.push_to_hub("fracapuano/robot_learning_tutorial_diffusion")
|
postprocessor.push_to_hub("<user>/robot_learning_tutorial_diffusion")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
@@ -8,8 +8,13 @@ from lerobot.policies.utils import build_inference_frame, make_robot_action
|
|||||||
from lerobot.robots.so100_follower.config_so100_follower import SO100FollowerConfig
|
from lerobot.robots.so100_follower.config_so100_follower import SO100FollowerConfig
|
||||||
from lerobot.robots.so100_follower.so100_follower import SO100Follower
|
from lerobot.robots.so100_follower.so100_follower import SO100Follower
|
||||||
|
|
||||||
|
MAX_EPISODES = 5
|
||||||
|
MAX_STEPS_PER_EPISODE = 20
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
device = torch.device("mps") # or "cuda" or "cpu"
|
device = torch.device("mps") # or "cuda" or "cpu"
|
||||||
model_id = "fracapuano/robot_learning_tutorial_diffusion"
|
model_id = "<user>/robot_learning_tutorial_diffusion"
|
||||||
|
|
||||||
model = DiffusionPolicy.from_pretrained(model_id)
|
model = DiffusionPolicy.from_pretrained(model_id)
|
||||||
|
|
||||||
@@ -20,10 +25,6 @@ preprocess, postprocess = make_pre_post_processors(
|
|||||||
model.config, model_id, dataset_stats=dataset_metadata.stats
|
model.config, model_id, dataset_stats=dataset_metadata.stats
|
||||||
)
|
)
|
||||||
|
|
||||||
MAX_EPISODES = 5
|
|
||||||
MAX_STEPS_PER_EPISODE = 20
|
|
||||||
|
|
||||||
|
|
||||||
# # find ports using lerobot-find-port
|
# # find ports using lerobot-find-port
|
||||||
follower_port = ... # something like "/dev/tty.usbmodem58760431631"
|
follower_port = ... # something like "/dev/tty.usbmodem58760431631"
|
||||||
|
|
||||||
@@ -42,7 +43,6 @@ robot_cfg = SO100FollowerConfig(port=follower_port, id=follower_id, cameras=came
|
|||||||
robot = SO100Follower(robot_cfg)
|
robot = SO100Follower(robot_cfg)
|
||||||
robot.connect()
|
robot.connect()
|
||||||
|
|
||||||
|
|
||||||
for _ in range(MAX_EPISODES):
|
for _ in range(MAX_EPISODES):
|
||||||
for _ in range(MAX_STEPS_PER_EPISODE):
|
for _ in range(MAX_STEPS_PER_EPISODE):
|
||||||
obs = robot.get_observation()
|
obs = robot.get_observation()
|
||||||
@@ -58,3 +58,7 @@ for _ in range(MAX_EPISODES):
|
|||||||
robot.send_action(action)
|
robot.send_action(action)
|
||||||
|
|
||||||
print("Episode finished! Starting new episode...")
|
print("Episode finished! Starting new episode...")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ from lerobot.robots.so100_follower.so100_follower import SO100Follower
|
|||||||
MAX_EPISODES = 5
|
MAX_EPISODES = 5
|
||||||
MAX_STEPS_PER_EPISODE = 20
|
MAX_STEPS_PER_EPISODE = 20
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
device = torch.device("mps") # or "cuda" or "cpu"
|
device = torch.device("mps") # or "cuda" or "cpu"
|
||||||
model_id = "lerobot/pi0_base"
|
model_id = "lerobot/pi0_base"
|
||||||
|
|
||||||
@@ -65,3 +67,7 @@ for _ in range(MAX_EPISODES):
|
|||||||
robot.send_action(action)
|
robot.send_action(action)
|
||||||
|
|
||||||
print("Episode finished! Starting new episode...")
|
print("Episode finished! Starting new episode...")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ from lerobot.teleoperators.utils import TeleopEvents
|
|||||||
|
|
||||||
LOG_EVERY = 10
|
LOG_EVERY = 10
|
||||||
SEND_EVERY = 10
|
SEND_EVERY = 10
|
||||||
|
MAX_EPISODES = 5
|
||||||
|
MAX_STEPS_PER_EPISODE = 20
|
||||||
|
|
||||||
|
|
||||||
def run_learner(
|
def run_learner(
|
||||||
@@ -223,6 +225,7 @@ def make_policy_obs(obs, device: torch.device = "cpu"):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
"""Main function - coordinates actor and learner processes."""
|
"""Main function - coordinates actor and learner processes."""
|
||||||
|
|
||||||
device = "mps" # or "cuda" or "cpu"
|
device = "mps" # or "cuda" or "cpu"
|
||||||
@@ -238,15 +241,12 @@ follower_id = ...
|
|||||||
leader_id = ...
|
leader_id = ...
|
||||||
|
|
||||||
# A pretrained model (to be used in-distribution!)
|
# A pretrained model (to be used in-distribution!)
|
||||||
reward_classifier_id = "fracapuano/reward_classifier_hil_serl_example"
|
reward_classifier_id = "<user>/reward_classifier_hil_serl_example"
|
||||||
reward_classifier = Classifier.from_pretrained(reward_classifier_id)
|
reward_classifier = Classifier.from_pretrained(reward_classifier_id)
|
||||||
|
|
||||||
reward_classifier.to(device)
|
reward_classifier.to(device)
|
||||||
reward_classifier.eval()
|
reward_classifier.eval()
|
||||||
|
|
||||||
MAX_EPISODES = 5
|
|
||||||
MAX_STEPS_PER_EPISODE = 20
|
|
||||||
|
|
||||||
# Robot and environment configuration
|
# Robot and environment configuration
|
||||||
robot_cfg = SO100FollowerConfig(port=follower_port, id=follower_id)
|
robot_cfg = SO100FollowerConfig(port=follower_port, id=follower_id)
|
||||||
teleop_cfg = SO100LeaderConfig(port=leader_port, id=leader_id)
|
teleop_cfg = SO100LeaderConfig(port=leader_port, id=leader_id)
|
||||||
@@ -285,13 +285,11 @@ transitions_queue = mp.Queue(maxsize=10)
|
|||||||
parameters_queue = mp.Queue(maxsize=2)
|
parameters_queue = mp.Queue(maxsize=2)
|
||||||
shutdown_event = mp.Event()
|
shutdown_event = mp.Event()
|
||||||
|
|
||||||
|
|
||||||
# Signal handler for graceful shutdown
|
# Signal handler for graceful shutdown
|
||||||
def signal_handler(sig):
|
def signal_handler(sig):
|
||||||
print(f"\nSignal {sig} received, shutting down...")
|
print(f"\nSignal {sig} received, shutting down...")
|
||||||
shutdown_event.set()
|
shutdown_event.set()
|
||||||
|
|
||||||
|
|
||||||
signal.signal(signal.SIGINT, signal_handler)
|
signal.signal(signal.SIGINT, signal_handler)
|
||||||
signal.signal(signal.SIGTERM, signal_handler)
|
signal.signal(signal.SIGTERM, signal_handler)
|
||||||
|
|
||||||
@@ -343,3 +341,7 @@ finally:
|
|||||||
learner_process.terminate()
|
learner_process.terminate()
|
||||||
if actor_process.is_alive():
|
if actor_process.is_alive():
|
||||||
actor_process.terminate()
|
actor_process.terminate()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ from lerobot.datasets.lerobot_dataset import LeRobotDataset
|
|||||||
from lerobot.policies.factory import make_policy, make_pre_post_processors
|
from lerobot.policies.factory import make_policy, make_pre_post_processors
|
||||||
from lerobot.policies.sac.reward_model.configuration_classifier import RewardClassifierConfig
|
from lerobot.policies.sac.reward_model.configuration_classifier import RewardClassifierConfig
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
# Device to use for training
|
# Device to use for training
|
||||||
device = "mps" # or "cuda", or "cpu"
|
device = "mps" # or "cuda", or "cpu"
|
||||||
|
|
||||||
@@ -26,8 +28,7 @@ policy = make_policy(config, ds_meta=dataset.meta)
|
|||||||
optimizer = config.get_optimizer_preset().build(policy.parameters())
|
optimizer = config.get_optimizer_preset().build(policy.parameters())
|
||||||
preprocessor, _ = make_pre_post_processors(policy_cfg=config, dataset_stats=dataset.meta.stats)
|
preprocessor, _ = make_pre_post_processors(policy_cfg=config, dataset_stats=dataset.meta.stats)
|
||||||
|
|
||||||
|
classifier_id = "<user>/reward_classifier_hil_serl_example"
|
||||||
classifier_id = "fracapuano/reward_classifier_hil_serl_example"
|
|
||||||
|
|
||||||
# Instantiate a dataloader
|
# Instantiate a dataloader
|
||||||
dataloader = torch.utils.data.DataLoader(dataset, batch_size=16, shuffle=True)
|
dataloader = torch.utils.data.DataLoader(dataset, batch_size=16, shuffle=True)
|
||||||
@@ -60,3 +61,7 @@ print("Training finished!")
|
|||||||
|
|
||||||
# You can now save the trained policy.
|
# You can now save the trained policy.
|
||||||
policy.push_to_hub(classifier_id)
|
policy.push_to_hub(classifier_id)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ from lerobot.robots.so100_follower.so100_follower import SO100Follower
|
|||||||
MAX_EPISODES = 5
|
MAX_EPISODES = 5
|
||||||
MAX_STEPS_PER_EPISODE = 20
|
MAX_STEPS_PER_EPISODE = 20
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
device = torch.device("mps") # or "cuda" or "cpu"
|
device = torch.device("mps") # or "cuda" or "cpu"
|
||||||
model_id = "lerobot/smolvla_base"
|
model_id = "lerobot/smolvla_base"
|
||||||
|
|
||||||
@@ -64,3 +66,7 @@ for _ in range(MAX_EPISODES):
|
|||||||
robot.send_action(action)
|
robot.send_action(action)
|
||||||
|
|
||||||
print("Episode finished! Starting new episode...")
|
print("Episode finished! Starting new episode...")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user