-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Update actor_critic_cartpole.py #2155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -45,7 +45,7 @@ | |||||||||
import os | ||||||||||
|
||||||||||
os.environ["KERAS_BACKEND"] = "tensorflow" | ||||||||||
import gym | ||||||||||
import gymnasium as gym | ||||||||||
import numpy as np | ||||||||||
import keras | ||||||||||
from keras import ops | ||||||||||
|
@@ -98,13 +98,13 @@ | |||||||||
episode_count = 0 | ||||||||||
|
||||||||||
while True: # Run until solved | ||||||||||
state = env.reset()[0] | ||||||||||
obs, _ = env.reset() | ||||||||||
episode_reward = 0 | ||||||||||
with tf.GradientTape() as tape: | ||||||||||
for timestep in range(1, max_steps_per_episode): | ||||||||||
|
||||||||||
state = ops.convert_to_tensor(state) | ||||||||||
state = ops.expand_dims(state, 0) | ||||||||||
state = tf.convert_to_tensor(state) | ||||||||||
state = tf.expand_dims(state, 0) | ||||||||||
Comment on lines
+106
to
+107
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change replaces The
Suggested change
|
||||||||||
|
||||||||||
# Predict action probabilities and estimated future rewards | ||||||||||
# from environment state | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
env.reset()
call now returns the observation into theobs
variable, but the rest of the loop expects this value to be in thestate
variable. This will cause aNameError
on line 106 whenstate
is used before it's assigned a value. To fix this, the observation should be assigned tostate
.