from tensorflow.python.framework import ops

    with ops.name_scope(name) as scope:
      with ops.device(v.device or ops.get_default_graph().get_default_device()):
        if callable(init):
          assert v.get_shape().is_fully_defined(), "Variable shape unknown."
          # TODO(mrry): Convert to v.shape when the property and
          # accessor are reconciled (and all initializers support
          # tf.TensorShape objects).
          value = init(v.get_shape().as_list(), v.dtype.base_dtype)
          value = ops.convert_to_tensor(value, name="value")
          return assign(v, value, name=scope)
        else:
          init = ops.convert_to_tensor(init, name="init")
          return assign(v, init, name=scope)


@ops.RegisterShape("Assign")
