message: Make Keras only initialize a variable after checking `tf.is_variable_initialized()`.
diff: @@ -373,7 +373,22 @@ def get_session():
  session = _SESSION
  if not _MANUAL_VAR_INIT:
  with session.graph.as_default():
  - _initialize_variables()
  + variables = variables_module.global_variables()
  + candidate_vars = []
  + for v in variables:
  + if not getattr(v, '_keras_initialized', False):
  + candidate_vars.append(v)
  + # This step is expensive, so we only run it on variables not already
  + # marked as initialized.
  + is_initialized = session.run(
  + [variables_module.is_variable_initialized(v) for v in candidate_vars])
  + uninitialized_vars = []
  + for flag, v in zip(is_initialized, candidate_vars):
  + if not flag:
  + uninitialized_vars.append(v)
  + v._keras_initialized = True
  + if uninitialized_vars:
  + session.run(variables_module.variables_initializer(uninitialized_vars))
  return session
  @@ -541,20 +556,6 @@ def variable(value, dtype=None, name=None, constraint=None):
  return v
  -def _initialize_variables():
  - """Utility to initialize uninitialized variables on the fly.
  - """
  - variables = variables_module.global_variables()
  - uninitialized_variables = []
  - for v in variables:
  - if not hasattr(v, '_keras_initialized') or not v._keras_initialized:
  - uninitialized_variables.append(v)
  - v._keras_initialized = True
  - if uninitialized_variables:
  - sess = get_session()
  - sess.run(variables_module.variables_initializer(uninitialized_variables))
  -
  -
  def constant(value, dtype=None, shape=None, name=None):
  """Creates a constant tensor.
  