ml-agents icon indicating copy to clipboard operation
ml-agents copied to clipboard

PPO Trainning won't produce steps

Open GeriBP opened this issue 8 years ago • 12 comments

I've set up a On Demand Decision Agent that is supposed to learn how to play basketball. To do so I Start agent -> Request Decision -> Reward/Punish -> Reset after the steps set in the agent brain (200 in this case)

This works great on the editor when using a Player Brain Type. Rewards, rounds and everything look great and correctly setup.

But when I start trainning the model I only get this output (even after a looong while): INFO:unityagents: BasketBrain: Step: 10000. Mean Reward: -0.088. Std of Reward: 0.033

As if there was an infinite lasting PPO step or something. Even though that the scene gets reset after the steps set in the agent brain is like the PPO step doesn't increase and gets stuck forever. The Time Scale in trainning configuration is set to 100 and in the small game window I can see the scene being played/simulated.

Anyone has a clue of what may be the problem? Thanks in advance

GeriBP avatar Apr 03 '18 00:04 GeriBP

I come across the same problem. My implementation is also a baskteball game.

Build it like you discribed it and i also get only one step displayed. When stopping and restart with --load the simulation will also output only the next step. Step number is not the same as at the start. Looking into the tensorboard --logdir=summaries i only find the reward at these steps displayed during simulation instead of every step.

Like the Bouncer example reward is set in FixedUpdates().

marcelwessely avatar May 10 '18 13:05 marcelwessely

One reason I see is that the agent never requests a decision after some point. It could be due to an Academy reset gone wrong or a condition to request a decision that is never met. Could you try interacting directly with the environment. Something along the lines of :

from unityagents import *
env=UnityEnvironment(<env_name>)
info = env.reset()
counter =0 
while True:
     print(counter)
     counter = counter+1
     info = env.step()

If the counter stops increasing at some point, it would mean the agents are not requesting decisions anymore. This could also happen if the agents are never set to done. Be sure to use Done, do not call ResetAgent directly.

vincentpierre avatar May 10 '18 20:05 vincentpierre

I added a counter after every decision and displayed it direktly in the UI. The counter went up and also the AgentAction is executed (the ball is thrown).

private void FixedUpdate()
    {
        if (text != null)
        {
            text.text = string.Format("D {0}: S {1}: M {2}", decided, solved, missed);
        }
        // Request decision if the ball is not already thrown
        if (!isThrown)
        {
            RequestDecision();
            decided++;
        }
        // Set the reward
        if (hitGoal)
        {
            AddReward(1f);
            solved++;
            Done();
            return;
        }
        else if (toFarAway)
        {
            AddReward(-0.1f);
            missed++;
            Done();
            return;
        }
   }

Nevertheless the training enviorment only displays one step. Also the reward is always (one or many?) miss so -0.1f . In the picture you can see that the enviorment did over 30k steps but only 2k are displayed in the prompt.

inkedfound_bug_li

When inspecting with the jupyter notebook the reward gets displayed.

Where can I look more into detail to fix the problem?

marcelwessely avatar May 14 '18 18:05 marcelwessely

Can you decrease summary-freq in trainer-config.yaml ? This will allow you to see at what point the environment stops displaying the step. Can you also print in addition to counter the local done flag ? If it is always false, it means the agent never finishes an episode, if it is always true, then it means the episode length is 1 and in this scenario, I am not sure ppo will consider it an episode at all.

vincentpierre avatar May 14 '18 19:05 vincentpierre

Decreasing the summary-freq to 1 also gives only one step as output. Monitoring the flag shows that it resets correctly every time when the agent has to be reset. On the other side the done flag is still true when the agent did the next desicion (but i think that is intended)

I could get a output when the agent has to do 2 RequestDecisions() between every Done(). Maybe the the framework does not support only one decision and a reset after that?

marcelwessely avatar May 15 '18 13:05 marcelwessely

The framework is not suitable for episodes of one step only, I think this could be the problem. PPO uses (state, action, reward, next_state) when training, it does not make sense if there is only one state per episode. Could you not set the agent to done every decision, could you do it every 10, 100 steps ? This would help us figure out if this is the issue here.

vincentpierre avatar May 15 '18 17:05 vincentpierre

The way to play the game (throw a ball into a basket) has to have only one decision at the start (throwing the ball with a specific velocity). Therefore I dont see how to implement this kind of game with more than one step.

It would make sense that one state per episode is not supported. When I allow the agents to execute 2 RequestDecision() it generates a output but that is not the way to play a basketball game.

Thank you for the help.

marcelwessely avatar May 16 '18 11:05 marcelwessely

Maybe you could consider one episode to be 10 free throws ? The agent has 10 attempts at throwing the ball per episode, He is only done after 10 throws. His cumulative score is given by the sum of the rewards for each throw. There is no correlation between throws but this should not bother the agent... Once the agent is trained, you can set the number of throws to be anything you want (including 1)

vincentpierre avatar May 16 '18 19:05 vincentpierre

@marcelwessely I have same problem but with football game. Trying to solve it like @vincentpierre said. Looks like this way work...now I trying to get correct parametres.

phatal avatar May 28 '18 15:05 phatal

@vincentpierre The solution you proposed sounds good but takes no advantage of PPO. There is no correlation between each throw which is the main advantage of PPO I think. Therefore I decided to let the agent aim in a direction and after some steps a ball will be shot. The agent has no possibility to get into the correct aim in one step and has to take more steps. First training sessions seem to show good results.

marcelwessely avatar Jun 16 '18 21:06 marcelwessely

Hi All,

I am closing this thread due to inactivity, but feel free to re-open it if you desire.

awjuliani avatar Sep 06 '18 18:09 awjuliani

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Jan 03 '20 04:01 lock[bot]