浏览代码

modify bullet/attn

/exp-alternate-atten
Andrew Cohen 4 年前
当前提交
d62f6b0a
共有 7 个文件被更改,包括 98 次插入97 次删除
  1. 7
      Project/Assets/ML-Agents/Examples/Bullet/Demos/ExpertPush.demo.meta
  2. 118
      Project/Assets/ML-Agents/Examples/Bullet/Prefabs/BulletArea.prefab
  3. 19
      Project/Assets/ML-Agents/Examples/Bullet/Scripts/BulletAgent.cs
  4. 2
      Project/Assets/ML-Agents/Examples/Bullet/Scripts/DodgeAgent.cs
  5. 10
      config/ppo/Bullet.yaml
  6. 32
      ml-agents/mlagents/trainers/torch/networks.py
  7. 7
      Project/Assets/ML-Agents/Examples/Bullet/Scripts/.BulletAgent.cs.swp

7
Project/Assets/ML-Agents/Examples/Bullet/Demos/ExpertPush.demo.meta


fileFormatVersion: 2
guid: 991552fb1f89746feb752872053e8fea
ScriptedImporter:
fileIDToRecycleName:
11400000: Assets/ML-Agents/Examples/Bullet/Demos/ExpertPush.demo
internalIDToNameTable:
- first:
114: 11400000
second: Assets/ML-Agents/Examples/Bullet/Demos/ExpertPush.demo
serializedVersion: 2
userData: ' (Unity.MLAgents.Demonstrations.DemonstrationSummary)'
assetBundleName:
assetBundleVariant:

118
Project/Assets/ML-Agents/Examples/Bullet/Prefabs/BulletArea.prefab


areaBounds:
m_Center: {x: 0, y: 0, z: 0}
m_Extent: {x: 0, y: 0, z: 0}
rad: 5
rad: 23
time: 0.2
dir: -1
useVectorObs: 0
--- !u!1 &7099812715628705112
GameObject:

areaBounds:
m_Center: {x: 0, y: 0, z: 0}
m_Extent: {x: 0, y: 0, z: 0}
rad: 1
rad: 23
time: 0.3
dir: 1
useVectorObs: 0
--- !u!1 &7564015931936126656
GameObject:

m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0

m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0

