Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hands-on-rl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Brussart Paul-emile
hands-on-rl
Commits
8b00c644
Commit
8b00c644
authored
2 years ago
by
Brussart Paul-emile
Browse files
Options
Downloads
Patches
Plain Diff
Adding a2c_sb3_cartpole.py using stable_baselines3
parent
69ad3981
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
a2c_sb3_cartpole.py
+25
-0
25 additions, 0 deletions
a2c_sb3_cartpole.py
a2c_sb3_cartpole.zip
+0
-0
0 additions, 0 deletions
a2c_sb3_cartpole.zip
with
25 additions
and
0 deletions
a2c_sb3_cartpole.py
0 → 100644
+
25
−
0
View file @
8b00c644
import
gym
from
stable_baselines3
import
A2C
from
stable_baselines3.common.vec_env
import
DummyVecEnv
# Create the CartPole environment
env
=
gym
.
make
(
'
CartPole-v1
'
)
# Wrap the environment in a DummyVecEnv to handle multiple environments
env
=
DummyVecEnv
([
lambda
:
env
])
# Initialize the A2C model
model
=
A2C
(
'
MlpPolicy
'
,
env
,
verbose
=
1
)
# Train the model for 1000 steps
model
.
learn
(
total_timesteps
=
1000
)
#Saving the model
model
.
save
(
"
a2c_sb3_cartpole
"
)
# Test the trained model
obs
=
env
.
reset
()
for
i
in
range
(
1000
):
action
,
_states
=
model
.
predict
(
obs
)
obs
,
rewards
,
dones
,
info
=
env
.
step
(
action
)
env
.
render
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
a2c_sb3_cartpole.zip
0 → 100644
+
0
−
0
View file @
8b00c644
File added
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