Example #1
0
  def test_hdf5_agrees_with_textprotos(self):

    hdf5_loader = loader.HDF5TrajectoryLoader(
        resources.GetResourceFilename(HDF5))

    for textproto_path in TEXTPROTOS:
      trajectory_textproto = resources.GetResource(textproto_path)
      trajectory_from_textproto = mocap_pb2.FittedTrajectory()
      text_format.Parse(trajectory_textproto, trajectory_from_textproto)

      trajectory_identifier = (
          trajectory_from_textproto.identifier.encode('utf-8'))
      self.assert_proto_equal(
          hdf5_loader.get_trajectory(trajectory_identifier)._proto,
          trajectory.Trajectory(trajectory_from_textproto)._proto)
Example #2
0
def print_stats(name, dataset):
    ref_path = cmu_mocap_data.get_path_for_cmu_2020()
    clip_loader = loader.HDF5TrajectoryLoader(ref_path)
    clip_lengths = []
    clips = []
    for clip_id in dataset.ids:
        trajectory = clip_loader.get_trajectory(clip_id)
        clip_lengths.append(trajectory.num_steps)
        clips.append((clip_id, trajectory.num_steps))
    print('{}: Clips: {} AvgLength: {:.1f} TotalFrames: {}'.format(
        name,
        len(dataset.ids), 
        sum(clip_lengths)/len(clip_lengths),
        sum(clip_lengths)))
    for clip_id, length in sorted(clips, key=lambda clip: clip[1]):
        print(clip_id, length)
Example #3
0
def _get_all_clip_infos_if_necessary():
    """Creates the global _ALL_CLIPS list if it has not already been created."""
    global _ALL_CLIPS
    if _ALL_CLIPS is None:
        loader = mocap_loader.HDF5TrajectoryLoader(
            H5_PATH, trajectories.WarehouseTrajectory)
        clip_numbers = (1, 2, 3, 4, 5, 6, 9, 10, 11, 12, 15, 16, 17, 18, 19,
                        20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
                        34, 35, 36, 37, 38, 39, 40, 42, 43, 44, 45, 46, 47, 48,
                        49, 50, 51, 52, 53)

        clip_infos = []
        for i, clip_number in enumerate(clip_numbers):
            flags = 0

            if i in _FLOOR_LEVEL:
                flags |= Flag.FLOOR_LEVEL
            elif i in _MEDIUM_PEDESTAL:
                flags |= Flag.MEDIUM_PEDESTAL
            elif i in _HIGH_PEDESTAL:
                flags |= Flag.HIGH_PEDESTAL

            if i in _LIGHT_PROP:
                flags |= Flag.LIGHT_PROP
            elif i in _HEAVY_PROP:
                flags |= Flag.HEAVY_PROP

            if i in _SMALL_BOX:
                flags |= Flag.SMALL_PROP
                flags |= Flag.BOX
            elif i in _LARGE_BOX:
                flags |= Flag.LARGE_PROP
                flags |= Flag.BOX
            elif i in _SMALL_BALL:
                flags |= Flag.SMALL_PROP
                flags |= Flag.BALL
            elif i in _LARGE_BALL:
                flags |= Flag.LARGE_PROP
                flags |= Flag.BALL
            clip_infos.append(_get_clip_info(loader, clip_number, flags))

        _ALL_CLIPS = tuple(clip_infos)
Example #4
0
  def _load_reference_data(self, ref_path, proto_modifier,
                           dataset: types.ClipCollection):
    self._loader = loader.HDF5TrajectoryLoader(
        ref_path, proto_modifier=proto_modifier)

    self._dataset = dataset
    self._num_clips = len(self._dataset.ids)

    if self._dataset.end_steps is None:
      # load all trajectories to infer clip end steps.
      self._all_clips = [
          self._loader.get_trajectory(  # pylint: disable=g-complex-comprehension
              clip_id,
              start_step=clip_start_step,
              end_step=_MAX_END_STEP) for clip_id, clip_start_step in zip(
                  self._dataset.ids, self._dataset.start_steps)
      ]
      # infer clip end steps to set sampling distribution
      self._dataset.end_steps = tuple(clip.end_step for clip in self._all_clips)
    else:
      self._all_clips = [None] * self._num_clips
