Instructions to use kuds/car-racing-sac with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- stable-baselines3
How to use kuds/car-racing-sac with stable-baselines3:
from huggingface_sb3 import load_from_hub checkpoint = load_from_hub( repo_id="kuds/car-racing-sac", filename="{MODEL FILENAME}.zip", ) - Notebooks
- Google Colab
- Kaggle
|
Download README.md from kuds/car-racing-sac: direct link, hf CLI and curl.
- Browser
- Download file 2.74 kB
-
https://huggingface.co/kuds/car-racing-sac/resolve/main/README.md
- Command line
-
hf download hf://kuds/car-racing-sac/README.md
-
curl -L -o README.md https://huggingface.co/kuds/car-racing-sac/resolve/main/README.md
2.74 kB
| license: mit | |
| language: | |
| - en | |
| library_name: stable-baselines3 | |
| tags: | |
| - reinforcement-learning | |
| - CarRacing-v3 | |
| model-index: | |
| - name: SAC | |
| results: | |
| - task: | |
| type: reinforcement-learning | |
| name: reinforcement-learning | |
| dataset: | |
| name: CarRacing-v3 | |
| type: CarRacing-v3 | |
| metrics: | |
| - type: mean_reward | |
| value: 787.69 +/- 120.19 | |
| name: mean_reward | |
| verified: false | |
| # **SAC** Agent playing **CarRacing-v3** | |
| - [Github Repository](https://github.com/kuds/rl-car-racing) | |
| - [Google Colab Notebook](https://colab.research.google.com/github/kuds/rl-car-racing/blob/main/%5BCar%20Racing%5D%20Soft%20Actor-Critic%20(SAC).ipynb) | |
| - [Finding Theta - Blog Post](https://www.findingtheta.com/blog/solving-gymnasiums-car-racing-with-reinforcement-learning) | |
| Then, you can load the model using the following Python code: | |
| ```python | |
| import gymnasium as gym | |
| from stable_baselines3 import SAC | |
| from stable_baselines3.common.env_util import make_vec_env | |
| from stable_baselines3.common.vec_env import VecTransposeImage | |
| from stable_baselines3.common.atari_wrappers import WarpFrame | |
| # Load the trained model | |
| model = SAC.load("best-model.zip") | |
| # Create the environment | |
| env = make_vec_env("CarRacing-v3", n_envs=1, wrapper_class=WarpFrame) | |
| env = VecFrameStack(env, n_stack=4) | |
| env = VecTransposeImage(env) | |
| # Reset the environment | |
| obs, info = env.reset() | |
| # Enjoy the trained agent | |
| for _ in range(1000): | |
| action, _states = model.predict(obs, deterministic=True) | |
| obs, rewards, terminated, truncated, info = env.step(action) | |
| if terminated or truncated: | |
| obs, info = env.reset() | |
| env.render() | |
| env.close() | |
| ``` | |
| ### Hugging Face Hub | |
| You can also use the Hugging Face Hub to load the model. First, you need to install the Hugging Face Hub library: | |
| ```bash | |
| pip install huggingface_hub | |
| ``` | |
| Then, you can load the model from the hub using the following code: | |
| ```python | |
| from huggingface_hub import hf_hub_download | |
| import torch as th | |
| import gymnasium as gym | |
| from stable_baselines3 import SAC | |
| from stable_baselines3.common.env_util import make_vec_env | |
| from stable_baselines3.common.vec_env import VecTransposeImage | |
| from stable_baselines3.common.atari_wrappers import WarpFrame | |
| # Download the model from the Hub | |
| model_path = hf_hub_download(repo_id="kuds/car-racing-sac", filename="best-model.zip") | |
| # Load the model | |
| model = SAC.load(model_path) | |
| # Create the environment | |
| env = make_vec_env("CarRacing-v3", n_envs=1, wrapper_class=WarpFrame) | |
| env = VecFrameStack(env, n_stack=4) | |
| env = VecTransposeImage(env) | |
| # Enjoy the trained agent | |
| obs = env.reset() | |
| for i in range(1000): | |
| action, _states = model.predict(obs, deterministic=True) | |
| obs, rewards, dones, info = env.step(action) | |
| env.render("human") | |
| ``` |