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

Method _init_from_proto

tensorflow/python/ops/variables.py:2087–2130  ·  view source on GitHub ↗

Recreates the Variable object from a `VariableDef` protocol buffer. Args: variable_def: `VariableDef` protocol buffer, describing a variable whose nodes already exists in the graph. import_scope: Optional `string`. Name scope to add.

(self, variable_def, import_scope=None)

Source from the content-addressed store, hash-verified

2085 self._constraint = constraint
2086
2087 def _init_from_proto(self, variable_def, import_scope=None):
2088 """Recreates the Variable object from a `VariableDef` protocol buffer.
2089
2090 Args:
2091 variable_def: `VariableDef` protocol buffer, describing a variable whose
2092 nodes already exists in the graph.
2093 import_scope: Optional `string`. Name scope to add.
2094 """
2095 assert isinstance(variable_def, variable_pb2.VariableDef)
2096 # Create from variable_def.
2097 g = ops.get_default_graph()
2098 self._variable = g.as_graph_element(
2099 ops.prepend_name_scope(
2100 variable_def.variable_name, import_scope=import_scope))
2101 self._initializer_op = g.as_graph_element(
2102 ops.prepend_name_scope(
2103 variable_def.initializer_name, import_scope=import_scope))
2104 # Tests whether initial_value_name exists first for backwards compatibility.
2105 if (hasattr(variable_def, "initial_value_name") and
2106 variable_def.initial_value_name):
2107 self._initial_value = g.as_graph_element(
2108 ops.prepend_name_scope(
2109 variable_def.initial_value_name, import_scope=import_scope))
2110 else:
2111 self._initial_value = None
2112 synchronization, aggregation, trainable = (
2113 validate_synchronization_aggregation_trainable(
2114 variable_def.synchronization, variable_def.aggregation,
2115 variable_def.trainable, variable_def.variable_name))
2116 self._synchronization = synchronization
2117 self._aggregation = aggregation
2118 self._trainable = trainable
2119 self._snapshot = g.as_graph_element(
2120 ops.prepend_name_scope(
2121 variable_def.snapshot_name, import_scope=import_scope))
2122 if variable_def.HasField("save_slice_info_def"):
2123 self._save_slice_info = Variable.SaveSliceInfo(
2124 save_slice_info_def=variable_def.save_slice_info_def,
2125 import_scope=import_scope)
2126 else:
2127 self._save_slice_info = None
2128 self._caching_device = None
2129 self._constraint = None
2130 self._is_sparse=False
2131
2132 def _as_graph_element(self):
2133 """Conversion function for Graph.as_graph_element()."""

Callers 1

__init__Method · 0.95

Tested by

no test coverage detected