How can I copy a variable in tensorflow

前端 未结 4 965
清歌不尽
清歌不尽 2020-12-24 13:19

In numpy I can create a copy of the variable with numpy.copy. Is there a similar method, that I can use to create a copy of a Tensor in TensorFlow?

4条回答
  •  清歌不尽
    2020-12-24 14:11

    This performs a deep copy

    copied_variable = tf.Variable(source_variable.initialized_value())
    

    It also handles intialization properly, i.e.

    tf.intialize_all_variables()
    

    will properly initialize source_variable first and then copy that value to copied_variable

提交回复
热议问题