text: #    Copyright 2020 Wen Ji & Kelei He (hkl@nju.edu.cn)
  #    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 cv2
  import numpy as np
  
  
  def str2bool(x):
      return x.lower() in ('true')
  
  
  def cam(x, size = 256):
      x = x - np.min(x)
      cam_img = x / np.max(x)
      cam_img = np.uint8(255 * cam_img)
      cam_img = cv2.resize(cam_img, (size, size))
      cam_img = cv2.applyColorMap(cam_img, cv2.COLORMAP_JET)
      return cam_img / 255.0
  
  
  def denorm(x):
      return x * 0.5 + 0.5
  
  
  def tensor2numpy(x):
      return x.detach().cpu().numpy().transpose(1,2,0)
  
  
  def RGB2BGR(x):
      return cv2.cvtColor(x, cv2.COLOR_RGB2BGR)