m_Modification:
m_TransformParent: {fileID: 7562565324271374322}
m_Modifications:
- target: {fileID: 968348991679639438, guid: 7a515d80a9d5b4cfaba55aa066594016,
- target: {fileID: 5229809530250264056, guid: 7a515d80a9d5b4cfaba55aa066594016,
propertyPath: ground
value:
objectReference: {fileID: 7564015931936126656}
- target: {fileID: 968348991679639438, guid: 7a515d80a9d5b4cfaba55aa066594016,
propertyPath: m_Name
value: DodgeAgentRaycast
objectReference: {fileID: 0}
- target: {fileID: 5229809530250264056, guid: 7a515d80a9d5b4cfaba55aa066594016,
propertyPath: area
value:
objectReference: {fileID: 7565593112241766594}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2272550728573618168, guid: 7a515d80a9d5b4cfaba55aa066594016,
type: 3}
propertyPath: m_LocalPosition.x

propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5229809530250264056, guid: 7a515d80a9d5b4cfaba55aa066594016,
- target: {fileID: 968348991679639438, guid: 7a515d80a9d5b4cfaba55aa066594016,
propertyPath: m_Name
value: DodgeAgentRaycast
objectReference: {fileID: 0}
- target: {fileID: 5229809530250264056, guid: 7a515d80a9d5b4cfaba55aa066594016,
propertyPath: ground
value:
objectReference: {fileID: 7564015931936126656}
- target: {fileID: 968348991679639438, guid: 7a515d80a9d5b4cfaba55aa066594016,
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
propertyPath: area
value:
objectReference: {fileID: 7565593112241766594}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 7a515d80a9d5b4cfaba55aa066594016, type: 3}
--- !u!4 &4270948751059092865 stripped

m_Modification:
m_TransformParent: {fileID: 7562565324271374322}
m_Modifications:
- target: {fileID: 968348991679639438, guid: 16266ae2c040142b1a996878d94ec3fb,
- target: {fileID: 5229809530250264056, guid: 16266ae2c040142b1a996878d94ec3fb,
propertyPath: ground
value:
objectReference: {fileID: 7564015931936126656}
- target: {fileID: 968348991679639438, guid: 16266ae2c040142b1a996878d94ec3fb,
propertyPath: m_Name
value: DodgeAgent
objectReference: {fileID: 0}
- target: {fileID: 5229809530250264056, guid: 16266ae2c040142b1a996878d94ec3fb,
propertyPath: area
value:
objectReference: {fileID: 7565593112241766594}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2272550728573618168, guid: 16266ae2c040142b1a996878d94ec3fb,
type: 3}
propertyPath: m_LocalPosition.x

propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5229809530250264056, guid: 16266ae2c040142b1a996878d94ec3fb,
- target: {fileID: 968348991679639438, guid: 16266ae2c040142b1a996878d94ec3fb,
propertyPath: m_Name
value: DodgeAgent
objectReference: {fileID: 0}
- target: {fileID: 5229809530250264056, guid: 16266ae2c040142b1a996878d94ec3fb,
propertyPath: ground
value:
objectReference: {fileID: 7564015931936126656}
- target: {fileID: 968348991679639438, guid: 16266ae2c040142b1a996878d94ec3fb,
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
propertyPath: area
value:
objectReference: {fileID: 7565593112241766594}
m_RemovedComponents:
- {fileID: 9204493211719777360, guid: 16266ae2c040142b1a996878d94ec3fb, type: 3}
m_SourcePrefab: {fileID: 100100000, guid: 16266ae2c040142b1a996878d94ec3fb, type: 3}

m_Modification:
m_TransformParent: {fileID: 7562565324271374322}
m_Modifications:
- target: {fileID: 114291266114270340, guid: 6693afcd33b8842fba88da9b967315ff,
- target: {fileID: 5229809530250264056, guid: 6693afcd33b8842fba88da9b967315ff,
propertyPath: ChannelDepth.Array.size
value: 1
propertyPath: m_Name
value: GridDodgeAgent
- target: {fileID: 114291266114270340, guid: 6693afcd33b8842fba88da9b967315ff,
- target: {fileID: 5229809530250264056, guid: 6693afcd33b8842fba88da9b967315ff,
propertyPath: ChannelDepth.Array.data[0]
value: 1
propertyPath: m_IsActive
value: 0
- target: {fileID: 968348991679639438, guid: 6693afcd33b8842fba88da9b967315ff,
type: 3}
propertyPath: ground
value:
objectReference: {fileID: 7564015931936126656}
- target: {fileID: 968348991679639438, guid: 6693afcd33b8842fba88da9b967315ff,
type: 3}
propertyPath: area
value:
objectReference: {fileID: 7565593112241766594}
- target: {fileID: 2272550728573618168, guid: 6693afcd33b8842fba88da9b967315ff,
type: 3}
propertyPath: m_LocalPosition.x

propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5229809530250264056, guid: 6693afcd33b8842fba88da9b967315ff,
- target: {fileID: 968348991679639438, guid: 6693afcd33b8842fba88da9b967315ff,
type: 3}
propertyPath: ground
value:
objectReference: {fileID: 7564015931936126656}
- target: {fileID: 968348991679639438, guid: 6693afcd33b8842fba88da9b967315ff,
propertyPath: m_Name
value: GridDodgeAgent
propertyPath: area
value:
objectReference: {fileID: 7565593112241766594}
- target: {fileID: 114291266114270340, guid: 6693afcd33b8842fba88da9b967315ff,
type: 3}
propertyPath: ChannelDepth.Array.size
value: 1
- target: {fileID: 5229809530250264056, guid: 6693afcd33b8842fba88da9b967315ff,
- target: {fileID: 114291266114270340, guid: 6693afcd33b8842fba88da9b967315ff,
propertyPath: m_IsActive
value: 0
propertyPath: ChannelDepth.Array.data[0]
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 6693afcd33b8842fba88da9b967315ff, type: 3}

19
Project/Assets/ML-Agents/Examples/Bullet/Scripts/BulletAgent.cs


[HideInInspector]
public Bounds areaBounds;
public float rad;
public float time;
public float dir;
BulletSettings m_BulletSettings;

public void FixedUpdate()
{
if (Time.time > m_BulletTime + 0.03f)
if (Time.time > m_BulletTime + time)
var r = Random.Range(0f, 360f);
var ra = Random.Range(0, 2);
var dir = -1f;
if (ra == 1)
{
dir = 1f;
}
var angle = dir * (5f * Mathf.PI/ 180f);
//var r = Random.Range(0f, 360f);
var angle = dir * (30f * Mathf.PI/ 180f);
Quaternion rotation = Quaternion.Euler(0, r, 0);
//Quaternion rotation = Quaternion.LookRotation(m_center - pos);
//Quaternion rotation = Quaternion.Euler(0, r, 0);
Quaternion rotation = Quaternion.LookRotation(m_center - pos);
var ob = Instantiate(m_BulletRb, pos, rotation, area.transform);
m_currX = x;
m_currZ = z;

2
Project/Assets/ML-Agents/Examples/Bullet/Scripts/DodgeAgent.cs


{
if (collision.gameObject.CompareTag("bullet") || collision.gameObject.CompareTag("wall"))
{
SetReward(0f);
SetReward(-1f);
EndEpisode();
}
}

10
config/ppo/Bullet.yaml


Dodge:
trainer_type: ppo
hyperparameters:
batch_size: 1024
buffer_size: 10240
batch_size: 4096
buffer_size: 40960
learning_rate_schedule: linear
learning_rate_schedule: constant
normalize: true
normalize: false
hidden_units: 128
num_layers: 2
vis_encode_type: simple

strength: 1.0
keep_checkpoints: 5
max_steps: 5000000
max_steps: 50000000
time_horizon: 64
summary_freq: 10000
threaded: true

32
ml-agents/mlagents/trainers/torch/networks.py


self.use_fc = False
if not self.use_fc:
emb_size = 64
emb_size = 32
x_self_size=64,
entities_sizes=[64], # hard coded, 4 obs per entity
x_self_size=32,
entities_sizes=[32], # hard coded, 4 obs per entity
#self.self_embedding = LinearEncoder(6, 2, 64)
#self.obs_embeding = LinearEncoder(4, 2, 64)
# self.self_and_obs_embedding = LinearEncoder(64 + 64, 1, 64)
# self.dense_after_attention = LinearEncoder(64, 1, 64)
#self.self_embedding = LinearEncoder(6, 2, 32)
#self.obs_embeding = LinearEncoder(4, 2, 32)
# self.self_and_obs_embedding = LinearEncoder(32 + 32, 1, 32)
# self.dense_after_attention = LinearEncoder(32, 1, 32)
self.embedding_encoder = LinearEncoder(10, 2, 64)
#self.embedding_encoder = LinearEncoder(10, 2, 32)
self.embedding_encoder = LinearEncoder(4, 2, 32)
emb_size, network_settings.num_layers - 1, self.h_size
emb_size + 6, network_settings.num_layers - 1, self.h_size
)
else:
self.linear_encoder = LinearEncoder(

if not self.use_fc:
#x_self = self.embedding(processed_vec)
var_len_input = vis_inputs[0].reshape(-1, 20, 4)
expanded_self = processed_vec.reshape(-1, 1, 6)
expanded_self = torch.cat([expanded_self] * 20, dim=1)
concat_ent = torch.cat([expanded_self, var_len_input], dim=-1)
processed_var_len_input = self.embedding_encoder(concat_ent)
#expanded_self = processed_vec.reshape(-1, 1, 6)
#expanded_self = torch.cat([expanded_self] * 20, dim=1)
#concat_ent = torch.cat([expanded_self, var_len_input], dim=-1)
#processed_var_len_input = self.embedding_encoder(concat_ent)
processed_var_len_input = self.embedding_encoder(var_len_input)
output = self.transformer(processed_var_len_input, self.masking_module([var_len_input]))
#output = self.transformer(x_self, [processed_var_len_input], self.masking_module([var_len_input]))

# 1 - key_mask, dim=1, keepdim=True
# ) + 0.001 ) # average pooling
#encoding = self.linear_encoder(torch.cat([output, x_self], dim=1))
encoding = self.linear_encoder(output)
encoding = self.linear_encoder(torch.cat([output, processed_vec], dim=1))
#encoding = self.linear_encoder(output)
else:
encoding = self.linear_encoder(torch.cat([vis_inputs[0].reshape(-1, 80), processed_vec], dim=1))

7
Project/Assets/ML-Agents/Examples/Bullet/Scripts/.BulletAgent.cs.swp
文件差异内容过多而无法显示
查看文件

正在加载...
取消
保存