class_docstr: Utils for testing next_frame_glow.
class_docstr_tok: ["Utils","for","testing","next_frame_glow","."]
docstr: Test 1 forward pass and sampling gives reasonable results.
docstr_tok: ["Test","1","forward","pass","and","sampling","gives","reasonable","results","."]
code: def GlowTrainAndDecode(
      self,
      in_frames=1,
      out_frames=1,
      latent_dist_encoder="pointwise",
      gen_mode="conditional",
      pretrain_steps=-1,
      num_train_frames=-1,
      cond_first_frame=False,
      apply_dilations=False,
      activation="relu",
  ):
      """Test 1 forward pass and sampling gives reasonable results."""
      if num_train_frames == -1:
          total_frames = in_frames + out_frames
      else:
          total_frames = num_train_frames
  
      curr_dir = tempfile.mkdtemp()
      model_path = os.path.join(curr_dir, "model")
  
      # Training pipeline
      with tf.Graph().as_default():
          hparams = next_frame_glow.next_frame_glow_hparams()
          hparams = fill_hparams(
              hparams,
              in_frames,
              out_frames,
              gen_mode,
              latent_dist_encoder,
              pretrain_steps,
              num_train_frames,
              cond_first_frame,
              apply_dilations,
              activation,
          )
          features = create_basic_features(hparams)
          model = next_frame_glow.NextFrameGlow(hparams, MODES.TRAIN)
          _, train_op = model(features)
          if self.should_run_session(hparams):
              self.RunModel(
                  model,
                  train_op,
                  hparams,
                  features,
                  total_frames,
                  model_path,
              )
  
      # Inference pipeline
      with tf.Graph().as_default():
          hparams = next_frame_glow.next_frame_glow_hparams()
          if hparams.gen_mode == "unconditional":
              hparams.video_num_target_frames = 1
          hparams = fill_hparams(
              hparams,
              in_frames,
              out_frames,
              gen_mode,
              latent_dist_encoder,
              pretrain_steps,
              num_train_frames,
              cond_first_frame,
              apply_dilations,
              activation,
          )
          features = create_basic_features(hparams)
          model = next_frame_glow.NextFrameGlow(
              hparams, tf_estimator.ModeKeys.PREDICT
          )
          predictions = model.infer(features)
          outputs = predictions["outputs"]
          model_path = os.path.join(curr_dir, "model")
  
          if self.should_run_session(hparams):
              with tf.Session() as session:
                  saver = tf.train.Saver()
                  saver.restore(session, model_path)
                  outputs_np = session.run(outputs)
                  self.assertEqual(
                      outputs_np.shape, (16, out_frames, 64, 64, 3)
                  )
                  self.assertTrue(np.all(outputs_np <= 255))
                  self.assertTrue(np.all(outputs_np >= 0))
  
file_path: tensor2tensor/tensor2tensor/models/video/nfg_test_utils.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os
  import tempfile
  import numpy
  from tensor2tensor.data_generators import video_generated
  from tensor2tensor.models.video import next_frame_glow
  from tensor2tensor.utils import registry
  import tensorflow.compat.v1
  from tensorflow.compat.v1 import estimator
label_desc: Use image node_id 4 for calling the NextFrameGlowTest obj's underlying member method code with example usage: obj.GlowTrainAndDecode(in_frames, out_frames, latent_dist_encoder, gen_mode, pretrain_steps, num_train_frames, cond_first_frame, apply_dilations, activation) without return types