Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
seminar-breakout
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shashank Suhas
seminar-breakout
Commits
bb1dd917
Commit
bb1dd917
authored
Jun 07, 2016
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto restart player
parent
772af23d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
36 deletions
+12
-36
tensorpack/RL/atari.py
tensorpack/RL/atari.py
+2
-1
tensorpack/RL/common.py
tensorpack/RL/common.py
+10
-35
No files found.
tensorpack/RL/atari.py
View file @
bb1dd917
...
@@ -28,6 +28,7 @@ def log_once():
...
@@ -28,6 +28,7 @@ def log_once():
class
AtariPlayer
(
RLEnvironment
):
class
AtariPlayer
(
RLEnvironment
):
"""
"""
A wrapper for atari emulator.
A wrapper for atari emulator.
NOTE: will automatically restart when a real episode ends
"""
"""
def
__init__
(
self
,
rom_file
,
viz
=
0
,
height_range
=
(
None
,
None
),
def
__init__
(
self
,
rom_file
,
viz
=
0
,
height_range
=
(
None
,
None
),
frame_skip
=
4
,
image_shape
=
(
84
,
84
),
nullop_start
=
30
,
frame_skip
=
4
,
image_shape
=
(
84
,
84
),
nullop_start
=
30
,
...
@@ -58,7 +59,7 @@ class AtariPlayer(RLEnvironment):
...
@@ -58,7 +59,7 @@ class AtariPlayer(RLEnvironment):
self
.
ale
.
setInt
(
"frame_skip"
,
1
)
self
.
ale
.
setInt
(
"frame_skip"
,
1
)
self
.
ale
.
setBool
(
'color_averaging'
,
False
)
self
.
ale
.
setBool
(
'color_averaging'
,
False
)
# manual.pdf suggests otherwise.
may need to check
# manual.pdf suggests otherwise.
self
.
ale
.
setFloat
(
'repeat_action_probability'
,
0.0
)
self
.
ale
.
setFloat
(
'repeat_action_probability'
,
0.0
)
# viz setup
# viz setup
...
...
tensorpack/RL/common.py
View file @
bb1dd917
...
@@ -8,41 +8,7 @@ import numpy as np
...
@@ -8,41 +8,7 @@ import numpy as np
from
collections
import
deque
from
collections
import
deque
from
.envbase
import
ProxyPlayer
from
.envbase
import
ProxyPlayer
__all__
=
[
'HistoryFramePlayer'
,
'PreventStuckPlayer'
,
'LimitLengthPlayer'
]
__all__
=
[
'PreventStuckPlayer'
,
'LimitLengthPlayer'
,
'AutoRestartPlayer'
]
class
HistoryFramePlayer
(
ProxyPlayer
):
""" Include history frames in state, or use black images"""
def
__init__
(
self
,
player
,
hist_len
):
super
(
HistoryFramePlayer
,
self
)
.
__init__
(
player
)
self
.
history
=
deque
(
maxlen
=
hist_len
)
s
=
self
.
player
.
current_state
()
self
.
history
.
append
(
s
)
def
current_state
(
self
):
assert
len
(
self
.
history
)
!=
0
diff_len
=
self
.
history
.
maxlen
-
len
(
self
.
history
)
if
diff_len
==
0
:
return
np
.
concatenate
(
self
.
history
,
axis
=
2
)
zeros
=
[
np
.
zeros_like
(
self
.
history
[
0
])
for
k
in
range
(
diff_len
)]
for
k
in
self
.
history
:
zeros
.
append
(
k
)
return
np
.
concatenate
(
zeros
,
axis
=
2
)
def
action
(
self
,
act
):
r
,
isOver
=
self
.
player
.
action
(
act
)
s
=
self
.
player
.
current_state
()
self
.
history
.
append
(
s
)
if
isOver
:
# s would be a new episode
self
.
history
.
clear
()
self
.
history
.
append
(
s
)
return
(
r
,
isOver
)
def
restart_episode
(
self
):
super
(
HistoryFramePlayer
,
self
)
.
restart_episode
()
self
.
history
.
clear
()
self
.
history
.
append
(
self
.
player
.
current_state
())
class
PreventStuckPlayer
(
ProxyPlayer
):
class
PreventStuckPlayer
(
ProxyPlayer
):
""" Prevent the player from getting stuck (repeating a no-op)
""" Prevent the player from getting stuck (repeating a no-op)
...
@@ -93,3 +59,12 @@ class LimitLengthPlayer(ProxyPlayer):
...
@@ -93,3 +59,12 @@ class LimitLengthPlayer(ProxyPlayer):
def
restart_episode
(
self
):
def
restart_episode
(
self
):
super
(
LimitLengthPlayer
,
self
)
.
restart_episode
()
super
(
LimitLengthPlayer
,
self
)
.
restart_episode
()
self
.
cnt
=
0
self
.
cnt
=
0
class
AutoRestartPlayer
(
ProxyPlayer
):
""" Auto-restart the player on episode ends,
in case some player wasn't designed to do so. """
def
action
(
self
,
act
):
r
,
isOver
=
self
.
player
.
action
(
act
)
if
isOver
:
self
.
player
.
restart_episode
()
return
r
,
isOver
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment