I’m getting this warning “Fewer observations(0) made than vector size.” (seems like every episode reset). Is it possible to fix this somehow? I’m adding the correct amount of observations in the CollectObservations method in my Agent.
Hi, sorry but I don’t think I can’t give you a clear answer without more details since this could be from any number of different issues. Would it be possible to share the bit of code you have in the below functions?
- CollectObservations
- OnEpisodeBegin
- Initialize
My initialization code and onepisodebegin contain no references to observation. Here’s the code for CollectObservations
public override void CollectObservations(VectorSensor sensor)
{
// Find closest food
float closestDistance = 9999;
GameObject closestCookie = null;
velocity = rb2D.velocity.magnitude;
var cookies = GameObject.FindGameObjectsWithTag("Food");
foreach (var cookie in cookies)
{
var cookiePosition = cookie.transform.position;
var distance = Vector3.Distance(cookiePosition, rb2D.position);
if (distance < closestDistance)
{
closestDistance = distance;
closestCookie = cookie;
}
}
sensor.AddObservation(rb2D.position);
sensor.AddObservation(rb2D.rotation);
sensor.AddObservation(rb2D.velocity);
if(closestCookie != null)
{
sensor.AddObservation(closestCookie.transform.position.x);
sensor.AddObservation(closestCookie.transform.position.y);
sensor.AddObservation(closestDistance);
}
else
{
// padding
sensor.AddObservation(0);
sensor.AddObservation(0);
sensor.AddObservation(0);
}
CountDownLife();
AddReward(Time.deltaTime);
}
Thanks, that looks great to me too. Are you using a “Decision Requester” and/or destroying / disabling and re-enabling any agents or components?
Yes, I’m using the decision requester with a decision period of 1. Agents are not destroyed or disabled.
I am not sure why this would be happening based on the information I have at the moment. Are you getting any other error messages? Is it possible to share what you are doing in the other agent methods?
i had a similar issue on some projects. I haven’t been able to pinpoint the exact problem, but i’ve noticed that the error message was also appearing after pressing “stop” during manual tests. I also was using a decision requester and no piece of the agent wad destroyable. Seemed like an attempt to get one more observation after the agent reset.
(August 2022 update on this problem, if other people have been going crazy like me over it)
Hi !
If you’re having this error, it may be because your GameObject has two (or more) Agent scripts attached to it.
You can verify that in that in the Inspector, check if there’s another Agent script existing.
Make sure the collect observation call isn’t happening when your agent game object is set as inactive.
If end episode is called before the next collect observations call, the academy will cause the agent to collect one more observation to pair the final rewards with a fresh observation. I have run into your issue when my scene logic was disabling the agent game object before this final call was happening, thus all of the sensors were disabled and not providing observation values (ie 0).