Skip to content
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

obs is not a dictionary but only has str 'proprioceptive'. #4

Open
psh9002 opened this issue Jan 5, 2023 · 0 comments
Open

obs is not a dictionary but only has str 'proprioceptive'. #4

psh9002 opened this issue Jan 5, 2023 · 0 comments

Comments

@psh9002
Copy link

psh9002 commented Jan 5, 2023

I got an error at class UnimalHeightObs(gym.ObservationWrapper), def observation(self, obs): from hfield.py

  File "/home/bak/Projects/metamorph/metamorph/envs/wrappers/hfield.py", line 211, in observation
    obs["torso_height"] = round(z_pos - 1, 3)
TypeError: 'str' object does not support item assignment

The def observation(self, obs): is called from class UnimalEnv(gym.Env): in unimal.py. Though the obs is a dictionary and has 'proprioceptive', 'edges' keys at the end of def reset(self):, obs is just a str 'proprioceptive' at def observation(self, obs): class UnimalHeightObs(gym.ObservationWrapper).

From the viewpoint of the train loop, the error occurs when the code creates (or initializes) the world environment. At ppo.py, obs cannot create at def train(self):.

To solve above issue, I added self.obs_temp = obs at def reset(self): at def reset(self): class UnimalEnv(gym.Env): and obs = self.obs_temp at class UnimalHeightObs(gym.ObservationWrapper), def observation(self, obs):to preserve obs information.

  • unimal.py
class UnimalEnv(gym.Env):
    """Superclass for all Unimal tasks."""

...........
...........
    ###########################################################################
    # Reset sim
    ###########################################################################
    def reset(self):
        if self.sim is None or cfg.ENV.NEW_SIM_ON_RESET:
            self.sim = self._get_sim()
        else:
            self.sim.reset()

        self.step_count = 0

        if self.viewer is not None:
            self.viewer.update_sim(self.sim)
        obs = self.reset_model()
        self._set_action_space()
        # This is just a temp initialization, the final obs space will depend
        # on SelectKeysWrapper
        self.observation_space = spu.convert_obs_to_space(obs)
        self.metadata["video.frames_per_second"] = int(np.round(1.0 / self.dt))
        self.obs_temp = obs  ### what I added

        return obs
  • hfield.py
class UnimalHeightObs(gym.ObservationWrapper):
    def __init__(self, env):
        super().__init__(env)
        self.observation_space = spu.update_obs_space(env, {"torso_height": (1,)})

    def observation(self, obs):
        obs = self.obs_temp   ### what I added
        x_pos, y_pos, z_pos = self.sim.data.get_body_xpos("torso/0")
   ........
   ........

After that, I got an error like below.

Process ForkProcess-3:
Traceback (most recent call last):
  File "/home/bak/Projects/metamorph/metamorph/envs/vec_env/subproc_vec_env.py", line 27, in worker
    remote.send([env.reset() for env in envs])
  File "/home/bak/Projects/metamorph/metamorph/envs/vec_env/subproc_vec_env.py", line 27, in <listcomp>
    remote.send([env.reset() for env in envs])
  File "/home/bak/Projects/metamorph/metamorph/envs/wrappers/multi_env_wrapper.py", line 40, in reset
    obs = self._env.reset()
  File "/home/bak/Projects/metamorph/metamorph/algos/ppo/envs.py", line 187, in reset
    observation = super(RecordEpisodeStatistics, self).reset(**kwargs)
  File "/home/bak/anaconda3/envs/metamorph/lib/python3.8/site-packages/gym/core.py", line 323, in reset
    return self.env.reset(**kwargs)
  File "/home/bak/Projects/metamorph/metamorph/algos/ppo/envs.py", line 169, in reset
    return self.env.reset(**kwargs)
  File "/home/bak/anaconda3/envs/metamorph/lib/python3.8/site-packages/gym/wrappers/time_limit.py", line 68, in reset
    return self.env.reset(**kwargs)
  File "/home/bak/anaconda3/envs/metamorph/lib/python3.8/site-packages/gym/wrappers/order_enforcing.py", line 42, in reset
    return self.env.reset(**kwargs)
  File "/home/bak/anaconda3/envs/metamorph/lib/python3.8/site-packages/gym/wrappers/env_checker.py", line 47, in reset
    return self.env.reset(**kwargs)
  File "/home/bak/anaconda3/envs/metamorph/lib/python3.8/site-packages/gym/core.py", line 379, in reset
    obs, info = self.env.reset(**kwargs)
ValueError: too many values to unpack (expected 2)

How can I fix these problems and check the result of your experiments?

I used Anaconda environment with mujoco-2.1.0 rather than Docker due to using free version of mujoco and using mujoco-py. Unfortunately, using mujoco after 2.1.0 does not support mujoco-py due to it has its own python binding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant