Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
ResNet50_tensorflow
Commits
8722f59f
Unverified
Commit
8722f59f
authored
Jun 12, 2020
by
moneypi
Committed by
GitHub
Jun 11, 2020
Browse files
update a3c_cartpole.py to tf2.x (#8662)
* update a3c_cartpole.py to tf2.x * update a3c_cartpole.py to tf2.x
parent
ad423d06
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
5 deletions
+3
-5
research/a3c_blogpost/README.md
research/a3c_blogpost/README.md
+1
-1
research/a3c_blogpost/a3c_cartpole.py
research/a3c_blogpost/a3c_cartpole.py
+2
-4
No files found.
research/a3c_blogpost/README.md
View file @
8722f59f
...
...
@@ -3,4 +3,4 @@ In order to run this code, you will need the following prerequisites:
*
[
OpenAI Gym
](
https://github.com/openai/gym
)
-
`pip install gym`
*
[
pyglet
](
https://bitbucket.org/pyglet/pyglet/wiki/Home
)
-
`pip install pyglet`
*
[
TensorFlow
](
https://www.tensorflow.org/install/
)
-
`pip install tensorflow==
v1.14
.0`
*
[
TensorFlow
](
https://www.tensorflow.org/install/
)
-
`pip install tensorflow==
2.2
.0`
research/a3c_blogpost/a3c_cartpole.py
View file @
8722f59f
...
...
@@ -14,8 +14,6 @@ import tensorflow as tf
from
tensorflow.python
import
keras
from
tensorflow.python.keras
import
layers
tf
.
enable_eager_execution
()
parser
=
argparse
.
ArgumentParser
(
description
=
'Run A3C algorithm on the game '
'Cartpole.'
)
parser
.
add_argument
(
'--algorithm'
,
default
=
'a3c'
,
type
=
str
,
...
...
@@ -135,7 +133,7 @@ class MasterAgent():
env
=
gym
.
make
(
self
.
game_name
)
self
.
state_size
=
env
.
observation_space
.
shape
[
0
]
self
.
action_size
=
env
.
action_space
.
n
self
.
opt
=
tf
.
train
.
AdamOptimizer
(
args
.
lr
,
use_locking
=
True
)
self
.
opt
=
tf
.
compat
.
v1
.
train
.
AdamOptimizer
(
args
.
lr
,
use_locking
=
True
)
print
(
self
.
state_size
,
self
.
action_size
)
self
.
global_model
=
ActorCriticModel
(
self
.
state_size
,
self
.
action_size
)
# global network
...
...
@@ -348,7 +346,7 @@ class Worker(threading.Thread):
# Calculate our policy loss
policy
=
tf
.
nn
.
softmax
(
logits
)
entropy
=
tf
.
nn
.
softmax_cross_entropy_with_logits
_v2
(
labels
=
policy
,
logits
=
logits
)
entropy
=
tf
.
nn
.
softmax_cross_entropy_with_logits
(
labels
=
policy
,
logits
=
logits
)
policy_loss
=
tf
.
nn
.
sparse_softmax_cross_entropy_with_logits
(
labels
=
memory
.
actions
,
logits
=
logits
)
...
...
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