python - get_variable 的自定义初始值设定项

标签 python tensorflow

如何将自定义初始化程序指定为 tf.get_variable() 的第三个参数?具体来说,我有一个变量 y,我想使用另一个(已经初始化的)变量 x 对其进行初始化。

使用 tf.Variable() 很容易做到这一点,只需说,y = tf.Variable(x.initialized_value())。但是我在 tf.get_variable() 的文档中找不到类似的东西。

最佳答案

您也可以使用 x.initialized_value()。例如:

import tensorflow as tf

x = tf.Variable(1.0)
y = tf.get_variable('y', initializer=x.initialized_value())

with tf.Session() as sess:
    sess.run(tf.initialize_all_variables())
    print(sess.run(y)) # prints 1.0

关于python - get_variable 的自定义初始值设定项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39211332/

相关文章:

python - MacOS 上的 python Datatable view() 的列名称模糊或不可见

python - Pandas :计算时间范围内的平均值

python - 有没有办法在 tf.keras 中保存指定时期的模型?

image - 如何根据某个类计算图像的梯度?

python - 在 Python 中将列表转换为字符串

python - 确保不可调用的 Python 类不被调用是否值得?

python - 使用 django-import-export 流式传输响应

python - 操纵神经网络的输出

python - Tensorflow 更改输出图像大小以不同于训练输入大小

python - tensor.numpy() 在 tensorflow.data.Dataset 中不起作用。抛出错误 : AttributeError: 'Tensor' object has no attribute 'numpy'