浏览代码

Implemented the reset parameters for Banana Collectors and Bouncer (#2258)

Banana Collectors: Length of laser and agent scale
Bouncer: Size of the banana
/develop-generalizationTraining-TrainerController
Ervin T 5 年前
当前提交
5465c2e0
共有 6 个文件被更改,包括 77 次插入13 次删除
  1. 8
      UnitySDK/Assets/ML-Agents/Examples/BananaCollectors/Scenes/Banana.unity
  2. 26
      UnitySDK/Assets/ML-Agents/Examples/BananaCollectors/Scripts/BananaAgent.cs
  3. 6
      UnitySDK/Assets/ML-Agents/Examples/Bouncer/Scenes/Bouncer.unity
  4. 8
      UnitySDK/Assets/ML-Agents/Examples/Bouncer/Scenes/BouncerIL.unity
  5. 24
      UnitySDK/Assets/ML-Agents/Examples/Bouncer/Scripts/BouncerAgent.cs
  6. 18
      docs/Learning-Environment-Examples.md

8
UnitySDK/Assets/ML-Agents/Examples/BananaCollectors/Scenes/Banana.unity


m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.44824862, g: 0.49827534, b: 0.57558274, a: 1}
m_IndirectSpecularColor: {r: 0.44824898, g: 0.49827564, b: 0.5755826, a: 1}
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0

timeScale: 1
targetFrameRate: 60
resetParameters:
resetParameters: []
resetParameters:
- key: laser_length
value: 1
- key: agent_scale
value: 1
agents: []
listArea: []
totalScore: 0

26
UnitySDK/Assets/ML-Agents/Examples/BananaCollectors/Scripts/BananaAgent.cs


float effectTime;
Rigidbody agentRb;
private int bananas;
private float laser_length;
// Speed of agent rotation.
public float turnSpeed = 300;

public bool contribute;
private RayPerception3D rayPer;
public bool useVectorObs;
public override void InitializeAgent()
{

myArea = area.GetComponent<BananaArea>();
rayPer = GetComponent<RayPerception3D>();
myAcademy = FindObjectOfType<BananaAcademy>();
SetResetParameters();
}
public override void CollectObservations()

if (shoot)
{
myLaser.transform.localScale = new Vector3(1f, 1f, 1f);
myLaser.transform.localScale = new Vector3(1f, 1f, laser_length);
Vector3 position = transform.TransformDirection(RayPerception3D.PolarToCartesian(25f, 90f));
Debug.DrawRay(transform.position, position, Color.red, 0f, true);
RaycastHit hit;

2f, Random.Range(-myArea.range, myArea.range))
+ area.transform.position;
transform.rotation = Quaternion.Euler(new Vector3(0f, Random.Range(0, 360)));
SetResetParameters();
}
void OnCollisionEnter(Collision collision)

public override void AgentOnDone()
{
}
public void SetLaserLengths()
{
laser_length = myAcademy.resetParameters["laser_length"];
}
public void SetAgentScale()
{
var agent_scale = myAcademy.resetParameters["agent_scale"];
gameObject.transform.localScale = new Vector3(agent_scale, agent_scale, agent_scale);
}
public void SetResetParameters()
{
SetLaserLengths();
SetAgentScale();
}
}

6
UnitySDK/Assets/ML-Agents/Examples/Bouncer/Scenes/Bouncer.unity


m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.44824862, g: 0.49827534, b: 0.57558274, a: 1}
m_IndirectSpecularColor: {r: 0.44824898, g: 0.49827564, b: 0.5755826, a: 1}
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0

timeScale: 1
targetFrameRate: 60
resetParameters:
resetParameters: []
resetParameters:
- key: banana_scale
value: 150
gravityMultiplier: 2
--- !u!4 &1453982295
Transform:

8
UnitySDK/Assets/ML-Agents/Examples/Bouncer/Scenes/BouncerIL.unity


m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.4482636, g: 0.49828887, b: 0.5755903, a: 1}
m_IndirectSpecularColor: {r: 0.44824898, g: 0.49827564, b: 0.5755826, a: 1}
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0

brain: {fileID: 11400000, guid: 5527511df7b944e8e9177dd69db5a9c1, type: 2}
agentParameters:
agentCameras: []
agentRenderTextures: []
maxStep: 0
resetOnDone: 1
onDemandDecision: 1

brain: {fileID: 11400000, guid: 573920e3a672d40038169c7ffdbdca05, type: 2}
agentParameters:
agentCameras: []
agentRenderTextures: []
maxStep: 0
resetOnDone: 1
onDemandDecision: 1

timeScale: 1
targetFrameRate: 60
resetParameters:
resetParameters: []
resetParameters:
- key: banana_scale
value: 150
gravityMultiplier: 2
--- !u!4 &1453982295
Transform:

24
UnitySDK/Assets/ML-Agents/Examples/Bouncer/Scripts/BouncerAgent.cs


using System.Collections;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MLAgents;

int numberJumps = 20;
int jumpLeft = 20;
ResetParameters resetParams;
var academy = FindObjectOfType<Academy>() as Academy;
resetParams = academy.resetParameters;
SetResetParameters();
}
public override void CollectObservations()

public override void AgentAction(float[] vectorAction, string textAction)
{
for (int i = 0; i < vectorAction.Length; i++)
for (int i = 0; i < vectorAction.Length; i++)
{
vectorAction[i] = Mathf.Clamp(vectorAction[i], -1f, 1f);
}

bb.Respawn();
}
jumpLeft = numberJumps;
SetResetParameters();
}
public override void AgentOnDone()

Quaternion.LookRotation(lookDir),
Time.deltaTime * 10f);
}
}
public void SetBananaScale()
{
var banana_scale = resetParams["banana_scale"];
banana.transform.localScale = new Vector3(banana_scale, banana_scale, banana_scale);
}
public void SetResetParameters()
{
SetBananaScale();
}
}

18
docs/Learning-Environment-Examples.md


# Example Learning Environments
# Example Learning Environments
The Unity ML-Agents toolkit contains an expanding set of example environments
which demonstrate various features of the platform. Environments are located in

`VisualBanana` scene. __The visual observation version of
this environment does not train with the provided default
training parameters.__
* Reset Parameters: None.
* Reset Parameters: Two, corresponding to the following
* laser_length: Length of the laser used by the agent
* Default: 1
* Recommended Minimum: 0.2
* Recommended Maximum: 7
* agent_scale: Specifies the scale of the agent in the 3 dimensions (equal across the three dimensions)
* Default: 1
* Recommended Minimum: 0.5
* Recommended Maximum: 5
* Benchmark Mean Reward: 10
* Optional Imitation Learning scene: `BananaIL`.

* Vector Action space: (Continuous) 3 corresponding to agent force applied for
the jump.
* Visual Observations: None.
* Reset Parameters: None.
* Reset Parameters: Two, corresponding to the following
* banana_scale: The scale of the banana in the 3 dimensions
* Default: 150
* Recommended Minimum: 50
* Recommended Maximum: 250
* Benchmark Mean Reward: 10
## [Soccer Twos](https://youtu.be/Hg3nmYD3DjQ)

正在加载...
取消
保存