Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
LearningEnvironment
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Armin Co
LearningEnvironment
Commits
99dec5eb
Commit
99dec5eb
authored
4 years ago
by
Armin Co
Browse files
Options
Downloads
Patches
Plain Diff
Monitoring offline training
parent
b39317dc
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
environment_wrapper.py
+15
-7
15 additions, 7 deletions
environment_wrapper.py
networks.py
+3
-2
3 additions, 2 deletions
networks.py
with
18 additions
and
9 deletions
environment_wrapper.py
+
15
−
7
View file @
99dec5eb
...
...
@@ -77,24 +77,32 @@ def one_episode(environment, agent, render, learn, conf=None, max_steps=1000):
def
learn_offline
(
agent
,
conf
):
"""
Train the agent with its memories.
"""
print
(
'
Learning with
'
,
len
(
agent
.
memory
.
history
),
'
memories.
'
)
agent
.
epsilon
=
agent
.
epsilon_min
score_history
=
[]
avg_score_history
=
[]
desc_train
=
''
pbar
=
trange
(
conf
.
offline_epochs
,
desc
=
'
Loss: x
'
)
for
i
in
pbar
:
loss
=
agent
.
learn
(
offline
=
True
,
epochs
=
conf
.
learn_iterations
)
desc
=
(
'
Loss: %05.4f
'
%
(
loss
))
desc
=
(
'
Loss: %05.4f
'
%
(
loss
))
+
desc_train
pbar
.
set_description
(
desc
)
pbar
.
refresh
()
if
i
%
conf
.
offline_validate_every_x_iteration
==
0
and
conf
.
offline_validate_every_x_iteration
is
not
-
1
:
score
,
avg
=
run
(
conf
.
env
,
conf
.
agent
,
1
,
render
=
conf
.
render
,
learn
=
False
,
conf
=
conf
)
conf
.
name
+=
'
1
'
process_logs
(
avg
,
score
,
conf
)
if
avg
[
-
1
]
>
IS_SOLVED
:
if
i
%
conf
.
offline_validate_every_x_iteration
==
1
and
conf
.
offline_validate_every_x_iteration
is
not
-
1
:
score
=
one_episode
(
conf
.
env
,
agent
,
conf
.
render
,
False
,
conf
=
conf
)
score_history
.
append
(
score
)
is_solved
=
np
.
mean
(
score_history
[
-
25
:])
desc_train
=
(
'
, Avg: %05.1f
'
%
(
is_solved
))
avg_score_history
.
append
(
is_solved
)
if
is_solved
>
IS_SOLVED
:
break
process_logs
(
avg_score_history
,
score_history
,
conf
)
def
run
(
environment
,
agent
,
episodes
,
render
=
True
,
learn
=
True
,
conf
=
None
):
"""
Run an agent
"""
conf
.
name
+=
'
on
'
# Set the exploring rate to its minimum.
# (epsilon *greedy*)
if
not
learn
:
...
...
This diff is collapsed.
Click to expand it.
networks.py
+
3
−
2
View file @
99dec5eb
...
...
@@ -5,7 +5,7 @@ from keras.layers import Dense
from
keras.optimizers
import
Adam
from
keras.activations
import
relu
,
linear
from
keras.regularizers
import
l2
from
keras.callbacks
import
EarlyStopping
class
QNet
:
learn_rate
=
0.0005
...
...
@@ -34,7 +34,8 @@ class QNet:
self
,
states
):
return
self
.
net
.
predict_on_batch
(
states
)
def
fit
(
self
,
X
,
Y
,
epochs
=
1
,
verbose
=
0
):
history
=
self
.
net
.
fit
(
X
,
Y
,
epochs
=
epochs
,
verbose
=
verbose
)
callback
=
EarlyStopping
(
monitor
=
'
loss
'
,
patience
=
3
)
history
=
self
.
net
.
fit
(
X
,
Y
,
epochs
=
epochs
,
verbose
=
verbose
,
callbacks
=
[
callback
])
return
history
.
history
[
'
loss
'
][
-
1
]
def
save
(
self
,
path
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment