Search Unity

Question How to train PPO algorithm in MLagents using Python instead of CLI?

Discussion in 'ML-Agents' started by hlwang01, May 8, 2023.

  1. hlwang01

    hlwang01

    Joined:
    Aug 25, 2022
    Posts:
    1
    I am seeking guidance on how to resolve the issue, or receive instructions on how to call the PPO algorithm using Python. As I need to configure several parameters in Python before executing PPO, the CLI training method is not suitable for my needs

    I tried the following code, but it threw an error. I don't know if it's because the feature is not supported yet or if my code is incorrect. The error message is as follow

    Code (Python):
    1.  
    2. from mlagents_envs.environment import UnityEnvironment
    3. from mlagents.trainers.ppo.trainer import PPOTrainer
    4. from mlagents.trainers.settings import TrainerSettings
    5.  
    6. trainer_settings = TrainerSettings()
    7.  
    8. env = UnityEnvironment("RollerAgent/RollerAgent.exe",no_graphics=True)
    9. behavior_names = list(env.behavior_specs.keys())
    10. print(behavior_names)
    11. ppotrainer = PPOTrainer("RollerBall", 10, trainer_settings, True, False, 0, "")
    12. env.reset()
    13. for _ in range(1000):
    14.     decision_steps, terminal_steps = env.get_steps(behavior_names[0])
    15.     ppotrainer.advance()
    16.  
    error message
    line 622, in _set_default_hyperparameters
    return all_trainer_settings[self.trainer_type]()
    KeyError: 'ppo'