python-3.x - 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)
解决方案
我检查了这条路径的来源 - 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
使测试图像的最后一个维度(通道)与训练图像的最后一个维度(通道)相匹配。进行相同的更改来调试它。希望这可以帮助!
推荐阅读
- python - 有趣的代码。它是如何工作的?
- ios - iOS:URLRequest Error Domain=NSURLErrorDomain Code=-1202 "此服务器的证书无效
- amazon-web-services - 如何使用 ENV 变量设置 default.region 和 default.output
- python - 没有 Spark 库的`spark-submit` vanilla Python 脚本
- php - 在 Symfony3.4 上没有调用 circular_reference_handler
- python - Pycharm 调试器:断点链接到 remote_source 文件
- database - 如何使用离线/缓存数据库并与在线服务器同步
- c# - 在 C# 中使用 Foreach 循环遍历文件并在 .pdf 之前删除一个破折号和三个额外字符
- php - PHP 从 foreach 循环中检索数组值并将单个值传递给函数
- python - 神经网络(操作数不能与形状一起广播 (1,713) (713,18) )