Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

trajectory need to be deepcopy! #73

Open
indeedzcr opened this issue Dec 4, 2024 · 0 comments
Open

trajectory need to be deepcopy! #73

indeedzcr opened this issue Dec 4, 2024 · 0 comments

Comments

@indeedzcr
Copy link

the difference reference and copy is as below:

a2={"aaa":1};b2={"bbb":2}
a1={"a2":a2};b1={"b2":b2}
ab={"a":a1,"b":b1}
dd=[]
dd.append(ab)
print(dd) # output is [{'a': {'a2': {'aaa': 1}}, 'b': {'b2': {'bbb': 2}}}]
a2["aaa"]=99;b2["bbb"]=99
print(dd) # output is [{'a': {'a2': {'aaa': 99}}, 'b': {'b2': {'bbb': 99}}}]

the dictionary in trajectory[2n]['info']['observation_metadata'] where n is 0,1,2,... , is actually a reference of ImageObservationProcessor.meta_data or TextObervationProcessor.meta_data.
The meta_data was created as the processor initialized, and then keep referenced all the time.
When processor.prosscess method runs and change the content of the meta_data, the trajectory changes then!
Thus: the 366 line of run_demo.py calls env.step then call _get_obs_metadata then call ObservationHandler.get_observation_metadata, it will finally reach the processor.meta_data modified by the processor.prosscess. After processor.prosscess modified the processor.meta_data, the trajectory was change the same time unexpectledy!
obs, _, terminated, _, info = env.step(action) # the 366 line of run_demo.py change the trajectory unexpectledy

Solution: use deepcopy the warp the obs and info

  1. line 322 of run_demo.py
    state_info: StateInfo = {"observation": obs, "info": info}
    change to
    state_info: StateInfo = {"observation": deepcopy(obs), "info": deepcopy(info)}
  2. line 367 of run_demo.py
    state_info = {"observation": obs, "info": info}
    change to
    state_info = {"observation": deepcopy(obs), "info": deepcopy(info)}
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant