Tensorflow 2.5.0 - TypeError: An op outside of the function building code is being passed a "Graph" tensor
Tensorflow 2.5.0 - TypeError: An op outside of the function building code is being passed a "Graph" tensor
我正在训练一个使用 tfp.layers.Convolution3DFlipout
层的卷积贝叶斯神经网络。我的损失函数如下:
from tensorflow.keras.losses import binary_crossentropy
def variational_free_energy_loss(model, scale_factor = tf.constant(1.)):
kl = sum(model.losses) / scale_factor
def loss(y_true, y_pred):
bce = binary_crossentropy(y_true, y_pred)
return bce + kl
return loss
我收到这个错误:
TypeError: An op outside of the function building code is being passed
a "Graph" tensor. It is possible to have Graph tensors
leak out of the function building context by including a
tf.init_scope in your function building code.
For example, the following function will fail:
@tf.function
def has_init_scope():
my_constant = tf.constant(1.)
with tf.init_scope():
added = my_constant * 2
The graph tensor has name: conv3d_flipout_189/divergence_kernel:0
有谁知道导致此错误的原因吗?
张量流版本:2.5.0
tensorflow_probability版本:0.13.0
我正在训练一个使用 tfp.layers.Convolution3DFlipout
层的卷积贝叶斯神经网络。我的损失函数如下:
from tensorflow.keras.losses import binary_crossentropy
def variational_free_energy_loss(model, scale_factor = tf.constant(1.)):
kl = sum(model.losses) / scale_factor
def loss(y_true, y_pred):
bce = binary_crossentropy(y_true, y_pred)
return bce + kl
return loss
我收到这个错误:
TypeError: An op outside of the function building code is being passed
a "Graph" tensor. It is possible to have Graph tensors
leak out of the function building context by including a
tf.init_scope in your function building code.
For example, the following function will fail:
@tf.function
def has_init_scope():
my_constant = tf.constant(1.)
with tf.init_scope():
added = my_constant * 2
The graph tensor has name: conv3d_flipout_189/divergence_kernel:0
有谁知道导致此错误的原因吗?
张量流版本:2.5.0
tensorflow_probability版本:0.13.0