code: def testVariablePredictionLengths(self):
      # Check that we can handle cases where the model produces predictions of
      # different lengths for different examples.
      temp_eval_export_dir = self._getEvalExportDir()
      (
          _,
          eval_export_dir,
      ) = fixed_prediction_classifier.simple_fixed_prediction_classifier(
          None, temp_eval_export_dir
      )
  
      eval_saved_model = load.EvalSavedModel(eval_export_dir)
      (
          _,
          prediction_dict,
          _,
      ) = eval_saved_model.get_features_predictions_labels_dicts()
      with eval_saved_model.graph_as_default():
          eval_saved_model.register_additional_metric_ops(
              {
                  "total_non_trivial_classes": metrics.total(
                      tf.reduce_sum(
                          input_tensor=tf.cast(
                              tf.logical_and(
                                  tf.not_equal(
                                      prediction_dict["classes"], "?"
                                  ),
                                  tf.not_equal(
                                      prediction_dict["classes"], ""
                                  ),
                              ),
                              tf.int32,
                          )
                      )
                  ),
                  "example_count": metrics.total(
                      tf.shape(input=prediction_dict["classes"])[0]
                  ),
                  "total_score": metrics.total(
                      prediction_dict["probabilities"]
                  ),
              }
          )
  
      example1 = self._makeExample(classes=["apple"], scores=[100.0])
      example2 = self._makeExample()
      example3 = self._makeExample(
          classes=["durian", "elderberry", "fig", "grape"],
          scores=[300.0, 301.0, 302.0, 303.0],
      )
      example4 = self._makeExample(
          classes=["banana", "cherry"], scores=[400.0, 401.0]
      )
  
      fpl_list1 = self.predict_injective_example_list(
          eval_saved_model,
          [
              example1.SerializeToString(),
              example2.SerializeToString(),
          ],
      )
      fpl_list2 = self.predict_injective_example_list(
          eval_saved_model,
          [
              example3.SerializeToString(),
              example4.SerializeToString(),
          ],
      )
  
      # Note that the '?' and 0 default values come from the model.
      self.assertAllEqual(
          np.array([[b"apple"]]),
          fpl_list1[0].predictions["classes"][encoding.NODE_SUFFIX],
      )
      self.assertAllEqual(
          np.array([[100]]),
          fpl_list1[0].predictions["probabilities"][
              encoding.NODE_SUFFIX
          ],
      )
      self.assertAllEqual(
          np.array([[b"?"]]),
          fpl_list1[1].predictions["classes"][encoding.NODE_SUFFIX],
      )
      self.assertAllEqual(
          np.array([[0]]),
          fpl_list1[1].predictions["probabilities"][
              encoding.NODE_SUFFIX
          ],
      )
  
      self.assertAllEqual(
          np.array([[b"durian", b"elderberry", b"fig", b"grape"]]),
          fpl_list2[0].predictions["classes"][encoding.NODE_SUFFIX],
      )
      self.assertAllEqual(
          np.array([[300, 301, 302, 303]]),
          fpl_list2[0].predictions["probabilities"][
              encoding.NODE_SUFFIX
          ],
      )
      self.assertAllEqual(
          np.array([[b"banana", b"cherry", b"?", b"?"]]),
          fpl_list2[1].predictions["classes"][encoding.NODE_SUFFIX],
      )
      self.assertAllEqual(
          np.array([[400, 401, 0, 0]]),
          fpl_list2[1].predictions["probabilities"][
              encoding.NODE_SUFFIX
          ],
      )
  
      eval_saved_model.metrics_reset_update_get_list(
          [
              example1.SerializeToString(),
              example2.SerializeToString(),
              example3.SerializeToString(),
              example4.SerializeToString(),
          ]
      )
      metric_values = eval_saved_model.get_metric_values()
  
      self.assertDictElementsAlmostEqual(
          metric_values,
          {
              "total_non_trivial_classes": 7.0,
              "example_count": 4.0,
              "total_score": 2107.0,
          },
      )
  
imports: import os
  import numpy
  import tensorflow
  from tensorflow_model_analysis.eval_saved_model import encoding
  from tensorflow_model_analysis.eval_saved_model import load
  from tensorflow_model_analysis.eval_saved_model import testutil
  from tensorflow_model_analysis.eval_saved_model.example_trainers import control_dependency_estimator
  from tensorflow_model_analysis.eval_saved_model.example_trainers import csv_linear_classifier
  from tensorflow_model_analysis.eval_saved_model.example_trainers import custom_estimator
  from tensorflow_model_analysis.eval_saved_model.example_trainers import dnn_classifier
  from tensorflow_model_analysis.eval_saved_model.example_trainers import fake_multi_examples_per_input_estimator
  from tensorflow_model_analysis.eval_saved_model.example_trainers import fake_sequence_to_prediction
  from tensorflow_model_analysis.eval_saved_model.example_trainers import fixed_prediction_classifier
  from tensorflow_model_analysis.eval_saved_model.example_trainers import fixed_prediction_estimator
  from tensorflow_model_analysis.eval_saved_model.example_trainers import fixed_prediction_estimator_no_labels
  from tensorflow_model_analysis.eval_saved_model.example_trainers import linear_classifier
  from tensorflow_model_analysis.eval_saved_model.example_trainers import linear_classifier_multivalent
  from tensorflow_model_analysis.eval_saved_model.example_trainers import multi_head
  from tensorflow_model_analysis.post_export_metrics import metrics
  from tensorflow.core.example import example_pb2
label_desc: Use image node_id 17 for calling the IntegrationTest obj's underlying member method code with example usage: obj.testVariablePredictionLengths() without return types