cmd 명령어? mlagents-learn config/rollerball_config.yaml --run-id=RollerBall
--resume, --force
이거 하고 start 하라고 하면 그때 재생하면 됨
교육 다 시켰다하면 컨트롤 C 하면 중지되고 nn 파일 생겼다하면 result 폴더에 생겼을거임
그 파일 프로젝트에 넣고 nn 파일 비어있는데 어사인하고 재생하면 교육 완료된거 재생될거임
스크립트 agent 에 Decision Requester 추가 필수 10으로 설정
파라미터 스크립트에 이름 잘 넣고 = 환경 교육 밑에 이름과 동일해야 함
사이즈 8
continuous
2
등등 잘 설정하기
Floor Plane - position = (0, 0, 0), rotation = (0, 0, 0), scale = (1, 1, 1)
Target Cube - position = (3, 0.5, 3), rotation = (0, 0, 0), scale = (1, 1, 1)
RollerAgent Sphere - position = (0, 0.5, 0), rotation = (0, 0, 0), scale = (1, 1, 1) + rigidbody 스크립트 추가!
환경교육? rollerball_config.yaml
behaviors:
RollerBall:
trainer_type: ppo
hyperparameters:
batch_size: 10
buffer_size: 100
learning_rate: 0.0003
beta: 0.005
epsilon: 0.2
lambd: 0.95
num_epoch: 3
learning_rate_schedule: linear
network_settings:
normalize: true
hidden_units: 128
num_layers: 2
vis_encode_type: simple
reward_signals:
extrinsic:
gamma: 0.99
strength: 1.0
keep_checkpoints: 5
checkpoint_interval: 500000
max_steps: 500000
time_horizon: 64
summary_freq: 1000
threaded: true
코드
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
public class RollerAgent : Agent
{
private Rigidbody rBody;
public Transform target;
private void Start()
{
this.rBody = this.GetComponent<Rigidbody>();
}
public override void OnEpisodeBegin()
{
Debug.Log("OnEpisodeBegin");
if(this.transform.localPosition.y < 0) //떨어졌다면
{
//속도를 0
this.rBody.angularVelocity = Vector3.zero;
this.rBody.velocity = Vector3.zero;
this.transform.localPosition = new Vector3(0, 0.5f, 0);
}
this.target.localPosition = new Vector3(UnityEngine.Random.value * 8 - 4, 0.5f, UnityEngine.Random.value * 8 -4); //위치를 초기로
}
public override void CollectObservations(VectorSensor sensor)
{
//
sensor.AddObservation(this.target.localPosition);
sensor.AddObservation(this.transform.localPosition);
sensor.AddObservation(this.rBody.velocity.x);
sensor.AddObservation(this.rBody.velocity.z);
}
public override void OnActionReceived(float[] vectorAction)
{
Vector3 controlSignal = Vector3.zero;
controlSignal.x = vectorAction[0];
controlSignal.z = vectorAction[1];
this.rBody.AddForce(controlSignal * 10);
float distanceToTarget = Vector3.Distance(
this.transform.localPosition, this.target.localPosition);
if (distanceToTarget < 1.42f)
{
AddReward(1.0f);
EndEpisode();
}
if (this.transform.localPosition.y < 0)
{
EndEpisode();
}
}
}
|
cs |
'c# > 수업내용' 카테고리의 다른 글
2020-07-13 node 배운 내용? (0) | 2020.07.13 |
---|---|
캐릭터 얼굴 따기 (0) | 2020.05.21 |
2020.05.15 책 진도 449페이지까지 (0) | 2020.05.15 |
캐릭터, 무기 선택해서 씬로드 실행하기 (0) | 2020.05.15 |
캡쳐해서 아이콘 따는 법 (0) | 2020.05.14 |