GitHub
5 年前
当前提交
eeeb09b3
共有 18 个文件被更改,包括 298 次插入 和 71 次删除
-
18com.unity.ml-agents/Editor/BehaviorParametersEditor.cs
-
2com.unity.ml-agents/Editor/CameraSensorComponentEditor.cs
-
4com.unity.ml-agents/Editor/RayPerceptionSensorComponentBaseEditor.cs
-
2com.unity.ml-agents/Editor/RenderTextureSensorComponentEditor.cs
-
20com.unity.ml-agents/Runtime/Agent.cs
-
35com.unity.ml-agents/Runtime/Policies/BehaviorParameters.cs
-
12com.unity.ml-agents/Runtime/Sensors/CameraSensorComponent.cs
-
29com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensor.cs
-
26com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensorComponentBase.cs
-
6com.unity.ml-agents/Runtime/Sensors/RenderTextureSensorComponent.cs
-
16com.unity.ml-agents/Editor/EditorUtilities.cs
-
11com.unity.ml-agents/Editor/EditorUtilities.cs.meta
-
8com.unity.ml-agents/Tests/Editor/PublicAPI.meta
-
144com.unity.ml-agents/Tests/Editor/PublicAPI/PublicApiValidation.cs
-
3com.unity.ml-agents/Tests/Editor/PublicAPI/PublicApiValidation.cs.meta
-
26com.unity.ml-agents/Tests/Editor/PublicAPI/Unity.ML-Agents.Editor.Tests.PublicAPI.asmdef
-
7com.unity.ml-agents/Tests/Editor/PublicAPI/Unity.ML-Agents.Editor.Tests.PublicAPI.asmdef.meta
|
|||
using UnityEngine; |
|||
|
|||
namespace MLAgents.Editor |
|||
{ |
|||
public static class EditorUtilities |
|||
{ |
|||
/// <summary>
|
|||
/// Whether or not properties that affect the model can be updated at the current time.
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
public static bool CanUpdateModelProperties() |
|||
{ |
|||
return !Application.isPlaying; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 840f5a76642c24b789ee312f0aa8e33b |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: f5aa894d83ebc411581c8475cd2f9ae0 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using MLAgents; |
|||
using MLAgents.Policies; |
|||
using MLAgents.Sensors; |
|||
using NUnit.Framework; |
|||
using UnityEngine; |
|||
|
|||
namespace MLAgentsExamples |
|||
{ |
|||
/// <summary>
|
|||
/// The purpose of these tests is to make sure that we can do basic operations like creating
|
|||
/// an Agent and adding components from code without requiring access to internal methods.
|
|||
/// The tests aren't intended to add extra test coverage (although they might) and might
|
|||
/// not check any conditions.
|
|||
/// </summary>
|
|||
[TestFixture] |
|||
public class PublicApiValidation |
|||
{ |
|||
[Test] |
|||
public void CheckSetupCameraSensorComponent() |
|||
{ |
|||
var gameObject = new GameObject(); |
|||
var width = 24; |
|||
var height = 16; |
|||
|
|||
var sensorComponent = gameObject.AddComponent<CameraSensorComponent>(); |
|||
sensorComponent.camera = Camera.main; |
|||
sensorComponent.sensorName = "camera1"; |
|||
sensorComponent.width = width; |
|||
sensorComponent.height = height; |
|||
sensorComponent.grayscale = true; |
|||
|
|||
// Make sure the sets actually applied
|
|||
Assert.AreEqual("camera1", sensorComponent.sensorName); |
|||
Assert.AreEqual(width, sensorComponent.width); |
|||
Assert.AreEqual(height, sensorComponent.height); |
|||
Assert.IsTrue(sensorComponent.grayscale); |
|||
} |
|||
|
|||
[Test] |
|||
public void CheckSetupRenderTextureSensorComponent() |
|||
{ |
|||
var gameObject = new GameObject(); |
|||
|
|||
var sensorComponent = gameObject.AddComponent<RenderTextureSensorComponent>(); |
|||
var width = 24; |
|||
var height = 16; |
|||
var texture = new RenderTexture(width, height, 0); |
|||
sensorComponent.renderTexture = texture; |
|||
sensorComponent.sensorName = "rtx1"; |
|||
sensorComponent.grayscale = true; |
|||
|
|||
// Make sure the sets actually applied
|
|||
Assert.AreEqual("rtx1", sensorComponent.sensorName); |
|||
Assert.IsTrue(sensorComponent.grayscale); |
|||
} |
|||
|
|||
[Test] |
|||
public void CheckSetupRayPerceptionSensorComponent() |
|||
{ |
|||
var gameObject = new GameObject(); |
|||
|
|||
var sensorComponent = gameObject.AddComponent<RayPerceptionSensorComponent3D>(); |
|||
sensorComponent.sensorName = "ray3d"; |
|||
sensorComponent.detectableTags = new List<string> { "Player", "Respawn" }; |
|||
sensorComponent.raysPerDirection = 3; |
|||
sensorComponent.maxRayDegrees = 30; |
|||
sensorComponent.sphereCastRadius = .1f; |
|||
sensorComponent.rayLayerMask = 0; |
|||
sensorComponent.observationStacks = 2; |
|||
|
|||
sensorComponent.CreateSensor(); |
|||
} |
|||
|
|||
class PublicApiAgent : Agent |
|||
{ |
|||
public int numHeuristicCalls; |
|||
|
|||
public override float[] Heuristic() |
|||
{ |
|||
numHeuristicCalls++; |
|||
return base.Heuristic(); |
|||
} |
|||
} |
|||
|
|||
|
|||
[Test] |
|||
public void CheckSetupAgent() |
|||
{ |
|||
var gameObject = new GameObject(); |
|||
|
|||
var behaviorParams = gameObject.AddComponent<BehaviorParameters>(); |
|||
behaviorParams.brainParameters.vectorObservationSize = 3; |
|||
behaviorParams.brainParameters.numStackedVectorObservations = 2; |
|||
behaviorParams.brainParameters.vectorActionDescriptions = new[] { "TestActionA", "TestActionB" }; |
|||
behaviorParams.brainParameters.vectorActionSize = new[] { 2, 2 }; |
|||
behaviorParams.brainParameters.vectorActionSpaceType = SpaceType.Discrete; |
|||
behaviorParams.behaviorName = "TestBehavior"; |
|||
behaviorParams.TeamId = 42; |
|||
behaviorParams.useChildSensors = true; |
|||
|
|||
var agent = gameObject.AddComponent<PublicApiAgent>(); |
|||
// Make sure we can set the behavior type correctly after the agent is added
|
|||
behaviorParams.behaviorType = BehaviorType.InferenceOnly; |
|||
|
|||
// TODO - not internal yet
|
|||
// var decisionRequester = gameObject.AddComponent<DecisionRequester>();
|
|||
// decisionRequester.DecisionPeriod = 2;
|
|||
|
|||
var sensorComponent = gameObject.AddComponent<RayPerceptionSensorComponent3D>(); |
|||
sensorComponent.sensorName = "ray3d"; |
|||
sensorComponent.detectableTags = new List<string> { "Player", "Respawn" }; |
|||
sensorComponent.raysPerDirection = 3; |
|||
|
|||
// ISensor isn't set up yet.
|
|||
Assert.IsNull(sensorComponent.raySensor); |
|||
|
|||
agent.LazyInitialize(); |
|||
// Make sure we can set the behavior type correctly after the agent is initialized
|
|||
// (this creates a new policy).
|
|||
behaviorParams.behaviorType = BehaviorType.HeuristicOnly; |
|||
|
|||
// Initialization should set up the sensors
|
|||
Assert.IsNotNull(sensorComponent.raySensor); |
|||
|
|||
// Let's change the inference device
|
|||
var otherDevice = behaviorParams.inferenceDevice == InferenceDevice.CPU ? InferenceDevice.GPU : InferenceDevice.CPU; |
|||
agent.SetModel(behaviorParams.behaviorName, behaviorParams.model, otherDevice); |
|||
|
|||
agent.AddReward(1.0f); |
|||
|
|||
agent.RequestAction(); |
|||
agent.RequestDecision(); |
|||
|
|||
Academy.Instance.AutomaticSteppingEnabled = false; |
|||
Academy.Instance.EnvironmentStep(); |
|||
|
|||
var actions = agent.GetAction(); |
|||
// default Heuristic implementation should return zero actions.
|
|||
Assert.AreEqual(new[] {0.0f, 0.0f}, actions); |
|||
Assert.AreEqual(1, agent.numHeuristicCalls); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 016a3ac45b0345e3ab95f14ecaabdb11 |
|||
timeCreated: 1583858370 |
|
|||
{ |
|||
"name": "Unity.ML-Agents.Editor.Tests.PublicAPI", |
|||
"references": [ |
|||
"Unity.ML-Agents.Editor", |
|||
"Unity.ML-Agents", |
|||
"Barracuda", |
|||
"Unity.ML-Agents.CommunicatorObjects" |
|||
], |
|||
"optionalUnityReferences": [ |
|||
"TestAssemblies" |
|||
], |
|||
"includePlatforms": [ |
|||
"Editor" |
|||
], |
|||
"excludePlatforms": [], |
|||
"allowUnsafeCode": false, |
|||
"overrideReferences": true, |
|||
"precompiledReferences": [ |
|||
"System.IO.Abstractions.dll", |
|||
"System.IO.Abstractions.TestingHelpers.dll" |
|||
], |
|||
"autoReferenced": false, |
|||
"defineConstraints": [ |
|||
"UNITY_INCLUDE_TESTS" |
|||
] |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 38254a2538c8f42fb9f2057d17fd0e70 |
|||
AssemblyDefinitionImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue