Esempio n. 1
0
def is_var(node):
    if not is_tensor(node):
        return False
    if node.op.type.startswith('Variable'):
        return True
    if ((resource_variable_ops.is_resource_variable(node)
         or utils.is_reference_variable(node))):
        return True
    if node.dtype == tf.resource and node.op.type == 'VarHandleOp':
        return True
    return False
Esempio n. 2
0
 def var_to_tensors(var):
     if resource_variable_ops.is_resource_variable(var):
         if tf.control_flow_v2_enabled():
             # TODO(b/143690035): Note that the "captures" property relies on an
             # API which might change.
             captures = layer_collection.graph.captures
             return [h for vh, h in captures if vh is var.handle]
         else:
             return [var.handle]
     if utils.is_reference_variable(var):
         return [tf_ops.internal_convert_to_tensor(var, as_ref=True)]
     raise ValueError('%s is not a recognized variable type.' % str(var))
Esempio n. 3
0
def is_var(node):
  if not is_tensor(node):
    return False
  if node.op.type.startswith('Variable'):
    return True
  if ((resource_variable_ops.is_resource_variable(node) or
       utils.is_reference_variable(node))):
    return True
  # TODO(b/143690035): Note that the Placeholder type handles the Control Flow
  # V2 case, but this could stop working in the future if the implementation of
  # Control Flow V2 changes.
  if node.dtype == tf.resource and (node.op.type == 'VarHandleOp'
                                    or node.op.type == 'Placeholder'):
    return True
  return False
Esempio n. 4
0
 def var_to_tensor(var):
     if resource_variable_ops.is_resource_variable(var):
         return var.handle
     if utils.is_reference_variable(var):
         return tf_ops.internal_convert_to_tensor(var, as_ref=True)
     raise ValueError('%s is not a recognized variable type.' % str(var))