class_docstr: Base class for next_frame models.
  
  This is the base class for the models that given the previous frames
  can predict the next frame. They may also support reward prediction
  and action condition prediction which enables them to be run as
  a world model in model-based RL pipeline.
  
  The API supports both recurrent and stacked frames models. Please look
  at the documents for next_frame function for the API.
  
  If you are implementing a next frame prediction model consider
  following the API presented in this class. But if the API
  is too limiting for your models, feel free to override lower level
  functions and/or inheret from T2TModel directly.
class_docstr_tok: ["Base","class","for","next_frame","models",".","This","is","the","base","class","for","the","models","that","given","the","previous","frames","can","predict","the","next","frame",".","They","may","also","support","reward","prediction","and","action","condition","prediction","which","enables","them","to","be","run","as","a","world","model","in","model-based","RL","pipeline",".","The","API","supports","both","recurrent","and","stacked","frames","models",".","Please","look","at","the","documents","for","next_frame","function","for","the","API",".","If","you","are","implementing","a","next","frame","prediction","model","consider","following","the","API","presented","in","this","class",".","But","if","the","API","is","too","limiting","for","your","models",",","feel","free","to","override","lower","level","functions","and\/or","inheret","from","T2TModel","directly","."]
docstr: Produce predictions from the model by running it.
docstr_tok: ["Produce","predictions","from","the","model","by","running","it","."]
code: def infer(
      self, features, *args, **kwargs
  ):  # pylint: disable=arguments-differ
      """Produce predictions from the model by running it."""
      del args, kwargs
      # Inputs and features preparation needed to handle edge cases.
      if not features:
          features = {}
      hparams = self.hparams
      inputs_old = None
      if "inputs" in features and len(features["inputs"].shape) < 4:
          inputs_old = features["inputs"]
          features["inputs"] = tf.expand_dims(features["inputs"], 2)
  
      def logits_to_samples(logits, key):
          """Get samples from logits."""
          # If the last dimension is 1 then we're using L1/L2 loss.
          if common_layers.shape_list(logits)[-1] == 1:
              return tf.to_int32(tf.squeeze(logits, axis=-1))
          if key == "targets":
              return pixels_from_softmax(
                  logits,
                  gumbel_noise_factor=0.0,
                  temperature=hparams.pixel_sampling_temperature,
              )
          # Argmax in TF doesn't handle more than 5 dimensions yet.
          logits_shape = common_layers.shape_list(logits)
          argmax = tf.argmax(
              tf.reshape(logits, [-1, logits_shape[-1]]), axis=-1
          )
          return tf.reshape(argmax, logits_shape[:-1])
  
      # Get predictions.
      try:
          num_channels = hparams.problem.num_channels
      except AttributeError:
          num_channels = 1
      if "inputs" in features:
          inputs_shape = common_layers.shape_list(features["inputs"])
          targets_shape = [
              inputs_shape[0],
              hparams.video_num_target_frames,
              inputs_shape[2],
              inputs_shape[3],
              num_channels,
          ]
      else:
          tf.logging.warn(
              "Guessing targets shape as no inputs are given."
          )
          targets_shape = [
              hparams.batch_size,
              hparams.video_num_target_frames,
              1,
              1,
              num_channels,
          ]
  
      features["targets"] = tf.zeros(targets_shape, dtype=tf.int32)
      reward_in_mod = "target_reward" in self.problem_hparams.modality
      action_in_mod = "target_action" in self.problem_hparams.modality
      if reward_in_mod:
          # TODO(lukaszkaiser): this is a hack. get the actual reward history.
          if "input_reward" not in features:
              features["input_reward"] = tf.zeros(
                  [inputs_shape[0], inputs_shape[1], 1], dtype=tf.int32
              )
          features["target_reward"] = tf.zeros(
              [targets_shape[0], targets_shape[1], 1], dtype=tf.int32
          )
      if action_in_mod and "target_action" not in features:
          features["target_action"] = tf.zeros(
              [targets_shape[0], targets_shape[1], 1], dtype=tf.int32
          )
      logits, _ = self(features)  # pylint: disable=not-callable
      if isinstance(logits, dict):
          results = {}
          for k, v in six.iteritems(logits):
              results[k] = logits_to_samples(v, k)
              results["%s_logits" % k] = v
          # HACK: bypassing decoding issues.
          results["outputs"] = results["targets"]
          results["scores"] = results["targets"]
      else:
          results = logits_to_samples(logits, "targets")
  
      # Restore inputs to not confuse Estimator in edge cases.
      if inputs_old is not None:
          features["inputs"] = inputs_old
  
      # Return results.
      return results
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import functools
  import six
  from tensor2tensor.layers import common_hparams
  from tensor2tensor.layers import common_layers
  from tensor2tensor.layers import common_video
  from tensor2tensor.layers import discretization
  from tensor2tensor.layers import modalities
  from tensor2tensor.utils import registry
  from tensor2tensor.utils import t2t_model
  import tensorflow.compat.v1
label_desc: Use image node_id 19 for calling the NextFrameBase obj's underlying member method code with example usage: obj.infer(features) and returns: results, tf, tf, pixels_from_softmax