Farama-Foundation / Minigrid

Simple and easily configurable grid world environments for reinforcement learning
https://minigrid.farama.org/
Other
2.13k stars 611 forks source link

[Bug Report] Cannot run example code: TypeError: 'module' object is not callable #441

Closed AsadJeewa closed 4 months ago

AsadJeewa commented 4 months ago

Describe the bug Cannot run example code: TypeError: 'module' object is not callable

Code example https://minigrid.farama.org/content/training/

Checklist

AsadJeewa commented 4 months ago

This file seems outdated: https://github.com/Farama-Foundation/Minigrid/blob/master/docs/content/training.md

pseudo-rnd-thoughts commented 4 months ago

What line exactly is causing errors?

AsadJeewa commented 4 months ago

When using the policy_kwargs in line 15: model = PPO("CnnPolicy", env, policy_kwargs=policy_kwargs, verbose=1)

return self.features_extractor_class(self.observation_space, **self.features_extractor_kwargs)
TypeError: 'module' object is not callable

So the issue is with the MinigridFeaturesExtractor

AsadJeewa commented 4 months ago
import minigrid
from minigrid.wrappers import ImgObsWrapper
from stable_baselines3 import PPO
import MinigridFeaturesExtractor
import gymnasium as gym

policy_kwargs = dict(
    features_extractor_class=MinigridFeaturesExtractor,
    features_extractor_kwargs=dict(features_dim=128),
)

env = gym.make("MiniGrid-Empty-16x16-v0", render_mode="rgb_array")
env = ImgObsWrapper(env)

model = PPO("CnnPolicy", env, policy_kwargs=policy_kwargs, verbose=1)
model.learn(2e5)
AsadJeewa commented 4 months ago

Apologies I was importing from MinigridFeaturesExtractor incorrectly. Changed it to from MinigridFeaturesExtractor import MinigridFeaturesExtractor

However, the team should add the imports to the example.