Recurrent Warning: Fewer observations made than vector observation size

Hello,

I am trying to implement a custom Agent in a custom environment where it has to navigate to a preset goal using its Transform position. However, I am getting the “Fewer observations (0) made than vector observation size (3). The observations will be padded.” warning at a rate that seems to be every other observation.

For example, if I log the expected observation once per Agent.CollectObservations(), after an episode I find 334 logged observations and 330 “fewer observation” warnings. Nothing in the observation is null - no objects are being instantiated/destroyed at runtime and the logging shows a consistent Vector3 observation.

Here is the warning call stack:

Fewer observations (0) made than vector observation size (3). The observations will be padded.
UnityEngine.Debug:LogWarningFormat (string,object[])
Unity.MLAgents.Sensors.VectorSensor:Write (Unity.MLAgents.Sensors.ObservationWriter) (at Library/PackageCache/com.unity.ml-agents@c1b26d49e4/Runtime/Sensors/VectorSensor.cs:56)
Unity.MLAgents.Policies.HeuristicPolicy:StepSensors (System.Collections.Generic.List`1<Unity.MLAgents.Sensors.ISensor>) (at Library/PackageCache/com.unity.ml-agents@c1b26d49e4/Runtime/Policies/HeuristicPolicy.cs:133)
Unity.MLAgents.Policies.HeuristicPolicy:RequestDecision (Unity.MLAgents.AgentInfo,System.Collections.Generic.List`1<Unity.MLAgents.Sensors.ISensor>) (at Library/PackageCache/com.unity.ml-agents@c1b26d49e4/Runtime/Policies/HeuristicPolicy.cs:38)
Unity.MLAgents.Agent:SendInfoToBrain () (at Library/PackageCache/com.unity.ml-agents@c1b26d49e4/Runtime/Agent.cs:1096)
Unity.MLAgents.Agent:SendInfo () (at Library/PackageCache/com.unity.ml-agents@c1b26d49e4/Runtime/Agent.cs:1323)
Unity.MLAgents.Academy:EnvironmentStep () (at Library/PackageCache/com.unity.ml-agents@c1b26d49e4/Runtime/Academy.cs:573)
Unity.MLAgents.AcademyFixedUpdateStepper:FixedUpdate () (at Library/PackageCache/com.unity.ml-agents@c1b26d49e4/Runtime/Academy.cs:43)

Here is my Agent.CollectObservations():

public override void CollectObservations(VectorSensor sensor)
{
    // agentPos and goalDestination are preset and do not get deleted. Nothing here indicates Null or 0.0 when logging
    sensor.AddObservation((agentPos.position - goalDestination.transform.position) / (goalRadius + 750.0f));
}

Does this log any errors ?

public override void CollectObservations(VectorSensor sensor)
{
    // agentPos and goalDestination are preset and do not get deleted. Nothing here indicates Null or 0.0 when logging
    try {
    sensor.AddObservation((agentPos.position - goalDestination.transform.position) / (goalRadius + 750.0f));
    } catch (Exception ex)
    {
         Debug.LogError(ex, this);
    }
}

Adding the Exception/LogError above does not log any errors.

Try add a breakpoint at the end of CollectObservations.
Once it hits the breakpoint add a watch on Sensor.m_Observations.count
(Private variable so have to use quickwatch to find it and add it)

Next run let it run a few times and each time it hits the breakpoint check if Sensor.m_Observations.count == 3

1 Like

Interesting. Looks like there may be a bug. Adding the breakpoint with a conditional checking if sensor.m_Observations.Count != 3 never triggers. However, if I do sensor.m_Observations.Count == 3 it does trigger correctly (since I have a Vector3 = 3-size observation).

edit: Is it possible that there is some other observation size check before the overrided Agent.CollectObservations() is called?

I got rid of the warning! It had nothing to do with my Agent script. Instead, it had something to do with the components I had on the GameObject. I reordered the components to match the picture on the ml-agents docs (picture at the “Final Agent Setup” section) and removed an extraneous VectorSensor component (which I do not think had any impact since it was set to size 2 but no errors/warnings) and it worked with no warnings!

If anyone wants, I could reorder my components and try to figure out the exact cause of the warning. Now to test if this was impacting training - I have been experiencing really weird training where the agent learns but at a rate extremely slow for a simple problem (like just solving what essentially was a direct linear equation). Maybe the observations were being dropped right before writing to the buffer.

If my training issues are solved with this and there had been some observation dropping, then I think there should be a specific warning/error about this. It was really weird to debug this because my Agent.CollectObservations() was returning the correct size. I’ll mark this thread as Resolved in a few days if still training issues since then it’s not related to the warning.

edit: Still have training issues. Guess basic continuous pathfinding to a goal is pretty hard for RL to do within 2M timesteps. Gonna try curriculum learning and other things, but it is safe to assume that the warning is unrelated to my RL issues. Marking as resolved.