【问题标题】:ValueError: Cannot feed value of shape (64, 80, 60, 3) for Tensor 'input/X:0', which has shape '(?, 80, 60, 1)'ValueError:无法为张量“输入/X:0”提供形状(64、80、60、3)的值,其形状为“(?、80、60、1)”
【发布时间】:2020-01-26 21:02:24
【问题描述】:

我试图重新创建 Sentdex 在“python 玩 gta V”系列中所做的程序,但是当我来训练 AI 时,它让我出现了这个错误:ValueError: Cannot feed value of shape (64, 80, 60, 3) for Tensor 'input/X:0', which has shape '(?, 80, 60, 1)' 我试图计算 sme 参数,但它没有不工作。这是我的代码:

import numpy as np
from alexnet import alexnet
import time
width=80
height=60
lr=1e-3
epochs=30
model_name='minecraft-ai-{}-{}-{}'.format(lr,'ghostbot',epochs)
model=alexnet(width,height,lr)
train_data=np.load('training_data.npy',allow_pickle=True)
train=train_data[:-500]
test=train_data[-500:]
X=np.array([i[0]for i in train]).reshape(-1,width,height,3)
Y=[i[1] for i in train]

test_x = np.array([i[0] for i in test]).reshape(-1,width,height,3)
test_y = [i[1] for i in test]
print(X.shape)
print(test_x.shape)
time.sleep(3)


model.fit({'input': X}, {'targets': Y}, n_epoch=epochs, validation_set=({'input': test_x}, {'targets': test_y}), 
    snapshot_step=500, show_metric=True, run_id=model_name,)
model.save(model_name)

【问题讨论】:

    标签: python-3.x tensorflow deep-learning


    【解决方案1】:

    我在这条路径上检查了源代码 - https://github.com/Sentdex/pygta5/blob/master/2.%20train_model.py#L91。看来第 91 行已更改为:

    test_x = np.array([i[0] for i in test]).reshape(-1,width,height,3)
    

    因此您需要将最后一个轴(通道数)编辑为3,以便测试图像的最后一个维度(通道)与训练图像的维度相匹配。进行相同的更改来调试它。希望这会有所帮助!

    【讨论】:

    • 它仍然无法正常工作并显示相同的错误
    • 您能否编辑问题并添加您遇到的新错误?
    • 错误和上一个一样
    • 你知道解决办法吗? @Balraj Ashwath
    【解决方案2】:

    这是因为训练图像中的通道数与输入层架构不匹配。

    如果你使用的是灰度图像,在alexnet模型定义和改变

    第 728 行来自

    network = input_data(shape=[None, width, height, 3], name='input') 
    

    到这里

    network = input_data(shape=[None, width, height, 1], name='input')
    

    https://github.com/Sentdex/pygta5/blob/master/models.py#L728

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-01
      • 1970-01-01
      • 2017-04-28
      • 2018-10-06
      • 1970-01-01
      相关资源
      最近更新 更多