首页 文章

迭代Tensor流占位符

提问于
浏览
1

docArray 是用于构建张量流图的占位符 . 图表已正确构建,但在会话中使用feed_dict提供数据时,可变动长度不会动态调整 . 以下是代码段 .

lContext = tf.zeros((100,1), dtype=tf.float64)
rContext = tf.zeros((100,1), dtype=tf.float64)
for i in range(1, docArray.shape[1].valu):
    j = docArrayShape - 1 - i
    lContext = tf.concat([lContext,somefun1()], 1)
    rContext = tf.concat([somefun2(), rContext], 1)       
X = tf.concat([lContext, docArray, rContext], axis= 0)

当此代码用作正向传递时,docArray初始化为docArray = tf.placeholder时会出现错误(tf.float64,[100,None])

如果我用随机形状随机初始化docArray,同时提供形状(100 x N)的实时docArray数据,其中N是文档中的单词数,在连接时训练时会出现错误,因为lContext和docArray将是形状各异 .

样本文档的大小不固定 .

在此先感谢您的帮助 .

1 回答

  • 0

    由于在连接期间没有提到变量的大小,因此很难估计出错的位置 . 但总的来说,为了进行连接,正在进行连接的张量应该在所有轴上具有相同的尺寸,除了正在进行连接的轴之外 .

    例如,

    不允许:(不同 dtype

    x = tf.placeholder(tf.float32, (100, None))
    y = tf.placeholder(tf.float64, (100, None))
    z = tf.concat((x,y), axis = 0)
    

    不允许:(形状为100和200不匹配)

    x = tf.placeholder(tf.float32, (100, None))
    y = tf.placeholder(tf.float32, (200, None))
    z = tf.concat((x,y), axis = 1)
    

    允许:(相同 dtype 和轴匹配)

    x = tf.placeholder(tf.float32, (100, 300))
    y = tf.placeholder(tf.float32, (200, 300))
    z = tf.concat((x,y), axis = 0)
    

    在上面的示例中,如果像其他示例一样使用 None ,它将进行编译,但在运行时, None 必须表示相同的形状 .

相关问题