Closed WangJuan6 closed 4 days ago
Dear Author, I use the custom environment to train the PPO agent. In my custom environment, the observations include the RGB and semantic map. The semantic model is initialized in the init function of the environment:
self.sem_seg_pred = SemanticPredMaskRCNN(gpu_id=0)
and I get the semantic map in the reset and step function by:
sem_seg_pred, _ = self.sem_seg_pred.get_prediction(rgb_frame.astype(np.uint8))
The code is worked.
Then, I wanted to use the multiprocess, so I modified the code in the main function: change:
my_env_ppo_create_config = dict( env_manager=dict(type='base'), policy=dict(type='ppo'), ) collector_env = BaseEnvManagerV2( env_fn=[ding_env_maker for _ in range(cfg.env.collector_env_num)], cfg=cfg.env.manager ) evaluator_env = BaseEnvManagerV2( env_fn=[ding_env_maker for _ in range(cfg.env.evaluator_env_num)], cfg=cfg.env.manager )
into:
my_env_ppo_create_config = dict( env_manager=dict(type='subprocess'), policy=dict(type='ppo'), ) collector_env = SubprocessEnvManagerV2( env_fn=[ding_env_maker for _ in range(cfg.env.collector_env_num)], cfg=cfg.env.manager ) evaluator_env = SubprocessEnvManagerV2( env_fn=[ding_env_maker for _ in range(cfg.env.evaluator_env_num)], cfg=cfg.env.manager )
However, the semantic model initialization code:
report an error:
Cannot re-initialize CUDA in forked subprocess. To use CUDA with multiprocessing, you must use the 'spawn' start method
Can you help me to solve this problem? Thanks
You need to set the context of subprocess from fork to spawn.
fork
spawn
It works, thanks for your reply.
Dear Author, I use the custom environment to train the PPO agent. In my custom environment, the observations include the RGB and semantic map. The semantic model is initialized in the init function of the environment:
and I get the semantic map in the reset and step function by:
The code is worked.
Then, I wanted to use the multiprocess, so I modified the code in the main function: change:
into:
However, the semantic model initialization code:
self.sem_seg_pred = SemanticPredMaskRCNN(gpu_id=0)
report an error:
Cannot re-initialize CUDA in forked subprocess. To use CUDA with multiprocessing, you must use the 'spawn' start method
Can you help me to solve this problem? Thanks