text: 
  import sys
  
  sys.path.append(".")
  sys.path.append("..")
  
  import os
  import numpy as np
  
  from torch.autograd import Variable
  from torchvision.utils import make_grid
  import torch
  import time
  import cv2
  from utils.shading import *
  
  def predict_lighting(filepath, lighting_network):
      img = cv2.imread(filepath)
      row, col, _ = img.shape
      img = cv2.resize(img, (1024, 1024))
      Lab = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
  
      inputL = Lab[:,:,0]
      inputL = inputL.astype(np.float32)/255.0
      inputL = inputL.transpose((0,1))
      inputL = inputL[None,None,...]
      inputL = Variable(torch.from_numpy(inputL).cuda())
  
      lightFolder = 'data/example_light/'
  
      sh = np.loadtxt(os.path.join(lightFolder, 'rotate_light_00.txt'))
      sh = sh[0:9]
      sh = sh * 0.7
  
      normal, valid = create_normal()
  
      # rendering half-sphere
      sh = np.squeeze(sh)
      shading = get_shading(normal, sh)
      value = np.percentile(shading, 95)
      ind = shading > value
      shading[ind] = value
      shading = (shading - np.min(shading))/(np.max(shading) - np.min(shading))
      shading = (shading *255.0).astype(np.uint8)
      shading = np.reshape(shading, (256, 256))
      shading = shading * valid
  
      #----------------------------------------------
      #  rendering images using the network
      #----------------------------------------------
      sh = np.reshape(sh, (1,9,1,1)).astype(np.float32)
      sh = Variable(torch.from_numpy(sh).cuda())
      outputImg, _, outputSH, _  = lighting_network(inputL, sh, 0)
      return outputSH.detach().cpu().numpy()
  
  def create_normal():
      # ---------------- create normal for rendering half sphere ------
      img_size = 256
      x = np.linspace(-1, 1, img_size)
      z = np.linspace(1, -1, img_size)
      x, z = np.meshgrid(x, z)
  
      mag = np.sqrt(x**2 + z**2)
      valid = mag <=1
      y = -np.sqrt(1 - (x*valid)**2 - (z*valid)**2)
      x = x * valid
      y = y * valid
      z = z * valid
      normal = np.concatenate((x[...,None], y[...,None], z[...,None]), axis=2)
      return np.reshape(normal, (-1, 3)), valid
      #-----------------------------------------------------------------