Views
No views yet
1import gymnasium as gym
2from sb3_contrib import TQC
3from stable_baselines3.common.env_util import make_vec_env
4
5gymnasium.register_envs(gymnasium_robotics)
6
7# Load the trained model
8model = TQC.load("best-model.zip")
9
10# Create the environment
11env = make_vec_env("FetchSlideDense-v4", n_envs=1)
12
13# Reset the environment
14obs, info = env.reset()
15
16# Enjoy the trained agent
17for _ in range(1000):
18 action, _states = model.predict(obs, deterministic=True)
19 obs, rewards, terminated, truncated, info = env.step(action)
20 if terminated or truncated:
21 obs, info = env.reset()
22 env.render()
23env.close()pip install huggingface_hub1from huggingface_hub import hf_hub_download
2import torch as th
3from sb3_contrib import TQC
4from stable_baselines3.common.env_util import make_vec_env
5
6gymnasium.register_envs(gymnasium_robotics)
7
8# Download the model from the Hub
9model_path = hf_hub_download(repo_id="kuds/fetch-slide-dense-tqc", filename="best-model.zip")
10
11# Load the model
12model = TQC.load(model_path)
13
14# Create the environment
15env = make_vec_env("FetchSlideDense-v4", n_envs=1)
16
17# Enjoy the trained agent
18obs = env.reset()
19for i in range(1000):
20 action, _states = model.predict(obs, deterministic=True)
21 obs, rewards, dones, info = env.step(action)
22 env.render("human")