Skip to content
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

Fix stable-baselines3 notebook for google colab usage (python 3.9) #455

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 43 additions & 35 deletions scripts/sb3_highway_dqn.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@
{
"cell_type": "markdown",
"metadata": {
"id": "5eeje4O8fviH",
"pycharm": {
"name": "#%% md\n"
}
"id": "5eeje4O8fviH"
},
"source": [
"# Highway with SB3's DQN\n",
Expand All @@ -51,21 +48,35 @@
"We start with a few useful installs and imports:"
]
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"# Install environment and agent\n",
"!pip install setuptools==65.5.0\n",
"!pip install highway-env==1.5\n",
"!pip install stable-baselines3[extra]==1.7.0\n",
"\n",
"!pip install tensorboardx gym pyvirtualdisplay\n",
"!apt-get install -y xvfb python-opengl ffmpeg\n",
"\n",
"# clone specific branch for script/utils to record and show videos\n",
"!git clone https://github.com/eleurent/highway-env.git --branch \"v1.6\" --single-branch"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"metadata": {
"id": "bzMSuJEOfviP",
"pycharm": {
"is_executing": false,
"name": "#%%\n"
"is_executing": false
}
},
"source": [
"# Install environment and agent\n",
"!pip install highway-env\n",
"# TODO: we use the bleeding edge version because the current stable version does not support the latest gym>=0.21 versions. Revert back to stable at the next SB3 release.\n",
"!pip install git+https://github.com/DLR-RM/stable-baselines3\n",
"\n",
"# Environment\n",
"import gym\n",
"import highway_env\n",
Expand All @@ -77,11 +88,11 @@
"%load_ext tensorboard\n",
"import sys\n",
"from tqdm.notebook import trange\n",
"!pip install tensorboardx gym pyvirtualdisplay\n",
"!apt-get install -y xvfb python-opengl ffmpeg\n",
"!git clone https://github.com/eleurent/highway-env.git 2> /dev/null\n",
"sys.path.insert(0, '/content/highway-env/scripts/')\n",
"from utils import record_videos, show_videos"
"from utils import record_videos, show_videos\n",
"\n",
"# for suppress warnings\n",
"import warnings"
],
"execution_count": null,
"outputs": []
Expand All @@ -90,9 +101,6 @@
"cell_type": "markdown",
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% md\n"
},
"id": "_wACJRDjqP-f"
},
"source": [
Expand Down Expand Up @@ -124,19 +132,22 @@
},
"source": [
"model = DQN('MlpPolicy', \"highway-fast-v0\",\n",
" policy_kwargs=dict(net_arch=[256, 256]),\n",
" learning_rate=5e-4,\n",
" buffer_size=15000,\n",
" learning_starts=200,\n",
" batch_size=32,\n",
" gamma=0.8,\n",
" train_freq=1,\n",
" gradient_steps=1,\n",
" target_update_interval=50,\n",
" exploration_fraction=0.7,\n",
" verbose=1,\n",
" tensorboard_log=\"highway_dqn/\")\n",
"model.learn(int(2e4))\n"
" policy_kwargs=dict(net_arch=[256, 256]),\n",
" learning_rate=5e-4,\n",
" buffer_size=15000,\n",
" learning_starts=200,\n",
" batch_size=32,\n",
" gamma=0.8,\n",
" train_freq=1,\n",
" gradient_steps=1,\n",
" target_update_interval=50,\n",
" exploration_fraction=0.7,\n",
" verbose=1,\n",
" tensorboard_log=\"highway_dqn/\")\n",
"with warnings.catch_warnings():\n",
" warnings.simplefilter('ignore') # suppress the df append usage warning\n",
" model.learn(int(2e4))\n",
"\n"
],
"execution_count": null,
"outputs": []
Expand All @@ -155,10 +166,7 @@
{
"cell_type": "code",
"metadata": {
"id": "xOcOP7Of18T2",
"pycharm": {
"name": "#%%\n"
}
"id": "xOcOP7Of18T2"
},
"source": [
"env = gym.make(\"highway-fast-v0\")\n",
Expand Down