gpt4 book ai didi

python - 如何在使用 tf.tile 时重现错误 'InvalidArgumentError : expected multiples argument to be a vector of length 2 but got length 3'

转载 作者:行者123 更新时间:2023-12-05 07:41:17 26 4
gpt4 key购买 nike

我用 tf.tile 实现了一些代码并得到了这个错误消息:

InvalidArgumentError : expected multiples argument to be a vector of length 2 but got length 3

代码比较复杂,无法直接找出错误原因。所以我做了一些伪代码来重现错误,这样我就可以理解哪个值是错误的来源。但是,我不知道如何使用伪代码重现此错误。

我试着这样做:

import tensorflow as tf
a = tf.constant([[1,2,3],[2,3,4]])
b = tf.tile(a, [1,1,3])

这给了我错误信息:

Shape must be rank 2 but is rank 3 for 'Tile_0' with input shapes:~~

谁能提供一些示例代码来重现我原来的错误?

最佳答案

四年后,我怀疑直接解决方案不会有用,所以这里是对同时查看此内容的其他 2,000 人的一般解释!

来自 the documentation :

This operation creates a new tensor by replicating input multiples times. The output tensor's i'th dimension has input.dims(i) * multiples[i] elements, and the values of input are replicated multiples[i] times along the 'i'th dimension. For example, tiling [a b c d] by [2] produces [a b c d a b c d].

您的a 向量是一个 2 阶张量,因此 tf.tiles 期望倍数有 2 个元素,但您的倍数 有 3 个元素。您必须将 a 的维度与 multiples 的长度相匹配。

关于python - 如何在使用 tf.tile 时重现错误 'InvalidArgumentError : expected multiples argument to be a vector of length 2 but got length 3',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45450009/

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