【问题标题】:Can't make dynamic dimension in tensorflow variable无法在张量流变量中制作动态维度
【发布时间】:2018-03-04 11:47:45
【问题描述】:

我有以下代码:

a = tf.placeholder(dtype = tf.float64, shape = (10, None))
b = tf.Variable(tf.random_normal((20, 10), dtype = tf.float64), dtype = tf.float64)
c = tf.matmul(b, a)
d = tf.shape(a)[1]
e = tf.Variable(tf.random_normal((d, d), dtype = tf.float64), dtype = tf.float64)

我想在执行过程中设置e的维度。但我得到一个错误。不可能吗?

【问题讨论】:

    标签: python variables tensorflow initialization tensor


    【解决方案1】:

    不,这是不可能的。 Tensorflow 不允许在变量定义中使用 dynamic 形状,因为它不能在图形定义时分配任意大小的内存。所以e 的维度必须静态地知道。

    【讨论】:

    • 是否允许 tf.constant?
    • 同理。 tf.constant 需要静态知道
    猜你喜欢
    • 1970-01-01
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 2016-11-17
    • 1970-01-01
    • 1970-01-01
    • 2022-09-29
    • 2016-03-08
    相关资源
    最近更新 更多