MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / getvar

Method getvar

tensorflow/python/framework/function.py:761–801  ·  view source on GitHub ↗

A custom variable getter.

(
      self,
      getter,
      name,
      shape=None,
      dtype=None,
      initializer=None,
      reuse=None,
      trainable=True,
      collections=None,  # pylint: disable=redefined-outer-name
      use_resource=None,
      **kwargs)

Source from the content-addressed store, hash-verified

759 # pylint: enable=g-doc-return-or-yield
760
761 def getvar(
762 self,
763 getter,
764 name,
765 shape=None,
766 dtype=None,
767 initializer=None,
768 reuse=None,
769 trainable=True,
770 collections=None, # pylint: disable=redefined-outer-name
771 use_resource=None,
772 **kwargs):
773 """A custom variable getter."""
774 # Here, we switch the default graph to the outer graph and ask the
775 # variable scope in which the function is defined to give us the
776 # variable. The variable is stashed in extra_vars and returned to
777 # the caller.
778 #
779 # We capture these variables so that the variable definition is
780 # hoisted upward to the outer most graph.
781 with self._outer_graph.as_default():
782 # pylint: disable=protected-access
783 var = self._vscope.get_variable(
784 vs._get_default_variable_store(),
785 name,
786 shape=shape,
787 dtype=dtype,
788 initializer=initializer,
789 reuse=reuse,
790 trainable=trainable,
791 collections=collections,
792 use_resource=use_resource)
793 self.extra_vars.append(var)
794 if (isinstance(var, resource_variable_ops.BaseResourceVariable) and
795 self._capture_resource_var_by_value):
796 # For resource-based variables read the variable outside the function
797 # and pass in the value. This ensures that the function is pure and
798 # differentiable. TODO(apassos) this may have performance problems if
799 # the function will only do embedding lookups on the variable.
800 return var.value()
801 return var
802
803 def create_op(self, op_type, inputs, dtypes=None, **kwargs): # pylint: disable=redefined-outer-name
804 for i, x in enumerate(inputs):

Callers

nothing calls this directly

Calls 4

as_defaultMethod · 0.45
get_variableMethod · 0.45
appendMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected