text: # Copyright 2022 Huawei Technologies Co., Ltd
  
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  
  # http://www.apache.org/licenses/LICENSE-2.0
  
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  
  import numpy as np
  
  def batch_mae_frame_float(gen_frames, gt_frames):
      # [batch, width, height]
      x = np.float32(gen_frames)
      y = np.float32(gt_frames)
      mae = np.sum(np.absolute(x - y), axis=(1, 2), dtype=np.float32)
      return np.mean(mae)
  
  def batch_psnr(gen_frames, gt_frames):
      # [batch, width, height]
      x = np.int32(gen_frames)
      y = np.int32(gt_frames)
      num_pixels = float(np.size(gen_frames[0]))
      mse = np.sum((x - y)**2, axis=(1, 2), dtype=np.float32) / num_pixels
      psnr = 20 * np.log10(255) - 10 * np.log10(mse)
      return np.mean(psnr)
  