class_docstr: Builds AdaNet candidates.
class_docstr_tok: ["Builds","AdaNet","candidates","."]
docstr: Builds and returns an AdaNet candidate.
  
  Args:
    ensemble_spec: `_EnsembleSpec` instance to track.
    training: A python boolean indicating whether the graph is in training
      mode or prediction mode.
    summary: A `Summary` for recording summaries for TensorBoard.
    rebuilding: Boolean whether the iteration is being rebuilt only to restore
      the previous best subnetworks and ensembles.
    track_moving_average: Bool whether to track the moving average of the
      ensemble's adanet loss.
  
  Returns:
    A _Candidate instance.
docstr_tok: ["Builds","and","returns","an","AdaNet","candidate",".","Args",":","ensemble_spec",":","`","_EnsembleSpec","`","instance","to","track",".","training",":","A","python","boolean","indicating","whether","the","graph","is","in","training","mode","or","prediction","mode",".","summary",":","A","`","Summary","`","for","recording","summaries","for","TensorBoard",".","rebuilding",":","Boolean","whether","the","iteration","is","being","rebuilt","only","to","restore","the","previous","best","subnetworks","and","ensembles",".","track_moving_average",":","Bool","whether","to","track","the","moving","average","of","the","ensemble","'s","adanet","loss",".","Returns",":","A","_Candidate","instance","."]
code: def build_candidate(
      self,
      ensemble_spec,
      training,
      summary,
      rebuilding=False,
      track_moving_average=True,
  ):
      """Builds and returns an AdaNet candidate.
  
      Args:
        ensemble_spec: `_EnsembleSpec` instance to track.
        training: A python boolean indicating whether the graph is in training
          mode or prediction mode.
        summary: A `Summary` for recording summaries for TensorBoard.
        rebuilding: Boolean whether the iteration is being rebuilt only to restore
          the previous best subnetworks and ensembles.
        track_moving_average: Bool whether to track the moving average of the
          ensemble's adanet loss.
  
      Returns:
        A _Candidate instance.
      """
  
      from tensorflow.python.training import (
          moving_averages,
      )  # pylint: disable=g-direct-tensorflow-import,g-import-not-at-top
  
      candidate_scope = "candidate_{}".format(ensemble_spec.name)
  
      with tf_compat.v1.variable_scope(candidate_scope):
          adanet_loss = ensemble_spec.adanet_loss
          variables = []
          if track_moving_average:
              loss_to_track = ensemble_spec.adanet_loss
              if loss_to_track is None:
                  # Dummy loss so that we always create moving averages variables.
                  # If we pass a None loss assign_moving_average raises an exception.
                  loss_to_track = tf.constant(
                      99999.0, name="dummy_adanet_loss"
                  )
  
              adanet_loss_var = tf_compat.v1.get_variable(
                  "adanet_loss", initializer=0.0, trainable=False
              )
              update_adanet_loss_op = (
                  moving_averages.assign_moving_average(
                      adanet_loss_var,
                      loss_to_track,
                      decay=self._adanet_loss_decay,
                  )
              )
              # Get the two moving average variables created by assign_moving_average.
              # Since these two variables are the most recently created ones, we can
              # slice them both from the end of the global variables collection.
              variables = [
                  adanet_loss_var
              ] + tf_compat.v1.global_variables()[-2:]
              if training and not rebuilding:
                  with tf.control_dependencies([update_adanet_loss_op]):
                      adanet_loss = adanet_loss_var.read_value()
              else:
                  adanet_loss = adanet_loss_var.read_value()
  
          with summary.current_scope():
              summary.scalar(
                  "adanet_loss/adanet/adanet_weighted_ensemble",
                  adanet_loss,
              )
  
          return _Candidate(
              ensemble_spec=ensemble_spec,
              adanet_loss=adanet_loss,
              variables=variables,
          )
  
file_path: adanet/adanet/core/candidate.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  from adanet import tf_compat
  import tensorflow.compat.v2
label_desc: Use image node_id 2 for calling the _CandidateBuilder obj's underlying member method code with example usage: obj.build_candidate(ensemble_spec, training, summary, rebuilding, track_moving_average) and returns: _Candidate