【问题标题】:ValueError: At least one stride in the given numpy array is negative, and tensors with negative strides are not currently supportedValueError:给定的numpy数组中至少一个步幅为负,当前不支持具有负步幅的张量
【发布时间】:2022-08-08 16:38:52
【问题描述】:

我正在使用 RL 编写自动驾驶代码。我正在使用一个稳定的baseline3 和一个开放的ai 健身房环境。我在 jupyter notebook 中运行以下代码,它给了我以下错误:

# Testing our model
episodes = 5 # test the environment 5 times
for episodes in range(1,episodes+1): # looping through each episodes
    bs = env.reset() # observation space
    # Taking the obs and passing it through our model
    # tells that which kind of the action is best for our work
    done = False 
    score = 0
    while not done:
        env.render()
        action, _ = model.predict(obs) # now using model here # returns model action and next 
state
        # take that action to get the best reward
        # for observation space we get the box environment
        # rather than getting random action we are using model.predict(obs) on our obs for an 
curr env to gen the action inorder to get best possible reward
        obs, reward, done, info = env.step(action)  # gies state, reward whose value is 1
        # reward is 1 for every step including the termination step
        score += reward
    print(\'Episode:{},Score:{}\'.format(episodes,score))\'\'\'
env.close()

错误

我编写的代码的链接如下: https://drive.google.com/file/d/1JBVmPLn-N1GCl_Rgb6-qGMpJyWvBaR1N/view?usp=sharing

我使用的python版本是Anaconda Environment中的Python 3.8.13。 我使用的是 Pytorch CPU 版本,操作系统是 Windows 10。 请帮我解决这个问题。

    标签: python reinforcement-learning openai-gym stable-baselines


    【解决方案1】:

    对 numpy 数组使用 .copy() 应该会有所帮助 (PyTorch tensors can't handle negative indices)

    action, _ = model.predict(obs.copy())
    

    由于依赖问题,我无法快速运行您的笔记本,但我在使用 AI2THOR 模拟器时遇到了同样的错误,添加 .copy() 有帮助。 也许对 numpy、torch 或 AI2THOR 有更多技术知识的人会解释为什么会这样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-26
      相关资源
      最近更新 更多