haosulab / ManiSkill

SAPIEN Manipulation Skill Framework, a GPU parallelized robotics simulator and benchmark
https://maniskill.ai/
Apache License 2.0
680 stars 120 forks source link

[Question] How to load in truly randomized YCB objects each time #412

Closed CreativeNick closed 2 weeks ago

CreativeNick commented 1 month ago

I'm building this custom environment and am having trouble with loading in a randomized YCB object. I would like it so when I run the command python ppo.py --env-id Bimanual_Allegro_YCB, a newly randomly generated YCB model is generated. So for example, if I ran the command the first time, it would train using 004_sugar_box, and when I run it a second time, it would train using 072-c_toy_airplane. When I evaluate these runs, they would use their respective model used when training. However, when running the command multiple times, it always ends up using the same model. It would select model 052_extra_large_clamp, and then select another model, the object being 011_banana. I have an example output below.

I setup a print statement to output which model it chooses. For some reason, when I simply view the environment using my own view_ycb_env.py file, it is able to generate a uniquely random model each time. This leads me to believe that this issue is happening because of how the seed works in ppo.py.

(ms_dev) creativenick@creativenick:~/Desktop/SimToReal/bimanual-sapien$ python ppo.py --capture-video --env-id Bimanual_Allegro_YCB
/home/creativenick/anaconda3/envs/ms_dev/lib/python3.9/site-packages/tyro/_fields.py:343: UserWarning: The field wandb_entity is annotated with type <class 'str'>, but the default value None has type <class 'NoneType'>. We'll try to handle this gracefully, but it may cause unexpected behavior.
  warnings.warn(
/home/creativenick/anaconda3/envs/ms_dev/lib/python3.9/site-packages/tyro/_fields.py:343: UserWarning: The field checkpoint is annotated with type <class 'str'>, but the default value None has type <class 'NoneType'>. We'll try to handle this gracefully, but it may cause unexpected behavior.
  warnings.warn(
Running training
Model ID: 052_extra_large_clamp
Model ID: 011_banana

... rest of output

Link to files for reference: ycb_env.py (environment file) view_ycb_env.py (used to view environment) ppo.py (this file is essentially the same as the ppo.py file in this repo, with only differences in formatting and class args like num_steps)

StoneT2000 commented 1 month ago

https://github.com/CreativeNick/SimToReal/blob/bf2bb092414742bb381575063f84876acf5f7e77/bimanual-sapien/envs/ycb_env.py#L78 is the line that randomizes your models. You should seed with a RNG (you can use self.np_random instead of np.random). self.np_random will be seeded by the seed passed to env.reset(seed=seed)

CreativeNick commented 1 month ago

Are there any built-in features to evaluate the run using the same object that was used in training, or is that something I would need to tweak? Using self.np_random I was able to generate random YCB models each time, but I'd like to also maintain the same model for both training & evaluation.

StoneT2000 commented 1 month ago

You will have to write code to do that to e.g. upon env creation limit which YCB models are loaded. You could modify the task to accept a new argument in the init function of the env class to accept a list of model IDs, and the env will only sample from that list.

StoneT2000 commented 1 month ago

@CreativeNick is this still an issue?