Access to neural network weights

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!

Hi,
There are some methods to support this in the TFPolicy class:

Thank you very much!
Are there such methods on the Unity side (C#) ?

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/com.unity.barracuda@0.6/manual/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: Issues · Unity-Technologies/barracuda-release · GitHub

Thank you very much for your kind reply!
Now I’m trying to implement NN using KelpNet (GitHub - harujoh/KelpNet: Pure C# machine learning framework) 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[ ]