Search Unity

Camera attached to agent - learning reward reduced when removed

Discussion in 'ML-Agents' started by Fr2, Apr 19, 2021.

  1. Fr2

    Fr2

    Joined:
    Jan 19, 2013
    Posts:
    39
    Well this really has me confused! In my training environment, my agents each have a camera attached to them, and training is successful:

    upload_2021-4-19_15-10-25.png
    However, if I remove the cameras, and re-run the training, training results are worse (light blue):

    upload_2021-4-19_15-11-17.png
    I'm trying to work out why removing the cameras would have a negative effect on learning. Observations are collected from raycasts. The agent is not using the camera for learning (there is no camera sensor component). No agent scripts reference the camera, and there are no console errors.

    Reaching out in case anyone has any ideas?
     
  2. ruoping_unity

    ruoping_unity

    Unity Technologies

    Joined:
    Jul 10, 2020
    Posts:
    134
    Hi,

    It's hard to tell since we don't have access to your environment. But from your description your agent does use the camera in some way in the training if it affects the training performance. Can you list out all the sensors and observations you're using? Or can you reproduce the same issue using any of our examples?
     
  3. ruoping_unity

    ruoping_unity

    Unity Technologies

    Joined:
    Jul 10, 2020
    Posts:
    134
    Another possible reason is that the extra camera affects the framerate, and that affects the training. If that's the case, you'll need to figure out what in your scene is depending on the framerate and fix that.
     
  4. Fr2

    Fr2

    Joined:
    Jan 19, 2013
    Posts:
    39
    Thanks for your feedback, am really scratching my head with this one! Observations include standard sensors:

    upload_2021-4-19_22-16-23.png

    and a single float observation in CollectObservations(VectorSensor sensor). The behavior details:

    upload_2021-4-19_22-19-0.png

    I wondered if there could have been a camera sensor on my character somewhere, but there are no child objects beneath the behavior parameters object. I've got a fairly complex character with animation rigging, etc, so somewhere in the model the camera must be affecting something. But I can remove the camera during inference without any issue. Strange!

    I'll try adding the camera to the examples as you suggested and see if I can recreate the issue outside of my project.
     
  5. Fr2

    Fr2

    Joined:
    Jan 19, 2013
    Posts:
    39
    Thanks, yes framerate was something I was considering. But the additional cameras would expect to slow the framerate... but perhaps that helps with training. Actually, during training I'm using a time-scale of 4. I could re-run training with the time-scale reduced even further, and see if I see a difference in learning rates.
     
  6. ruoping_unity

    ruoping_unity

    Unity Technologies

    Joined:
    Jul 10, 2020
    Posts:
    134
    Given that you mentioned you have some complex animation stuff it's likely something about framerate. One thing to mention here is during training, mlagents-learn set captureFramerate to 60 by default and that might affect frame updates and thus affect training.
     
  7. Fr2

    Fr2

    Joined:
    Jan 19, 2013
    Posts:
    39
    As an experiment I tried re-running the training again with a timescale of 1, but was still seeing a difference:

    with camera (orange)
    without camera (blue)

    upload_2021-4-20_14-9-0.png

    My FPS counter reported a steady 120 frames per second while training. Considering that captureFramerate is 60, I disabled v-sync and set the Application.targetFrameRate to 60. Re-running training, still similar differences despite a steady framerate of 60 during training:

    upload_2021-4-20_14-46-13.png

    So, it's interesting. The work-around is easy - I can just enable the cameras while training, and turn them of for inference. But I'd be curious to know what could be causing the difference. Gut feeling is that it's framerate related.
     
    Last edited: Apr 20, 2021