code: def test_last_layer_fn(self):
      head = tf.contrib.estimator.regression_head(
          loss_reduction=tf.losses.Reduction.SUM_OVER_BATCH_SIZE
      )
      optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.01)
      feature_columns = [
          tf.feature_column.numeric_column("input_1", shape=[2])
      ]
      cand_pool = [
          tf.estimator.DNNEstimator(
              head=head,
              feature_columns=feature_columns,
              optimizer=optimizer,
              hidden_units=[3],
          )
      ]
      input_features = {}
      features = {"input_1": [[1.0, 0.0]]}
      labels = [[1.0]]
      for key, feature in features.items():
          input_features[key] = tf.constant(feature, name=key)
      input_labels = tf.constant(labels, name="labels")
  
      class _FakeSummary(object):
          """A fake adanet.Summary."""
  
          def scalar(self, name, tensor, family=None):
              del name, tensor, family
              return "fake_scalar"
  
          @contextlib.contextmanager
          def current_scope(self):
              yield
  
      def _adanet_last_layer_fn(estimator_spec):
          del estimator_spec
          return input_labels
  
      # Call with custom last_layer_fn which simply returns the labels tensor.
      generator = _GeneratorFromCandidatePool(
          cand_pool, logits_fn=None, last_layer_fn=_adanet_last_layer_fn
      )
      candidates = generator.generate_candidates(
          previous_ensemble=None,
          iteration_number=None,
          previous_ensemble_reports=None,
          all_reports=None,
          config=tf.estimator.RunConfig(),
      )
      subnetwork = candidates[0].build_subnetwork(
          input_features,
          input_labels,
          None,
          False,
          1,
          _FakeSummary(),
          None,
      )
  
      self.assertEqual(input_labels, subnetwork.last_layer)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import contextlib
  import os
  import shutil
  import sys
  from absl import flags
  from absl import logging
  from absl.testing import parameterized
  from adanet import tf_compat
  from adanet.autoensemble.common import AutoEnsembleSubestimator
  from adanet.autoensemble.estimator import _GeneratorFromCandidatePool
  from adanet.autoensemble.estimator import AutoEnsembleEstimator
  import tensorflow.compat.v1
  from tensorflow.python.estimator.export import export
label_desc: Use image node_id 4 for calling the AutoEnsembleEstimatorTest obj's underlying member method code with example usage: obj.test_last_layer_fn() and returns: input_labels, str