Arthur Juliani
4 年前
当前提交
b84b4880
共有 25 个文件被更改,包括 3451 次插入 和 14 次删除
-
2Project/Assets/ML-Agents/Examples/GoalNav/Scripts/PushBlockSettings.cs.meta
-
8Project/Assets/ML-Agents/Examples/GoalNav.meta
-
26config/ppo/GoalNav.yaml
-
8Project/Assets/ML-Agents/Examples/GoalNav/Meshes.meta
-
1001Project/Assets/ML-Agents/Examples/GoalNav/Meshes/PushBlockCourt.fbx
-
126Project/Assets/ML-Agents/Examples/GoalNav/Meshes/PushBlockCourt.fbx.meta
-
8Project/Assets/ML-Agents/Examples/GoalNav/Prefabs.meta
-
1001Project/Assets/ML-Agents/Examples/GoalNav/Prefabs/Area.prefab
-
7Project/Assets/ML-Agents/Examples/GoalNav/Prefabs/Area.prefab.meta
-
8Project/Assets/ML-Agents/Examples/GoalNav/Scenes.meta
-
1001Project/Assets/ML-Agents/Examples/GoalNav/Scenes/GoalNav.unity
-
7Project/Assets/ML-Agents/Examples/GoalNav/Scenes/GoalNav.unity.meta
-
8Project/Assets/ML-Agents/Examples/GoalNav/Scripts.meta
-
11Project/Assets/ML-Agents/Examples/GoalNav/Scripts/GoalDetect.cs.meta
-
219Project/Assets/ML-Agents/Examples/GoalNav/Scripts/GoalNavAgent.cs
-
11Project/Assets/ML-Agents/Examples/GoalNav/Scripts/GoalNavAgent.cs.meta
-
13Project/Assets/ML-Agents/Examples/PushBlock/Scripts/GoalDetect.cs.meta
-
0/Project/Assets/ML-Agents/Examples/GoalNav/Scripts/GoalDetect.cs
-
0/Project/Assets/ML-Agents/Examples/GoalNav/Scripts/PushBlockSettings.cs
-
0/Project/Assets/ML-Agents/Examples/GoalNav/Scripts/PushBlockSettings.cs.meta
|
|||
fileFormatVersion: 2 |
|||
guid: a210b813c05e344ffab6a3f77903d159 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
behaviors: |
|||
GoalNav: |
|||
trainer_type: ppo |
|||
hyperparameters: |
|||
batch_size: 128 |
|||
buffer_size: 2048 |
|||
learning_rate: 0.0003 |
|||
beta: 0.01 |
|||
epsilon: 0.2 |
|||
lambd: 0.95 |
|||
num_epoch: 3 |
|||
learning_rate_schedule: linear |
|||
network_settings: |
|||
normalize: false |
|||
hidden_units: 100 |
|||
num_layers: 2 |
|||
vis_encode_type: simple |
|||
reward_signals: |
|||
extrinsic: |
|||
gamma: 0.99 |
|||
strength: 1.0 |
|||
keep_checkpoints: 5 |
|||
max_steps: 2000000 |
|||
time_horizon: 64 |
|||
summary_freq: 60000 |
|||
threaded: true |
|
|||
fileFormatVersion: 2 |
|||
guid: b73520d910a3b4c009d8d11ddb375f57 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1001
Project/Assets/ML-Agents/Examples/GoalNav/Meshes/PushBlockCourt.fbx
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 8ea51e3c5ff764bcbbebef11c96e5de1 |
|||
ModelImporter: |
|||
serializedVersion: 23 |
|||
fileIDToRecycleName: |
|||
100000: GoalArea |
|||
100002: Ground |
|||
100004: //RootNode |
|||
100006: WallsOuter |
|||
400000: GoalArea |
|||
400002: Ground |
|||
400004: //RootNode |
|||
400006: WallsOuter |
|||
2100000: rep_WhiteWalls |
|||
2100002: rep_Floor |
|||
2100004: rep_Checkers |
|||
2300000: GoalArea |
|||
2300002: Ground |
|||
2300004: WallsOuter |
|||
3300000: GoalArea |
|||
3300002: Ground |
|||
3300004: WallsOuter |
|||
4300000: WallsOuter |
|||
4300002: Ground |
|||
4300004: GoalArea |
|||
externalObjects: |
|||
- first: |
|||
type: UnityEngine:Material |
|||
assembly: UnityEngine.CoreModule |
|||
name: rep_Checkers |
|||
second: {fileID: 2100000, guid: 36c7baa347d68f347a9aa9698aa1bcdd, type: 2} |
|||
- first: |
|||
type: UnityEngine:Material |
|||
assembly: UnityEngine.CoreModule |
|||
name: rep_Floor |
|||
second: {fileID: 2100000, guid: bc723809e6ff3174fad3e774cae1aed0, type: 2} |
|||
- first: |
|||
type: UnityEngine:Material |
|||
assembly: UnityEngine.CoreModule |
|||
name: rep_WhiteWalls |
|||
second: {fileID: 2100000, guid: 6a39c0407dd85684384bf0277294e9b6, type: 2} |
|||
materials: |
|||
importMaterials: 1 |
|||
materialName: 0 |
|||
materialSearch: 1 |
|||
materialLocation: 1 |
|||
animations: |
|||
legacyGenerateAnimations: 4 |
|||
bakeSimulation: 0 |
|||
resampleCurves: 1 |
|||
optimizeGameObjects: 0 |
|||
motionNodeName: |
|||
rigImportErrors: |
|||
rigImportWarnings: |
|||
animationImportErrors: |
|||
animationImportWarnings: |
|||
animationRetargetingWarnings: |
|||
animationDoRetargetingWarnings: 0 |
|||
importAnimatedCustomProperties: 0 |
|||
importConstraints: 0 |
|||
animationCompression: 1 |
|||
animationRotationError: 0.5 |
|||
animationPositionError: 0.5 |
|||
animationScaleError: 0.5 |
|||
animationWrapMode: 0 |
|||
extraExposedTransformPaths: [] |
|||
extraUserProperties: [] |
|||
clipAnimations: [] |
|||
isReadable: 1 |
|||
meshes: |
|||
lODScreenPercentages: [] |
|||
globalScale: 1 |
|||
meshCompression: 0 |
|||
addColliders: 0 |
|||
useSRGBMaterialColor: 1 |
|||
importVisibility: 1 |
|||
importBlendShapes: 1 |
|||
importCameras: 1 |
|||
importLights: 1 |
|||
swapUVChannels: 0 |
|||
generateSecondaryUV: 1 |
|||
useFileUnits: 1 |
|||
optimizeMeshForGPU: 1 |
|||
keepQuads: 0 |
|||
weldVertices: 1 |
|||
preserveHierarchy: 0 |
|||
indexFormat: 0 |
|||
secondaryUVAngleDistortion: 8 |
|||
secondaryUVAreaDistortion: 15.000001 |
|||
secondaryUVHardAngle: 88 |
|||
secondaryUVPackMargin: 4 |
|||
useFileScale: 1 |
|||
previousCalculatedGlobalScale: 1 |
|||
hasPreviousCalculatedGlobalScale: 0 |
|||
tangentSpace: |
|||
normalSmoothAngle: 60 |
|||
normalImportMode: 0 |
|||
tangentImportMode: 3 |
|||
normalCalculationMode: 4 |
|||
legacyComputeAllNormalsFromSmoothingGroupsWhenMeshHasBlendShapes: 1 |
|||
blendShapeNormalImportMode: 1 |
|||
normalSmoothingSource: 0 |
|||
importAnimation: 1 |
|||
copyAvatar: 0 |
|||
humanDescription: |
|||
serializedVersion: 2 |
|||
human: [] |
|||
skeleton: [] |
|||
armTwist: 0.5 |
|||
foreArmTwist: 0.5 |
|||
upperLegTwist: 0.5 |
|||
legTwist: 0.5 |
|||
armStretch: 0.05 |
|||
legStretch: 0.05 |
|||
feetSpacing: 0 |
|||
rootMotionBoneName: |
|||
hasTranslationDoF: 0 |
|||
hasExtraRoot: 0 |
|||
skeletonHasParents: 1 |
|||
lastHumanDescriptionAvatarSource: {instanceID: 0} |
|||
animationType: 0 |
|||
humanoidOversampling: 1 |
|||
additionalBone: 0 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: ba1e44c40fae5452dbd5fc91021b6c3e |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1001
Project/Assets/ML-Agents/Examples/GoalNav/Prefabs/Area.prefab
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 7e00e0f579d3d45af894c9b817bb585d |
|||
PrefabImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 034c1bac9b9a249f6bc339d830ad0544 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1001
Project/Assets/ML-Agents/Examples/GoalNav/Scenes/GoalNav.unity
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 0928e22e8f6ac4766afb9badb82246b3 |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 7a6ecbd64ff0c49959ecb732683c89d5 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: db06de03634014d669f89681637d18d8 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
//Put this script on your blue cube.
|
|||
|
|||
using System.Collections; |
|||
using UnityEngine; |
|||
using Unity.MLAgents; |
|||
using Unity.MLAgents.Sensors; |
|||
using Unity.MLAgents.Actuators; |
|||
|
|||
public class GoalNavAgent : Agent |
|||
{ |
|||
/// <summary>
|
|||
/// The ground. The bounds are used to spawn the elements.
|
|||
/// </summary>
|
|||
public GameObject ground; |
|||
|
|||
public GameObject area; |
|||
|
|||
/// <summary>
|
|||
/// The area bounds.
|
|||
/// </summary>
|
|||
[HideInInspector] |
|||
public Bounds areaBounds; |
|||
|
|||
PushBlockSettings m_PushBlockSettings; |
|||
|
|||
GoalSensorComponent goalSensor; |
|||
|
|||
public GameObject goalObject; |
|||
public GameObject obstacleObject; |
|||
|
|||
Vector3 goalLoc; |
|||
Vector3 obstacleLoc; |
|||
|
|||
public bool useVectorObs; |
|||
|
|||
Rigidbody m_AgentRb; //cached on initialization
|
|||
Material m_GroundMaterial; //cached on Awake()
|
|||
|
|||
/// <summary>
|
|||
/// We will be changing the ground material based on success/failue
|
|||
/// </summary>
|
|||
Renderer m_GroundRenderer; |
|||
|
|||
EnvironmentParameters m_ResetParams; |
|||
|
|||
void Awake() |
|||
{ |
|||
m_PushBlockSettings = FindObjectOfType<PushBlockSettings>(); |
|||
} |
|||
|
|||
public override void Initialize() |
|||
{ |
|||
|
|||
// Cache the agent rigidbody
|
|||
m_AgentRb = GetComponent<Rigidbody>(); |
|||
// Get the ground's bounds
|
|||
areaBounds = ground.GetComponent<Collider>().bounds; |
|||
// Get the ground renderer so we can change the material when a goal is scored
|
|||
m_GroundRenderer = ground.GetComponent<Renderer>(); |
|||
// Starting material
|
|||
m_GroundMaterial = m_GroundRenderer.material; |
|||
|
|||
m_ResetParams = Academy.Instance.EnvironmentParameters; |
|||
|
|||
SetResetParameters(); |
|||
} |
|||
|
|||
public override void CollectObservations(VectorSensor sensor) |
|||
{ |
|||
goalSensor = this.GetComponent<GoalSensorComponent>(); |
|||
goalSensor.AddGoal(goalLoc / 10f); |
|||
goalSensor.AddGoal(obstacleLoc/ 10f); |
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// Use the ground's bounds to pick a random spawn position.
|
|||
/// </summary>
|
|||
public Vector3 GetRandomSpawnPos() |
|||
{ |
|||
var foundNewSpawnLocation = false; |
|||
var randomSpawnPos = Vector3.zero; |
|||
while (foundNewSpawnLocation == false) |
|||
{ |
|||
var randomPosX = Random.Range(-areaBounds.extents.x * m_PushBlockSettings.spawnAreaMarginMultiplier, |
|||
areaBounds.extents.x * m_PushBlockSettings.spawnAreaMarginMultiplier); |
|||
|
|||
var randomPosZ = Random.Range(-areaBounds.extents.z * m_PushBlockSettings.spawnAreaMarginMultiplier, |
|||
areaBounds.extents.z * m_PushBlockSettings.spawnAreaMarginMultiplier); |
|||
randomSpawnPos = ground.transform.position + new Vector3(randomPosX, 1f, randomPosZ); |
|||
if (Physics.CheckBox(randomSpawnPos, new Vector3(2.5f, 0.01f, 2.5f)) == false) |
|||
{ |
|||
foundNewSpawnLocation = true; |
|||
} |
|||
} |
|||
return randomSpawnPos; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Moves the agent according to the selected action.
|
|||
/// </summary>
|
|||
public void MoveAgent(ActionSegment<int> act) |
|||
{ |
|||
var dirToGo = Vector3.zero; |
|||
var rotateDir = Vector3.zero; |
|||
|
|||
var action = act[0]; |
|||
|
|||
switch (action) |
|||
{ |
|||
case 1: |
|||
dirToGo = transform.forward * 1f; |
|||
break; |
|||
case 2: |
|||
dirToGo = transform.forward * -1f; |
|||
break; |
|||
case 3: |
|||
rotateDir = transform.up * 1f; |
|||
break; |
|||
case 4: |
|||
rotateDir = transform.up * -1f; |
|||
break; |
|||
case 5: |
|||
dirToGo = transform.right * -0.75f; |
|||
break; |
|||
case 6: |
|||
dirToGo = transform.right * 0.75f; |
|||
break; |
|||
} |
|||
transform.Rotate(rotateDir, Time.fixedDeltaTime * 200f); |
|||
m_AgentRb.AddForce(dirToGo * m_PushBlockSettings.agentRunSpeed, |
|||
ForceMode.VelocityChange); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Called every step of the engine. Here the agent takes an action.
|
|||
/// </summary>
|
|||
public override void OnActionReceived(ActionBuffers actionBuffers) |
|||
|
|||
{ |
|||
// Move the agent using the action.
|
|||
MoveAgent(actionBuffers.DiscreteActions); |
|||
|
|||
// Penalty given each step to encourage agent to finish task quickly.
|
|||
AddReward(-1f / MaxStep); |
|||
|
|||
CheckGoal(); |
|||
} |
|||
|
|||
public void CheckGoal() |
|||
{ |
|||
var distanceGoal = Vector3.Distance(transform.localPosition, goalLoc); |
|||
if (distanceGoal < 1.5f) |
|||
{ |
|||
Debug.Log("Found goal"); |
|||
SetReward(1f); |
|||
EndEpisode(); |
|||
} |
|||
|
|||
var distanceObstacle = Vector3.Distance(transform.localPosition, obstacleLoc); |
|||
if (distanceObstacle < 1.5f) |
|||
{ |
|||
Debug.Log("Found obstacle"); |
|||
SetReward(-1f); |
|||
EndEpisode(); |
|||
} |
|||
} |
|||
|
|||
public override void Heuristic(in ActionBuffers actionsOut) |
|||
{ |
|||
var discreteActionsOut = actionsOut.DiscreteActions; |
|||
discreteActionsOut[0] = 0; |
|||
if (Input.GetKey(KeyCode.D)) |
|||
{ |
|||
discreteActionsOut[0] = 3; |
|||
} |
|||
else if (Input.GetKey(KeyCode.W)) |
|||
{ |
|||
discreteActionsOut[0] = 1; |
|||
} |
|||
else if (Input.GetKey(KeyCode.A)) |
|||
{ |
|||
discreteActionsOut[0] = 4; |
|||
} |
|||
else if (Input.GetKey(KeyCode.S)) |
|||
{ |
|||
discreteActionsOut[0] = 2; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// In the editor, if "Reset On Done" is checked then AgentReset() will be
|
|||
/// called automatically anytime we mark done = true in an agent script.
|
|||
/// </summary>
|
|||
public override void OnEpisodeBegin() |
|||
{ |
|||
var rotation = Random.Range(0, 4); |
|||
var rotationAngle = rotation * 90f; |
|||
area.transform.Rotate(new Vector3(0f, rotationAngle, 0f)); |
|||
|
|||
transform.position = GetRandomSpawnPos(); |
|||
m_AgentRb.velocity = Vector3.zero; |
|||
m_AgentRb.angularVelocity = Vector3.zero; |
|||
|
|||
goalLoc = new Vector3(Random.Range(-10f, 10f), 1f, Random.Range(-10f, 10f)); |
|||
goalObject.transform.localPosition = goalLoc; |
|||
|
|||
obstacleLoc = new Vector3(Random.Range(-10f, 10f), 1f, Random.Range(-10f, 10f)); |
|||
obstacleObject.transform.localPosition = obstacleLoc; |
|||
|
|||
SetResetParameters(); |
|||
} |
|||
|
|||
|
|||
void SetResetParameters() |
|||
{ |
|||
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 0ceffd7f848ac40ba84e863a63d95b2c |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 7d079d09ceed84ff49cf6841c66cf7ec |
|||
timeCreated: 1513645763 |
|||
licenseType: Free |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue