title: How to copy a graph operation in Tensorflow using node_def?
body: <p>Lets say I have an operation <code>my_op</code> defined as follows:</p>
  
  <pre><code>name: "Const"
  op: "Const"
  attr {
    key: "dtype"
    value {
      type: DT_INT32
    }
  }
  attr {
    key: "value"
    value {
      tensor {
        dtype: DT_INT32
        tensor_shape {
          dim {
            size: 2
          }
        }
        tensor_content: "\001\000\000\000\001\000\000\000"
      }
    }
  }
  </code></pre>
  
  <p>I have access to operation in the graph but not to the construction code. I want to copy operation and change some of it's attributes:</p>
  
  <pre><code>name: "PrettyConst"
  op: "Const"
  attr {
    key: "dtype"
    value {
      type: DT_INT32
    }
  }
  attr {
    key: "value"
    value {
      tensor {
        dtype: DT_FLOAT32
        tensor_shape {
          dim {
            size: 8
          }
        }
        tensor_content: "\001\000\000\000\001\000\000\000\001\000\000\000\001\000\000\000\001\000\000\000\001\000\000\000\001\000\000\000\001\000\000\000"
      }
    }
  }
  </code></pre>
  
  <p>While I can easily do it by saving graph as txt, modifying content of the file, and restoring it back, I can not find a simple way of doing that in python. I would expect there should be possible to do something like following:</p>
  
  <pre><code>op_def_copy = op.node_def.copy()
  op_def_copy.name = "PrettyConst"
  op_def_copy.attr["dtype"] = 0
  # and also do something with the content, whatever
  graph.append(tf.Operation(op_def_copy))
  </code></pre>
  
  <p>The <code>tf.contrig.graph_editor</code> seems to be able to do that sort of thing, though.</p>