Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Access to neural network weights

Discussion in 'ML-Agents' started by unity_nBMnid_GOQvclw, Mar 21, 2020.

  1. unity_nBMnid_GOQvclw

    unity_nBMnid_GOQvclw

    Joined:
    Feb 3, 2020
    Posts:
    5
    I want to train agents in the FoodCollector-like environment with a genetic algorithm.
    I want each agent to inherit the neural network weight parameter from the parent when they are born, so I think I need to access to the network and assign the weight.
    How can I access to weight parameters of ML-Agents Agent?

    Thanks!
     
  2. celion_unity

    celion_unity

    Joined:
    Jun 12, 2019
    Posts:
    289
  3. unity_nBMnid_GOQvclw

    unity_nBMnid_GOQvclw

    Joined:
    Feb 3, 2020
    Posts:
    5
    Thank you very much!
    Are there such methods on the Unity side (C#) ?
     
  4. celion_unity

    celion_unity

    Joined:
    Jun 12, 2019
    Posts:
    289
    I'm not exactly sure what's available on the C# side. We import the models with Barracuda, which has access for iterating through the layers:
    https://docs.unity3d.com/Packages/c...ual/index.html#introspecting-barracuda-models
    and you should be able to access the weights from the layers:
    https://docs.unity3d.com/Packages/com.unity.barracuda@0.6/api/Barracuda.Layer.html
    but I believe these are read-only.

    If you have feature requests for Barracuda, they best place to ask is on their github issues: https://github.com/Unity-Technologies/barracuda-release/issues
     
  5. unity_nBMnid_GOQvclw

    unity_nBMnid_GOQvclw

    Joined:
    Feb 3, 2020
    Posts:
    5
    Thank you very much for your kind reply!
    Now I'm trying to implement NN using KelpNet (https://github.com/harujoh/KelpNet) and train it by GA on C#,
    but I'll try your methods if I have a chance.

    Looking at the code a bit, the weight variable is at
    Agent.m_Brain : BarracudaPolicy
    .m_ModelRunner : ModelRunner (protected)
    .barracudaModel : Barracuda.Model (not a member variable)
    .layers : List<Barracuda.Layer>
    -> Layer.weights : float[]
     
    Last edited: Mar 25, 2020