gpt4 book ai didi

python - ValueError : Error when checking input: expected input_3 to have shape (34, )但得到形状为(36,)的数组

转载 作者:行者123 更新时间:2023-11-30 10:00:30 26 4
gpt4 key购买 nike

我已经使用 Keras 训练了 TPU 来进行图像字幕处理。我运行时遇到错误: 将 matplotlib.pyplot 导入为 plt

def generateCaption(photo):

in_text = START
for i in range(max_length):
sequence = [wordtoidx[w] for w in in_text.split() if w in wordtoidx]
sequence = pad_sequences([sequence], maxlen=max_length)

yhat = caption_model.predict([photo,sequence], verbose=0)
yhat = np.argmax(yhat)

word = idxtoword[yhat]
in_text += ' ' + word

if word == STOP:
break

final = in_text.split()
final = final[1:-1]
final = ' '.join(final)

return final


for z in range(10):
pic = list(encoding_test.keys())[z]
image = encoding_test[pic].reshape((1,OUTPUT_DIM))

print(os.path.join(root_captioning,'/content/drive/My Drive/ImageCaptioning/Flicker8k Dataset', pic))
x = plt.imread(os.path.join(root_captioning,'/content/drive/My Drive/ImageCaptioning/Flicker8k Dataset', pic))

plt.imshow(x)
plt.show()

print("Caption:",generateCaption(image))
print("_____________________________________")

行错误:print("Caption:",generateCaption(image))我尝试了不同的 reshape 选项,还尝试删除 reshape 功能,但错误仍然存​​在。

最佳答案

这个错误发生在我尝试训练网络时,所以它可能与LSTM有关。在这种特定情况下,模型会提示,因为第三层尺寸不匹配。您可以尝试检查训练图像是否与您在此处使用的图像具有相同的尺寸,或者检查图层的参数。

关于python - ValueError : Error when checking input: expected input_3 to have shape (34, )但得到形状为(36,)的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59226356/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com