Example #5
0
 def __init__(self, mocap_key='CMU_077_02', version='2019'):
     """Load the trajectory."""
     ref_path = cmu_mocap_data.get_path_for_cmu(version)
     self._loader = loader.HDF5TrajectoryLoader(ref_path)
     self._trajectory = self._loader.get_trajectory(mocap_key)
Example #6
0
  def __init__(self, walker,
               proto_modifier=None,
               negative_reward_on_failure_termination=True,
               priority_friction=False,
               bucket_offset=1.,
               y_range=0.5,
               toss_delay=0.5,
               randomize_init=False,
              ):
    """Initialize ball tossing task.

    Args:
      walker: the walker to be used in this task.
      proto_modifier: function to modify trajectory proto.
      negative_reward_on_failure_termination: flag to provide negative reward
        as task fails.
      priority_friction: sets friction priority thereby making prop objects have
        higher friction.
      bucket_offset: distance in meters to push bucket (away from walker)
      y_range: range (uniformly sampled) of distance in meters the ball is
        thrown left/right of the walker.
      toss_delay: time in seconds to delay after catching before changing reward
        to encourage throwing the ball.
      randomize_init: flag to randomize initial pose.
    """
    self._proto_modifier = proto_modifier
    self._negative_reward_on_failure_termination = (
        negative_reward_on_failure_termination)
    self._priority_friction = priority_friction
    self._bucket_rewarded = False
    self._bucket_offset = bucket_offset
    self._y_range = y_range
    self._toss_delay = toss_delay
    self._randomize_init = randomize_init

    # load a clip to grab a ball prop and initializations
    loader = mocap_loader.HDF5TrajectoryLoader(
        mocap_data.H5_PATH, trajectories.WarehouseTrajectory)
    clip_number = 54
    self._trajectory = loader.get_trajectory(
        mocap_data.IDENTIFIER_TEMPLATE.format(clip_number))

    # create the floor arena
    self._arena = floors.Floor()

    self._walker = walker
    self._walker_geoms = tuple(self._walker.mjcf_model.find_all('geom'))
    self._feet_geoms = (
        walker.mjcf_model.find('body', 'lfoot').find_all('geom') +
        walker.mjcf_model.find('body', 'rfoot').find_all('geom'))
    self._lhand_geoms = (
        walker.mjcf_model.find('body', 'lhand').find_all('geom'))
    self._rhand_geoms = (
        walker.mjcf_model.find('body', 'rhand').find_all('geom'))

    # resize the humanoid based on the motion capture data subject
    self._trajectory.configure_walkers([self._walker])
    walker.create_root_joints(self._arena.attach(walker))

    control_timestep = self._trajectory.dt
    self.set_timesteps(control_timestep, _PHYSICS_TIMESTEP)

    # build and attach the bucket to the arena
    self._bucket = props.Bucket(_BUCKET_SIZE)
    self._arena.attach(self._bucket)

    self._prop = self._trajectory.create_props(
        priority_friction=self._priority_friction)[0]
    self._arena.add_free_entity(self._prop)

    self._task_observables = collections.OrderedDict()

    # define feature based observations (agent may or may not use these)
    def ego_prop_xpos(physics):
      prop_xpos, _ = self._prop.get_pose(physics)
      walker_xpos = physics.bind(self._walker.root_body).xpos
      return self._walker.transform_vec_to_egocentric_frame(
          physics, prop_xpos - walker_xpos)
    self._task_observables['prop_{}/xpos'.format(0)] = (
        observable.Generic(ego_prop_xpos))

    def prop_zaxis(physics):
      prop_xmat = physics.bind(
          mjcf.get_attachment_frame(self._prop.mjcf_model)).xmat
      return prop_xmat[[2, 5, 8]]
    self._task_observables['prop_{}/zaxis'.format(0)] = (
        observable.Generic(prop_zaxis))

    def ego_bucket_xpos(physics):
      bucket_xpos, _ = self._bucket.get_pose(physics)
      walker_xpos = physics.bind(self._walker.root_body).xpos
      return self._walker.transform_vec_to_egocentric_frame(
          physics, bucket_xpos - walker_xpos)
    self._task_observables['bucket_{}/xpos'.format(0)] = (
        observable.Generic(ego_bucket_xpos))

    for obs in (self._walker.observables.proprioception +
                self._walker.observables.kinematic_sensors +
                self._walker.observables.dynamic_sensors +
                list(self._task_observables.values())):
      obs.enabled = True