“OpenAI Gym Mario模型用于强化学习中的数值过多/不足”

huangapple go评论69阅读模式
英文:

Too many / Not enough values in OpenAI Gym Mario Model for Reinforcement Learning

问题

Reinforcement learning使用OpenAI Gym具有创建Super Mario Bros强化模型的能力。我尝试按照Nicholas Renotte的YouTube教程进行操作,但大约在10分钟时出现了错误"too many values to unpack (expected 4)"或"not enough values to unpack (expected 5, got 4)"。

这个错误来自于循环中的4个参数返回,但我认为它起源于"env"的实例化。

从Jupyter Notebook:

# 安装必要的库
#!pip install gym_super_mario_bros==7.3.0 nes_py 
import gym_super_mario_bros # 导入游戏库
from nes_py.wrappers import JoypadSpace # 导入包装器
from gym_super_mario_bros.actions import SIMPLE_MOVEMENT # 导入基本动作

# 初始化游戏环境
env = gym_super_mario_bros.make('SuperMarioBros-v0', apply_api_compatibility=True, render_mode="human")

# 使用JoypadSpace包装环境,使用简单的动作
env = JoypadSpace(env, SIMPLE_MOVEMENT)

# 输出动作空间信息
print(env.action_space)

# 输出观察空间形状和信息
print(env.observation_space.shape)
print(env.observation_space)

done = True # 创建一个标志以知道何时重新开始游戏

for step in range(100000): # 循环遍历游戏中的每一帧
    if done:
        # 重新开始游戏
        env.reset()
    state, reward, done, info = env.step(env.action_space.sample()) # 随机执行动作
    env.render() # 在屏幕上显示游戏
# 关闭游戏
env.close()

希望这能帮助你解决问题。

英文:

Reinforcement learning using OpenAI Gym has the ability to make a reinforcement model for playing Super Mario Bros. I tried doing this following Nicholas Renotte's youtube tutorial but around 10 minutes I get the errors "too many values to unpack (expected 4) or "not enough values to unpack (expected 5, got 4)."

The error comes from the 4 parameter return in the loop, but I think it originates from where "env" is instantiated.

From Jupyter Notebook:

#!pip install gym_super_mario_bros==7.3.0 nes_py 
import gym_super_mario_bros #import game

from nes_py.wrappers import JoypadSpace #import wrapper

from gym_super_mario_bros.actions import SIMPLE_MOVEMENT #import basic movements

# Initialize the game

env = gym_super_mario_bros.make('SuperMarioBros-v0', apply_api_compatibility=True, render_mode="human")

#env = gym_super_mario_bros.make('SuperMarioBros-v0')

#make calls the type of environment.you can find more environmnets on the gym website. 

print(env.action_space) #this shows there are 256 actions (complex)

env = JoypadSpace(env, SIMPLE_MOVEMENT) 
#this wraps the environmnet with the simple movement inputs into one object

print(env.action_space) #This shows there are 7 available actions (simplified)

print(env.observation_space.shape)

print(env.observation_space)

print((env.action_space.sample()))

done = True # Create a flag when finished to know when to restart

for step in range(100000): # Loop through each frame in the game

    if done: 

        # Start the gamee

        env.reset()

    state, reward, done, info = env.step(env.action_space.sample())
 # Do random actions

    # Show the game on the screen

    env.render()
# Close the game
env.close()

答案1

得分: 0

问题出在这行代码上:state, reward, done, info = env.step(env.action_space.sample())。您试图使用4个变量而不是5个来解包env.step。请查看step函数的文档此处

用这个替换:

state, reward, done, truncated, info = env.step(env.action_space.sample())
英文:

The issue is with this line : state, reward, done, info = env.step(env.action_space.sample()). you're trying to unpack env.step using 4 variables instead of 5. Take a look at the documentation of the step function here

Replace it with this :

state, reward, done, truncated , info = env.step(env.action_space.sample()

huangapple
  • 本文由 发表于 2023年5月7日 03:18:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76190686.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定