
    qi;                        d Z ddlZddlZddlZddlmZ ddlmZ	 de
fdZdej        fdZ ej        d	           G d
 dej                              Z ej        d	           G d dej                              ZdS )zPolicy inputs/outputs for the YAM bimanual robot.

State/action: 14D joint positions [left_joint(6), left_grip(1), right_joint(6), right_grip(1)]
Cameras: head (base view), left_wrist, right_wrist
    N)
transforms)modelreturnc                     t           j                            d                              t           j                  t           j                            ddt           j                  t           j                            ddt           j                  t           j                            ddt           j                  ddS )z2Creates a random input example for the YAM policy.      )   r	      )sizedtypez(pick up the lock and put it into the box)observation/stateobservation/image_headobservation/image_left_wristobservation/image_right_wristprompt)nprandomrandastypefloat32randintuint8     ;/home/robot-lab/Pi0.5_yam/src/openpi/policies/yam_policy.pymake_yam_exampler      s      Y^^B//66rzBB"$)"3"3CmSUS["3"\"\(*	(9(9#MY[Ya(9(b(b)+):):3]Z\Zb):)c)c<  r   c                    t          j        |           } t          j        | j        t           j                  r"d| z                      t           j                  } | j        d         dk    rt          j	        | d          } | S )N   r   r
   zc h w -> h w c)
r   asarray
issubdtyper   floatingr   r   shapeeinops	rearrange)images    r   _parse_imager&      sk    JuE	}U["+.. /u$$RX..{1~ (899Lr   T)frozenc                   P    e Zd ZU dZej        j        Zej        ed<   de	de	fdZ
dS )	YAMInputsat  Inputs for the YAM bimanual policy.

    Expected inputs:
    - observation/image_head: base camera image
    - observation/image_left_wrist: left wrist camera image
    - observation/image_right_wrist: right wrist camera image
    - observation/state: [14] joint positions
    - actions: [action_horizon, 14] (only during training)
    - prompt: language instruction
    
model_typedatar   c                 $   t          |d                   }t          |d                   }t          |d                   }|d         |||dt          j        t          j        t          j        dd}d|v r|d         |d<   d|v r|d         |d<   |S )	Nr   r   r   r   )
base_0_rgbleft_wrist_0_rgbright_wrist_0_rgb)stater%   
image_maskactionsr   )r&   r   True_)selfr+   
base_imageleft_wrist_imageright_wrist_imageinputss         r   __call__zYAMInputs.__call__3   s    !$'?"@AA
'-K(LMM(.M)NOO -.($4%6  !h$&H%'X 
 
  $YF9t#H~F8r   N)__name__
__module____qualname____doc___model	ModelTypePI0r*   __annotations__dictr9   r   r   r   r)   r)   $   s]         	 	 $*#3#7J 777T d      r   r)   c                   "    e Zd ZdZdedefdZdS )
YAMOutputszuOutputs for the YAM bimanual policy.

    Returns the first 14 action dimensions (matching the 14D joint space).
    r+   r   c                 R    dt          j        |d         d d d df                   iS )Nr2   r   )r   r   )r4   r+   s     r   r9   zYAMOutputs.__call__V   s,    2:d9oaaa"f&=>>??r   N)r:   r;   r<   r=   rB   r9   r   r   r   rD   rD   O   sH         
@T @d @ @ @ @ @ @r   rD   )r=   dataclassesr#   numpyr   openpir   openpi.modelsr   r>   rB   r   ndarrayr&   	dataclassDataTransformFnr)   rD   r   r   r   <module>rM      s7                   ) ) ) ) ) )$    2:     d###' ' ' ' '
* ' ' $#'T d###@ @ @ @ @+ @ @ $#@ @ @r   