首页 > 解决方案 > ValueError:无法为张量“输入/X:0”提供形状(64、80、60、3)的值,其形状为“(?、80、60、1)”

问题描述

我试图重新创建 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)'我试图 canche 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.xtensorflowdeep-learning

解决方案


我检查了这条路径的来源 - 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使测试图像的最后一个维度(通道)与训练图像的最后一个维度(通道)相匹配。进行相同的更改来调试它。希望这可以帮助!


推荐阅读