def init_restore_or_wait_for_variables():
    """Initialize or restore variables or wait for variables to be initialized."""
    session = backend._get_session()  # pylint: disable=protected-access
    if not multi_worker_util.has_worker_context(
    ) or multi_worker_util.should_load_checkpoint():
        # TODO(yuefengz): if checkpoints exist, restore from checkpoint.
        backend._initialize_variables(session)  # pylint: disable=protected-access
    else:
        _wait_for_variable_initialization(session)
Exemplo n.º 2
0
 def _build(self, shape):
   self._shape = tf.TensorShape(shape)
   self._build_input_shape = self._shape
   # Create new state variables
   self._total = self.add_weight(
       name='total', shape=shape, initializer='zeros')
   self._count = self.add_weight(
       name='count', shape=shape, initializer='zeros')
   with tf.init_scope():
     if not tf.executing_eagerly():
       backend._initialize_variables(backend._get_session())  # pylint: disable=protected-access
   self._built = True
Exemplo n.º 3
0
 def _build(self, shape):
     self._shape = tf.TensorShape(shape)
     self._build_input_shape = self._shape
     # Create new state variables
     self._total = self.add_weight(
         name="total", shape=shape, initializer="zeros"
     )
     self._count = self.add_weight(
         name="count", shape=shape, initializer="zeros"
     )
     with tf.init_scope():
         if not tf.executing_eagerly():
             backend._initialize_variables(backend._get_session())
     self._built = True
Exemplo n.º 4
0
def init_restore_or_wait_for_variables():
    """Initialize or restore variables or wait for variables to be initialized."""
    backend._initialize_variables(backend._get_session())  # pylint: disable=protected-access
Exemplo n.º 5
0
def variable(value, dtype=_FLOATX, name=None):
    v = tf.Variable(np.asarray(value, dtype=dtype), name=name)
    K._get_session().run(v.initializer)
    return v
def init_restore_or_wait_for_variables():
    """Initialize or restore variables or wait for variables to be
    initialized."""
    backend._initialize_variables(backend._get_session())