TensorFlow 中带有权重参数的层的输出
Output of a layer with weight argument in TensorFlow
TensorFlow 中是否有一种方法可以在指定权重的同时计算层的输出,例如 y = layer(x, weights=w)
?
最终目的是计算某些权重函数的梯度,$w \mapsto layer(x, weights = f(w))$
,但是自动微分似乎不适用于 layer.set_weights
。
要更新变量,您必须使用它们的 .assign
函数。有关详细信息,请参阅 https://www.tensorflow.org/api_docs/python/tf/Variable for more details. You can also most definitely pass weights to a layer. You would need to create custom later by subclassing tf.keras.layers.Layer
. See https://www.tensorflow.org/tutorials/customization/custom_layers。
TensorFlow 中是否有一种方法可以在指定权重的同时计算层的输出,例如 y = layer(x, weights=w)
?
最终目的是计算某些权重函数的梯度,$w \mapsto layer(x, weights = f(w))$
,但是自动微分似乎不适用于 layer.set_weights
。
要更新变量,您必须使用它们的 .assign
函数。有关详细信息,请参阅 https://www.tensorflow.org/api_docs/python/tf/Variable for more details. You can also most definitely pass weights to a layer. You would need to create custom later by subclassing tf.keras.layers.Layer
. See https://www.tensorflow.org/tutorials/customization/custom_layers。