コード例 #1
0
def init_restore_or_wait_for_variables():
    """Initialize or restore variables or wait for variables to be initialized."""
    session = K._get_session()  # pylint: disable=protected-access
    worker_context = dc_context.get_current_worker_context()
    if not worker_context or worker_context.should_init:
        # TODO(yuefengz): if checkpoints exit, restore from checkpoint.
        K._initialize_variables(session)  # pylint: disable=protected-access
    else:
        _wait_for_variable_initialization(session)
コード例 #2
0
def init_restore_or_wait_for_variables():
  """Initialize or restore variables or wait for variables to be initialized."""
  session = K._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.
    K._initialize_variables(session)  # pylint: disable=protected-access
  else:
    _wait_for_variable_initialization(session)
コード例 #3
0
def init_restore_or_wait_for_variables():
  """Initialize or restore variables or wait for variables to be initialized."""
  session = K._get_session()  # pylint: disable=protected-access
  worker_context = dc_context.get_current_worker_context()
  if not worker_context or worker_context.experimental_should_init:
    # TODO(yuefengz): if checkpoints exist, restore from checkpoint.
    K._initialize_variables(session)  # pylint: disable=protected-access
  else:
    _wait_for_variable_initialization(session)
コード例 #4
0
    def _build(self, shape):
        """Initialize TP, FP, TN, and FN tensors, given the shape of the data."""
        if self.multi_label:
            if shape.ndims != 2:
                raise ValueError(
                    '`y_true` must have rank=2 when `multi_label` is '
                    'True. Found rank %s.' % shape.ndims)
            variable_shape = tensor_shape.TensorShape(
                [tensor_shape.Dimension(self.num_thresholds), shape[1]])
        else:
            variable_shape = tensor_shape.TensorShape(
                [tensor_shape.Dimension(self.num_thresholds)])

        # Create metric variables
        self.true_positives = self.add_weight(
            'true_positives',
            shape=variable_shape,
            initializer=init_ops.zeros_initializer)
        self.true_negatives = self.add_weight(
            'true_negatives',
            shape=variable_shape,
            initializer=init_ops.zeros_initializer)
        self.false_positives = self.add_weight(
            'false_positives',
            shape=variable_shape,
            initializer=init_ops.zeros_initializer)
        self.false_negatives = self.add_weight(
            'false_negatives',
            shape=variable_shape,
            initializer=init_ops.zeros_initializer)

        if self.multi_label:
            with ops.init_scope():
                # This should only be necessary for handling v1 behavior. In v2, AUC
                # should be initialized outside of any tf.functions, and therefore in
                # eager mode.
                if not context.executing_eagerly():
                    K._initialize_variables(K._get_session())  # pylint: disable=protected-access

        self._built = True
コード例 #5
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
コード例 #6
0
def variable(value, dtype=_FLOATX, name=None):
    v = tf.Variable(np.asarray(value, dtype=dtype), name=name)
    _get_session().run(v.initializer)
    return v