1

I am trying to implement an Pybullet + Gym model to generate an RF-Learning Robot.

Referred to this YouTube video - https://youtu.be/uczY8oAgLMs

Code -

import gym
import pybullet, pybullet_envs
import torch as th

from stable_baselines3 import PPO
from stable_baselines3.common.evaluation import evaluate_policy

# Create environment
# env = gym.make('LunarLanderContinuous-v2')

env = gym.make('AntBulletEnv-v0')
env.render(mode="human")

policy_kwargs = dict(activation_fn=th.nn.LeakyReLU, net_arch=[512, 512])
# Instantiate the agent
model = PPO('MlpPolicy', env,learning_rate=0.0003,policy_kwargs=policy_kwargs, verbose=1)

del model  # delete trained model to demonstrate loading
# Load the trained agent
model = PPO.load("ppo_Ant_saved_model_7.zip")

# # Evaluate the agent
# mean_reward, std_reward = evaluate_policy(model, model.get_env(), n_eval_episodes=10)

# Enjoy trained agent
obs = env.reset()
for i in range(100):
    dones = False
    game_score = 0
    steps = 0
    while not dones:
        action, _states = model.predict(obs, deterministic=True)
        obs, rewards, dones, info = env.step(action)
        # import ipdb;ipdb.set_trace()
        game_score+=rewards
        steps+=1
        env.render()
    print("game ", i ," steps   ",steps, " game score %.3f"%game_score)
    obs = env.reset()
    # break

Error -

pybullet build time: Oct 16 2022 21:41:54
Using cpu device
Wrapping the env with a `Monitor` wrapper
Wrapping the env in a DummyVecEnv.
C:\Python\Python395\lib\site-packages\stable_baselines3\common\save_util.py:1
using `custom_objects` argument to replace this object.
  warnings.warn(
C:\Python\Python395\lib\site-packages\stable_baselines3\common\save_util.py:1    model._setup_model()
  File "C:\Python\Python395\lib\site-packages\stable_baselines3\ppo\ppo.py", 
line 173, in _setup_model
    self.clip_range = get_schedule_fn(self.clip_range)
  File "C:\Python\Python395\lib\site-packages\stable_baselines3\common\utils.py", line 91, in get_schedule_fn
    assert callable(value_schedule)
AssertionError

Already Tried - I have already trained the model and a ZIP file has been created, but unable to run the model when called.

Topaz Blue
  • 11
  • 1

0 Answers0