【问题标题】:Creating a placeholder having a shape that is a function of another shape创建一个占位符,其形状是另一个形状的函数
【发布时间】:2019-02-08 01:46:02
【问题描述】:

假设我们有一个tensorflow占位符如下:

x = tf.placeholder(tf.float32, (2, 2, 3 ..., 1))

我想创建另一个张量y,其形状与x 相同,除了第一和第二维是x 的三倍。

y = tf.placeholder(tf.float32, (6, 6, 3, ..., 1))

x 的形状不是预定义的,所以我想要做的是这样的:

y = tf.placeholder(tf.float32, (x.shape[0]* 3, x.shape[1] * 3, remaining_are_the_same_as_x_shape))

你能建议我如何在 tensorflow 中做到这一点吗?

【问题讨论】:

    标签: python tensorflow placeholder


    【解决方案1】:

    这个呢?

    x = tf.placeholder(tf.float32, (2, 2, 3 , 1))
    
    shape = x.get_shape().as_list()
    shape[0] = shape[0] * 3
    shape[1] = shape[1] * 3
    
    y = tf.placeholder(tf.float32, shape=shape)
    shape = y.get_shape().as_list()
    print(shape)
    

    [6, 6, 3, 1]

    【讨论】:

      猜你喜欢
      • 2013-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-27
      • 2016-01-20
      • 1970-01-01
      • 2015-06-29
      • 1970-01-01
      相关资源
      最近更新 更多