浏览代码

Sensor cleanup

/goal-conditioning/new
Arthur Juliani 4 年前
当前提交
4413203d
共有 14 个文件被更改,包括 134 次插入59 次删除
  1. 4
      Project/Assets/ML-Agents/Examples/Crawler/Scripts/CrawlerAgent.cs
  2. 11
      Project/Assets/ML-Agents/Examples/GoalNav/Prefabs/Area.prefab
  3. 3
      Project/Assets/ML-Agents/Examples/GoalNav/Scenes/GoalNav.unity
  4. 4
      Project/Assets/ML-Agents/Examples/GoalNav/Scripts/GoalNavAgent.cs
  5. 2
      Project/Assets/ML-Agents/Examples/GridWorld/Scripts/GridAgent.cs
  6. 2
      Project/Assets/ML-Agents/Examples/PushJump/Scripts/WJPBAgent.cs
  7. 2
      ml-agents/mlagents/trainers/settings.py
  8. 7
      ml-agents/mlagents/trainers/torch/layers.py
  9. 2
      com.unity.ml-agents/Runtime/Sensors/VectorSensorComponent.cs.meta
  10. 42
      com.unity.ml-agents/Editor/VectorSensorComponentEditor.cs
  11. 11
      com.unity.ml-agents/Editor/VectorSensorComponentEditor.cs.meta
  12. 62
      com.unity.ml-agents/Runtime/Sensors/VectorSensorComponent.cs
  13. 41
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/VectorSensorComponent.cs
  14. 0
      /com.unity.ml-agents/Runtime/Sensors/VectorSensorComponent.cs.meta

4
Project/Assets/ML-Agents/Examples/Crawler/Scripts/CrawlerAgent.cs


//avg body vel relative to cube
sensor.AddObservation(m_OrientationCube.transform.InverseTransformDirection(avgVel));
//vel goal relative to cube
goalSensor.sensor.AddObservation(m_OrientationCube.transform.InverseTransformDirection(velGoal));
goalSensor.GetSensor().AddObservation(m_OrientationCube.transform.InverseTransformDirection(velGoal));
goalSensor.sensor.AddObservation(m_OrientationCube.transform.InverseTransformPoint(m_Target.transform.position));
goalSensor.GetSensor().AddObservation(m_OrientationCube.transform.InverseTransformPoint(m_Target.transform.position));
RaycastHit hit;
float maxRaycastDist = 10;

11
Project/Assets/ML-Agents/Examples/GoalNav/Prefabs/Area.prefab


- component: {fileID: 4505552578305912855}
- component: {fileID: 441485152799695089}
- component: {fileID: 441485152799695094}
- component: {fileID: 441485152799695088}
- component: {fileID: 4324470601561966908}
m_Layer: 0
m_Name: Agent
m_TagString: agent

VectorActionDescriptions: []
VectorActionSpaceType: 0
hasUpgradedBrainParametersWithActionSpec: 1
m_Model: {fileID: 0}
m_Model: {fileID: 11400000, guid: ad29336c39b53441bac1c1dc86f627a8, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: GoalNav

m_EditorClassIdentifier:
DecisionPeriod: 5
TakeActionsBetweenDecisions: 1
--- !u!114 &441485152799695088
--- !u!114 &4324470601561966908
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}

m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fd48a95d788a348b0b7a8cefd39e7c27, type: 3}
m_Script: {fileID: 11500000, guid: cd4eb5a37d8bf4074bbbbb470263d151, type: 3}
observationSize: 6
m_observationSize: 6
m_ObservationType: 1
--- !u!1 &441518250880870225
GameObject:
m_ObjectHideFlags: 0

3
Project/Assets/ML-Agents/Examples/GoalNav/Scenes/GoalNav.unity


propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedComponents:
- {fileID: 7930513067898411695, guid: 7e00e0f579d3d45af894c9b817bb585d, type: 3}
m_SourcePrefab: {fileID: 100100000, guid: 7e00e0f579d3d45af894c9b817bb585d, type: 3}

4
Project/Assets/ML-Agents/Examples/GoalNav/Scripts/GoalNavAgent.cs


goalSensor = this.GetComponent<VectorSensorComponent>();
if (useVectorObs)
{
goalSensor.sensor.AddObservation(goalLoc / 10f);
goalSensor.GetSensor().AddObservation(goalLoc / 10f);
goalSensor.sensor.AddObservation(obstacleLoc / 10f);
goalSensor.GetSensor().AddObservation(obstacleLoc / 10f);
}

2
Project/Assets/ML-Agents/Examples/GridWorld/Scripts/GridAgent.cs


Array values = Enum.GetValues(typeof(GridGoal));
int goalNum = (int)gridGoal;
goalSensor = this.GetComponent<VectorSensorComponent>();
goalSensor.sensor.AddOneHotObservation(goalNum, values.Length);
goalSensor.GetSensor().AddOneHotObservation(goalNum, values.Length);
}
public override void WriteDiscreteActionMask(IDiscreteActionMask actionMask)

2
Project/Assets/ML-Agents/Examples/PushJump/Scripts/WJPBAgent.cs


