浏览代码
Brains as Scriptable Objects (#1250)
Brains as Scriptable Objects (#1250)
* Initial Commit Ported most functionalities, still need to : - Documentation - Add Comments - Custom drawer for BrainParameters - Fix the UnitTests - Review Functionalities * Added Custom Drawer for the Brain Parameters * Improvements to the HubDrawer * Modified the Brain Editors * Minor bug fixes and UI changes * Modified the Help Boxes of the Drawers * Modified Brain class, renamed Initialize and made DecideAction virtual * Fix the UnityTests * Simpler Brain creation menu * Renamed Internal Brain to Learning Brain * modified the parameters to remove reference to External or Internal in the Protobuf objects * Updated the protobuf generated files * Fix the Pytests * Removed the graph scope from the Learning Brain * cleaner logic than try catch * Removed the isExternal field of the brain and put the isTraining logic into LearningBrain and Training Hub * Modified how the Brain finds the A.../develop-generalizationTraining-TrainerController
GitHub
6 年前
当前提交
d7224351
共有 130 个文件被更改,包括 4984 次插入 和 2491 次删除
-
168UnitySDK/Assets/ML-Agents/Editor/BrainEditor.cs
-
15UnitySDK/Assets/ML-Agents/Editor/BrainEditor.cs.meta
-
175UnitySDK/Assets/ML-Agents/Editor/ResetParameterDrawer.cs
-
2UnitySDK/Assets/ML-Agents/Editor/Tests/DemonstrationTests.cs
-
62UnitySDK/Assets/ML-Agents/Editor/Tests/MLAgentsEditModeTest.cs
-
5UnitySDK/Assets/ML-Agents/Examples/3DBall/Prefabs/Game.prefab
-
279UnitySDK/Assets/ML-Agents/Examples/3DBall/Scenes/3DBall.unity
-
9UnitySDK/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DDecision.cs
-
6UnitySDK/Assets/ML-Agents/Examples/Basic/Scripts/BasicDecision.cs
-
6UnitySDK/Assets/ML-Agents/Examples/Reacher/Scripts/ReacherDecision.cs
-
17UnitySDK/Assets/ML-Agents/Examples/SharedAssets/Scripts/RandomDecision.cs
-
6UnitySDK/Assets/ML-Agents/Examples/Template/Scripts/TemplateDecision.cs
-
73UnitySDK/Assets/ML-Agents/Scripts/Academy.cs
-
21UnitySDK/Assets/ML-Agents/Scripts/ActionMasker.cs
-
4UnitySDK/Assets/ML-Agents/Scripts/Agent.cs
-
2UnitySDK/Assets/ML-Agents/Scripts/Batcher.cs
-
315UnitySDK/Assets/ML-Agents/Scripts/Brain.cs
-
58UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/BrainParametersProto.cs
-
4UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityInput.cs
-
6UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityMessage.cs
-
4UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityOutput.cs
-
2UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityRlInitializationOutput.cs
-
2UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityRlInput.cs
-
8UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityToExternalGrpc.cs
-
8UnitySDK/Assets/ML-Agents/Scripts/Decision.cs
-
2UnitySDK/Assets/ML-Agents/Scripts/DemonstrationStore.cs
-
19UnitySDK/Assets/ML-Agents/Scripts/Utilities.cs
-
10docs/Background-TensorFlow.md
-
46docs/Basic-Guide.md
-
6docs/FAQ.md
-
56docs/Getting-Started-with-Balance-Ball.md
-
4docs/Glossary.md
-
79docs/Learning-Environment-Create-New.md
-
5docs/Learning-Environment-Design-Academy.md
-
19docs/Learning-Environment-Design-Agents.md
-
70docs/Learning-Environment-Design-Brains.md
-
11docs/Learning-Environment-Design-Heuristic-Brains.md
-
7docs/Learning-Environment-Design-Player-Brains.md
-
51docs/Learning-Environment-Design.md
-
22docs/Learning-Environment-Executable.md
-
51docs/ML-Agents-Overview.md
-
18docs/Migrating.md
-
14docs/Python-API.md
-
2docs/Readme.md
-
15docs/Training-Imitation-Learning.md
-
2docs/Training-ML-Agents.md
-
2docs/Using-Docker.md
-
12docs/Using-TensorFlow-Sharp-in-Unity.md
-
629docs/images/academy.png
-
114docs/images/agent.png
-
204docs/images/brain.png
-
355docs/images/broadcast.png
-
348docs/images/mlagents-NewTutAcademy.png
-
999docs/images/mlagents-NewTutAssignBrain.png
-
703docs/images/mlagents-NewTutBrain.png
-
92docs/images/mlagents-NewTutHierarchy.png
-
1ml-agents/mlagents/envs/communicator_objects/__init__.py
-
15ml-agents/mlagents/envs/communicator_objects/agent_action_proto_pb2.py
-
29ml-agents/mlagents/envs/communicator_objects/agent_info_proto_pb2.py
-
39ml-agents/mlagents/envs/communicator_objects/brain_parameters_proto_pb2.py
-
13ml-agents/mlagents/envs/communicator_objects/command_proto_pb2.py
-
19ml-agents/mlagents/envs/communicator_objects/engine_configuration_proto_pb2.py
-
18ml-agents/mlagents/envs/communicator_objects/environment_parameters_proto_pb2.py
-
11ml-agents/mlagents/envs/communicator_objects/header_pb2.py
-
13ml-agents/mlagents/envs/communicator_objects/resolution_proto_pb2.py
-
11ml-agents/mlagents/envs/communicator_objects/space_type_proto_pb2.py
-
11ml-agents/mlagents/envs/communicator_objects/unity_input_pb2.py
-
13ml-agents/mlagents/envs/communicator_objects/unity_message_pb2.py
-
11ml-agents/mlagents/envs/communicator_objects/unity_output_pb2.py
-
9ml-agents/mlagents/envs/communicator_objects/unity_rl_initialization_input_pb2.py
-
17ml-agents/mlagents/envs/communicator_objects/unity_rl_initialization_output_pb2.py
-
28ml-agents/mlagents/envs/communicator_objects/unity_rl_input_pb2.py
-
24ml-agents/mlagents/envs/communicator_objects/unity_rl_output_pb2.py
-
6ml-agents/mlagents/envs/environment.py
-
2ml-agents/tests/mock_communicator.py
-
3protobuf-definitions/proto/mlagents/envs/communicator_objects/brain_parameters_proto.proto
-
183UnitySDK/Assets/Gizmos/LearningBrain Icon.png
-
369UnitySDK/Assets/ML-Agents/Editor/BrainParametersDrawer.cs
-
12UnitySDK/Assets/ML-Agents/Editor/BrainParametersDrawer.cs.meta
-
208UnitySDK/Assets/ML-Agents/Editor/BroadcastHubDrawer.cs
-
3UnitySDK/Assets/ML-Agents/Editor/BroadcastHubDrawer.cs.meta
-
56UnitySDK/Assets/ML-Agents/Editor/HeuristicBrainEditor.cs
-
3UnitySDK/Assets/ML-Agents/Editor/HeuristicBrainEditor.cs.meta
-
27UnitySDK/Assets/ML-Agents/Editor/LearningBrainEditor.cs
-
3UnitySDK/Assets/ML-Agents/Editor/LearningBrainEditor.cs.meta
-
106UnitySDK/Assets/ML-Agents/Editor/PlayerBrainEditor.cs
-
3UnitySDK/Assets/ML-Agents/Editor/PlayerBrainEditor.cs.meta
-
23UnitySDK/Assets/ML-Agents/Editor/Tests/UtilitiesTests.cs
-
3UnitySDK/Assets/ML-Agents/Editor/Tests/UtilitiesTests.cs.meta
-
8UnitySDK/Assets/ML-Agents/Examples/3DBall/Brains.meta
-
124UnitySDK/Assets/ML-Agents/Scripts/BrainParameters.cs
-
3UnitySDK/Assets/ML-Agents/Scripts/BrainParameters.cs.meta
-
68UnitySDK/Assets/ML-Agents/Scripts/BroadcastHub.cs
-
3UnitySDK/Assets/ML-Agents/Scripts/BroadcastHub.cs.meta
-
86UnitySDK/Assets/ML-Agents/Scripts/HeuristicBrain.cs
-
486UnitySDK/Assets/ML-Agents/Scripts/LearningBrain.cs
-
108UnitySDK/Assets/ML-Agents/Scripts/PlayerBrain.cs
-
73docs/Learning-Environment-Design-Learning-Brains.md
|
|||
fileFormatVersion: 2 |
|||
guid: f1895a43ed0f54ffd9ee06234c4399e7 |
|||
timeCreated: 1503270350 |
|||
licenseType: Free |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
fileFormatVersion: 2 |
|||
guid: 7b07bebd03994ed08559c725da882b62 |
|||
timeCreated: 1537834304 |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using System.Collections.Generic; |
|||
using UnityEngine.UI; |
|||
|
|||
using System.Linq; |
|||
|
|||
|
|||
// Class contains all necessary environment parameters
|
|||
// to be defined and sent to external agent
|
|||
|
|||
public enum BrainType |
|||
{ |
|||
Player, |
|||
Heuristic, |
|||
External, |
|||
Internal |
|||
} |
|||
|
|||
public enum SpaceType |
|||
/// <summary>
|
|||
/// Brain receive data from Agents through calls to SendState. The brain then updates the
|
|||
/// actions of the agents at each FixedUpdate.
|
|||
/// The Brain encapsulates the decision making process. Every Agent must be assigned a Brain,
|
|||
/// but you can use the same Brain with more than one Agent. You can also create several
|
|||
/// Brains, attach each of the Brain to one or more than one Agent.
|
|||
/// Brain assets has several important properties that you can set using the Inspector window.
|
|||
/// These properties must be appropriate for the Agents using the Brain. For example, the
|
|||
/// Vector Observation Space Size property must match the length of the feature
|
|||
/// vector created by an Agent exactly.
|
|||
/// </summary>
|
|||
public abstract class Brain : ScriptableObject |
|||
discrete, |
|||
continuous |
|||
}; |
|||
[SerializeField] public BrainParameters brainParameters; |
|||
protected Dictionary<Agent, AgentInfo> agentInfos = |
|||
new Dictionary<Agent, AgentInfo>(1024); |
|||
|
|||
protected Batcher brainBatcher; |
|||
/** Only need to be modified in the brain's inpector. |
|||
* Defines what is the resolution of the camera |
|||
*/ |
|||
[System.Serializable] |
|||
public struct resolution |
|||
{ |
|||
public int width; |
|||
|
|||
/**< \brief The width of the observation in pixels */ |
|||
public int height; |
|||
|
|||
/**< \brief The height of the observation in pixels */ |
|||
public bool blackAndWhite; |
|||
/**< \brief If true, the image will be in black and white. |
|||
* If false, it will be in colors RGB */ |
|||
} |
|||
|
|||
/** Should be modified via the Editor Inspector. |
|||
* Defines brain-specific parameters |
|||
*/ |
|||
[System.Serializable] |
|||
public class BrainParameters |
|||
{ |
|||
public int vectorObservationSize = 1; |
|||
/**< \brief If continuous : The length of the float vector that represents |
|||
* the state |
|||
* <br> If discrete : The number of possible values the state can take*/ |
|||
|
|||
[Range(1, 50)] public int numStackedVectorObservations = 1; |
|||
|
|||
public int[] vectorActionSize = new int[1]{1}; |
|||
/**< \brief If continuous : The length of the float vector that represents |
|||
* the action |
|||
* <br> If discrete : The number of possible values the action can take*/ |
|||
|
|||
public resolution[] cameraResolutions; |
|||
/**<\brief The list of observation resolutions for the brain */ |
|||
|
|||
public string[] vectorActionDescriptions; |
|||
/**< \brief The list of strings describing what the actions correpond to */ |
|||
[System.NonSerialized] |
|||
private bool _isInitialized; |
|||
public SpaceType vectorActionSpaceType = SpaceType.discrete; |
|||
/**< \brief Defines if the action is discrete or continuous */ |
|||
|
|||
/// Converts a Brain into to a Protobuff BrainInfoProto so it can be sent
|
|||
/// Sets the Batcher of the Brain. The brain will call the batcher at every step and give
|
|||
/// it the agent's data using SendBrainInfo at each DecideAction call.
|
|||
/// <returns>The BrainInfoProto generated.</returns>
|
|||
/// <param name="name">The name of the brain.</param>
|
|||
/// <param name="type">The type of brain.</param>
|
|||
public CommunicatorObjects.BrainParametersProto |
|||
ToProto(string name, CommunicatorObjects.BrainTypeProto type) |
|||
/// <param name="batcher"> The Batcher the brain will use for the current session</param>
|
|||
public void SetBatcher(Batcher batcher) |
|||
var brainParametersProto = new CommunicatorObjects.BrainParametersProto |
|||
{ |
|||
VectorObservationSize = vectorObservationSize, |
|||
NumStackedVectorObservations = numStackedVectorObservations, |
|||
VectorActionSize = {vectorActionSize}, |
|||
VectorActionSpaceType = |
|||
(CommunicatorObjects.SpaceTypeProto)vectorActionSpaceType, |
|||
BrainName = name, |
|||
BrainType = type |
|||
}; |
|||
brainParametersProto.VectorActionDescriptions.AddRange(vectorActionDescriptions); |
|||
foreach (resolution res in cameraResolutions) |
|||
if (batcher == null) |
|||
brainParametersProto.CameraResolutions.Add( |
|||
new CommunicatorObjects.ResolutionProto |
|||
{ |
|||
|