在以下代码段中,即使初始值和 expected_shape
不匹配,代码也会运行并给出输出 1.0
。这是代码。
import tensorflow as tf
import numpy as np
X = tf.placeholder(dtype=tf.float32)
y = tf.placeholder(dtype=tf.float32)
W = tf.Variable(0.0, expected_shape=(3,1))
b = tf.Variable(1.0)
sess = tf.Session()
init = tf.global_variables_initializer()
sess.run(init)
print(sess.run(tf.add(W,b)))
不是应该抛出错误吗?
最佳答案
目前,建议使用tf.get_variable并尽可能避免使用 tf.Variable。
现在,如果您查看 source code,那么为什么 expected_shape
没有任何效果? ,它被提及是因为它已被弃用并被忽略。如果您进一步查看 _init_from_args
函数,就会发现 expected_shape
参数完全被忽略,并且该值不会用于进一步处理。
关于python - Expected_shape 变量在 tensorflow 中没有任何影响,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47531328/