Then, you can load the model using the following Python code:
import gymnasium as gym
from stable_baselines3 import SAC
from stable_baselines3.common.env_util import make_atari_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_atari_env("BreakoutNoFrameskip-v4", n_envs=1)
env = VecFrameStack(env, n_stack=4)
env = VecTransposeImage(env)
# Reset the environment
obs, info = env.reset()
# Enjoy the trained agentfor _ inrange(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:
pip install huggingface_hub
Then, you can load the model from the hub using the following code:
from huggingface_hub import hf_hub_download
import torch as th
import gymnasium as gym
from stable_baselines3 import PPO
from stable_baselines3.common.env_util import make_atari_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/drone-racer-sac", filename="best-model.zip")
# Load the model
model = SAC.load(model_path)
# Create the environment
env = make_atari_env("DroneRacer-v0", n_envs=1)
env = VecFrameStack(env, n_stack=4)
env = VecTransposeImage(env)
# Enjoy the trained agent
obs = env.reset()
for i inrange(1000):
action, _states = model.predict(obs, deterministic=True)
obs, rewards, dones, info = env.step(action)
env.render("human")
env.close()
Runs of kuds drone-racer-sac on huggingface.co
0
Total runs
0
24-hour runs
0
3-day runs
0
7-day runs
0
30-day runs
More Information About drone-racer-sac huggingface.co Model
drone-racer-sac huggingface.co is an AI model on huggingface.co that provides drone-racer-sac's model effect (), which can be used instantly with this kuds drone-racer-sac model. huggingface.co supports a free trial of the drone-racer-sac model, and also provides paid use of the drone-racer-sac. Support call drone-racer-sac model through api, including Node.js, Python, http.
drone-racer-sac huggingface.co is an online trial and call api platform, which integrates drone-racer-sac's modeling effects, including api services, and provides a free online trial of drone-racer-sac, you can try drone-racer-sac online for free by clicking the link below.
kuds drone-racer-sac online free url in huggingface.co:
drone-racer-sac is an open source model from GitHub that offers a free installation service, and any user can find drone-racer-sac on GitHub to install. At the same time, huggingface.co provides the effect of drone-racer-sac install, users can directly use drone-racer-sac installed effect in huggingface.co for debugging and trial. It also supports api for free installation.