Skip to content

Latest commit

 

History

History
160 lines (123 loc) · 5.84 KB

File metadata and controls

160 lines (123 loc) · 5.84 KB

Inference Tools

실시간 inference를 위한 도구들입니다.

파일 구조

경로 역할
maskact/inference_time_topic.py 실시간 mask 생성 + end-pose TF publish (메인 inference 노드)
maskact/handle_pruning.py pruning indicator 토글 publish
maskact/mask_distribution_monitor.py mask가 학습 분포(in-distribution) 안에 들어오는 비율을 실시간 시각화
maskact/mask_distribution_classifier.py 누적 분포 .npy로 in/out-distribution 판정하는 유틸 클래스
end_pose/inference_time_end_pose.py TF에서 end-pose만 publish하는 경량 노드 (rosbag replay 분리용)
zed_tf/zed_tf_with_cloud.py ZED 스테레오로 2D 클릭을 3D로 변환해 타겟 TF publish (별도 README)

inference/zed/ 폴더는 현재 placeholder(__init__.py만 존재)입니다.

MaskACT Inference

inference_time_topic.py

실시간으로 mask 이미지를 생성하고 TF 정보를 publish하는 노드입니다.

기능:

  1. /end_pose_left, /end_pose_right publish (PoseStamped)
  2. /zed 이미지 창(OpenCV) 띄우고 마우스 클릭으로 타겟 지정
  3. 타겟 기반 mask 생성:
    • pruning_topic == 1.0 이면 mask OFF (all-zero)
    • 기본: SAM2 우선(옵션), 실패 시 bbox tracker fallback
  4. mask를 /mf_perception/ch0_binary_image_sam2/compressed로 publish (png CompressedImage)

사용법:

cd /workspace/physical_ai_tools/learning_data_preprocessing
python3 inference/maskact/inference_time_topic.py \
    --image-topic /zed/zed_node/left/image_rect_color/compressed \
    --out-topic /mf_perception/ch0_binary_image_sam2/compressed \
    --pruning-topic /mf_perception/ch0_pruning_indicator \
    --base-left arm_l_link1 --ee-left arm_l_link7 \
    --base-right arm_r_link1 --ee-right arm_r_link7 \
    --window-w 1280 --window-h 720 \
    --max-tf-dt-sec 0.5 \
    --visualize \
    --use-sam --sam-checkpoint rosbag_preprocessing/maskact/sam2_b.pt

의존성:

  • ROS2 Humble/Jazzy (rclpy)
  • opencv-python
  • numpy
  • tf2_ros
  • ultralytics (SAM2DynamicInteractivePredictor, 옵션)

handle_pruning.py

Pruning indicator를 publish하는 간단한 노드입니다.

사용법:

python3 inference/maskact/handle_pruning.py

기능:

  • /mf_perception/ch0_pruning_indicator 토픽에 Float32 메시지 publish
  • 키보드 입력으로 값 토글 (기본값: 0.0)

mask_distribution_monitor.py

생성되는 mask가 학습 데이터의 누적 mask 분포 안에 얼마나 들어오는지 실시간으로 모니터링합니다.

사용법:

python3 inference/maskact/mask_distribution_monitor.py \
    --distribution-npy /workspace/dkim_result_3_extracted_masks/mask_distribution_accumulated.npy \
    --mask-topic /mf_perception/ch0_binary_image_sam2/compressed \
    --visualize

기능:

  • 압축 mask 토픽을 구독해 in-distribution 영역 안의 픽셀 비율(coverage %) 계산
  • in-distribution(녹색) / out-distribution(빨강) 영역을 색상으로 시각화
  • --threshold, --threshold-type(absolute/percentile)로 판정 기준 조정
  • mask_distribution_accumulated.npyscripts/visualize_mask_distribution.py로 생성

mask_distribution_classifier.py

mask_distribution_monitor.py가 사용하는 판정 유틸 클래스입니다. 단독 실행 시 테스트 mask에 대한 분포 시각화를 생성합니다.

사용법(단독 테스트):

python3 inference/maskact/mask_distribution_classifier.py \
    --npy /path/to/mask_distribution_accumulated.npy \
    --threshold 10 --threshold-type absolute \
    --mask /path/to/test_mask.png --output vis.png

제공 메서드: is_in_distribution(), calculate_coverage_percentage(), visualize_distribution(), get_statistics()

End Pose Inference

end_pose/inference_time_end_pose.py

inference_time_topic.py에서 end-pose publish 부분만 떼어낸 경량 노드입니다. mask 생성 없이 TF에서 end-effector pose만 publish하므로 rosbag replay와 분리해 쓰기 좋습니다.

사용법:

# 실제 로봇
python3 inference/end_pose/inference_time_end_pose.py \
    --base-left arm_l_link1 --ee-left arm_l_link7 \
    --base-right arm_r_link1 --ee-right arm_r_link7 \
    --rate 50

# rosbag replay와 함께 (--clock 동기화)
python3 inference/end_pose/inference_time_end_pose.py \
    --base-left arm_l_link1 --ee-left arm_l_link7 \
    --base-right arm_r_link1 --ee-right arm_r_link7 \
    --rate 50 --use-sim-time

기능:

  • /end_pose_left, /end_pose_right를 PoseStamped로 publish
  • spin thread 기반 TF buffer로 백그라운드 TF 갱신, --use-sim-time으로 rosbag --clock 동기화 지원

Inference 워크플로우

MaskACT Inference

  1. 로봇 켜기

    ssh robotis@ffw-snpr48a1027.local
  2. 목 내리기 (rosbag 재생)

    ros2 bag play /workspace/rosbag2/dkim/ffw_sg2_rev1_dkim/123/ --clock -l --topics /leader/joystick_controller_left/joint_trajectory
  3. Mask 이미지 생성 및 TF 뿌리기

    python3 inference/maskact/inference_time_topic.py \
        --image-topic /zed/zed_node/left/image_rect_color/compressed \
        --out-topic /mf_perception/ch0_binary_image_sam2/compressed \
        --pruning-topic /mf_perception/ch0_pruning_indicator \
        --base-left arm_l_link1 --ee-left arm_l_link7 \
        --base-right arm_r_link1 --ee-right arm_r_link7 \
        --window-w 1280 --window-h 720 \
        --max-tf-dt-sec 0.5 \
        --visualize \
        --use-sam --sam-checkpoint ../rosbag_preprocessing/maskact/sam2_b.pt

ZED TF with Cloud (2D → 3D 변환)

ZED 스테레오 카메라를 사용하여 이미지에서 클릭한 위치를 3D로 변환하고 TF 메시지로 publish합니다.

python3 inference/zed_tf/zed_tf_with_cloud.py

자세한 내용: ZED TF with Cloud README