sensor.AddObservation(agentPos / 20f);
sensor.AddObservation(DoGroundCheck(true) ? 1 : 0);
goalSensor = this.GetComponent<VectorSensorComponent>();
goalSensor.sensor.AddObservation(m_GoalOneHot);
goalSensor.GetSensor().AddObservation(m_GoalOneHot);
}
/// <summary>

2
ml-agents/mlagents/trainers/settings.py


num_layers: int = 2
vis_encode_type: EncoderType = EncoderType.SIMPLE
memory: Optional[MemorySettings] = None
conditioning_type: ConditioningType = ConditioningType.DEFAULT
conditioning_type: ConditioningType = ConditioningType.HYPER
@attr.s(auto_attribs=True)

7
ml-agents/mlagents/trainers/torch/layers.py


output_weights = self.hypernet(hyper_input)
output_weights = output_weights.view(-1, self.input_size, self.output_size)
return (
torch.bmm(input_activation.unsqueeze(1), output_weights).squeeze(1)
+ self.bias
)
result = torch.bmm(input_activation.unsqueeze(1), output_weights).squeeze(1) + self.bias
return result

2
com.unity.ml-agents/Runtime/Sensors/VectorSensorComponent.cs.meta


fileFormatVersion: 2
guid: fd48a95d788a348b0b7a8cefd39e7c27
guid: cd4eb5a37d8bf4074bbbbb470263d151
MonoImporter:
externalObjects: {}
serializedVersion: 2

42
com.unity.ml-agents/Editor/VectorSensorComponentEditor.cs


using UnityEditor;
using Unity.MLAgents.Sensors;
namespace Unity.MLAgents.Editor
{
[CustomEditor(typeof(VectorSensorComponent))]
[CanEditMultipleObjects]
internal class VectorSensorComponentEditor : UnityEditor.Editor
{
public override void OnInspectorGUI()
{
var so = serializedObject;
so.Update();
// Drawing the VectorSensorComponent
EditorGUI.BeginChangeCheck();
EditorGUI.BeginDisabledGroup(!EditorUtilities.CanUpdateModelProperties());
{
// These fields affect the sensor order or observation size,
// So can't be changed at runtime.
EditorGUILayout.PropertyField(so.FindProperty("m_observationSize"), true);
EditorGUILayout.PropertyField(so.FindProperty("m_ObservationType"), true);
}
EditorGUI.EndDisabledGroup();
var requireSensorUpdate = EditorGUI.EndChangeCheck();
so.ApplyModifiedProperties();
if (requireSensorUpdate)
{
UpdateSensor();
}
}
void UpdateSensor()
{
var sensorComponent = serializedObject.targetObject as VectorSensorComponent;
sensorComponent?.UpdateSensor();
}
}
}

11
com.unity.ml-agents/Editor/VectorSensorComponentEditor.cs.meta


fileFormatVersion: 2
guid: 7353c768b27de4de18487d7a0e3516c5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

62
com.unity.ml-agents/Runtime/Sensors/VectorSensorComponent.cs


using UnityEngine;
using UnityEngine.Serialization;
namespace Unity.MLAgents.Sensors
{
[AddComponentMenu("ML Agents/Vector Sensor", (int)MenuGroup.Sensors)]
public class VectorSensorComponent : SensorComponent
{
public int ObservationSize
{
get { return m_observationSize; }
set { m_observationSize = value; }
}
[HideInInspector, SerializeField]
int m_observationSize;
[HideInInspector, SerializeField]
ObservationType m_ObservationType;
VectorSensor m_sensor;
public ObservationType ObservationType
{
get { return m_ObservationType; }
set { m_ObservationType = value; }
}
/// <summary>
/// Creates a VectorSensor.
/// </summary>
/// <returns></returns>
public override ISensor CreateSensor()
{
m_sensor = new VectorSensor(m_observationSize, observationType: m_ObservationType);
return m_sensor;
}
/// <inheritdoc/>
public override int[] GetObservationShape()
{
return new[] { m_observationSize };
}
public VectorSensor GetSensor()
{
return m_sensor;
}
/// <summary>
/// Update fields that are safe to change on the Sensor at runtime.
/// </summary>
internal void UpdateSensor()
{
if (m_sensor != null)
{
}
}
}
}

41
Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/VectorSensorComponent.cs


using System.Collections.Generic;
using System.Collections.ObjectModel;
using Unity.MLAgents.Sensors;
using UnityEngine;
public class VectorSensorComponent : SensorComponent
{
int m_observationSize;
ObservationType m_ObservationType;
public int ObservationSize
{
get { return m_observationSize; }
set { m_observationSize = value; }
}
public VectorSensor sensor;
public ObservationType ObservationType
{
get { return m_ObservationType; }
set { m_ObservationType = value; }
}
/// <summary>
/// Creates a VectorSensor.
/// </summary>
/// <returns></returns>
public override ISensor CreateSensor()
{
sensor = new VectorSensor(m_observationSize, observationType: m_ObservationType);
return sensor;
}
/// <inheritdoc/>
public override int[] GetObservationShape()
{
return new[] { m_observationSize };
}
}

/Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/VectorSensorComponent.cs.meta → /com.unity.ml-agents/Runtime/Sensors/VectorSensorComponent.cs.meta

正在加载...
取消
保存