无法在张量流变量中创建动态维度
Can't make dynamic dimension in tensorflow variable
我有以下代码:
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
的维度。但是我得到一个错误。不可能吗?
不,这不可能。 Tensorflow 不允许在变量定义中使用 dynamic 形状,因为它无法在图定义期间分配任意大小的内存。所以e
的维度必须静态。
我有以下代码:
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
的维度。但是我得到一个错误。不可能吗?
不,这不可能。 Tensorflow 不允许在变量定义中使用 dynamic 形状,因为它无法在图定义期间分配任意大小的内存。所以e
的维度必须静态。