不知怎的,我的火车圈里没有梯度。下面是一个简单的例子。你知道吗
import tensorflow as tf
import tensorflow_probability as tfp
tf.enable_eager_execution()
hidden_size = 32
output_size = 1
m = tf.keras.Sequential(
[
tfp.layers.DenseLocalReparameterization(hidden_size, tf.nn.leaky_relu),
tfp.layers.DenseLocalReparameterization(hidden_size, tf.nn.leaky_relu),
tfp.layers.DenseLocalReparameterization(output_size)
]
)
如果我运行一个梯度记录步骤两次,第二次不会显示任何梯度。返回具有None
类型的列表。你知道吗
for _ in range(2):
with tf.GradientTape() as tape:
loss_value = m(tf.ones((1, 2))) * 2
print(tape.gradient(loss_value, m.trainable_variables))
如果我们用一个“标准”的张量流模型来代替模型m
,情况就不是这样了
m = tf.keras.Sequential([tf.keras.layers.Dense(1)])
我使用的是tensorflow=1.13.1和tensorflow概率=0.6.0
这似乎是一个暂时的错误。我上传到了tensorflow和tensorflow概率的夜间版本,问题就解决了。你知道吗
相关问题 更多 >
编程相关推荐