text: from __future__ import print_function
  import argparse
  import torch
  import torch.nn as nn
  import torch.optim as optim
  import torch.nn.functional as F
  from dataloader import listflowfile as lt
  from dataloader import SecenFlowLoader as DA
  from models import *
  import matplotlib.pyplot as plt
  
  torch.cuda.empty_cache()
  
  parser = argparse.ArgumentParser(description='PSMNet')
  parser.add_argument('--maxdisp', type=int ,default=192,
                      help='maxium disparity')
  parser.add_argument('--model', default='stackhourglass',
                      help='select model')
  parser.add_argument('--datapath', default='E:/dataset/test/',
                      help='datapath')
  parser.add_argument('--epochs', type=int, default=10,
                      help='number of epochs to train')
  parser.add_argument('--loadmodel', default= r'C:\Users\Dharshan\Desktop\PSMNet-master\pretrained_sceneflow.tar',
                      help='load model')
  parser.add_argument('--savemodel', default='./',
                      help='save model')
  parser.add_argument('--no-cuda', action='store_true', default=False,
                      help='enables CUDA training')
  parser.add_argument('--seed', type=int, default=1, metavar='S',
                      help='random seed (default: 1)')
  args = parser.parse_args()
  args.cuda = not args.no_cuda and torch.cuda.is_available()
  
  torch.manual_seed(args.seed)
  if args.cuda:
      torch.cuda.manual_seed(args.seed)
  
  ##Load the Scene FLow test image set. 
  all_left_img,all_right_img,all_left_disp,test_left_img, test_right_img, test_left_disp = lt.dataloader(args.datapath)
  
  
  TestImgLoader = torch.utils.data.DataLoader(
           DA.myImageFloder(test_left_img,test_right_img,test_left_disp, False), 
           batch_size=1, shuffle= False, num_workers= 0, drop_last=False)
  
  
  if args.model == 'stackhourglass':
      model = stackhourglass(args.maxdisp)
  elif args.model == 'basic':
      model = basic(args.maxdisp)
  else:
      print('no model')
  
  if args.cuda:
      model = nn.DataParallel(model)
      model.cuda()
  
  if args.loadmodel is not None:
      print('Load pretrained model')
      pretrain_dict = torch.load(args.loadmodel)
      model.load_state_dict(pretrain_dict['state_dict'])
  print(pretrain_dict['state_dict'])
  print('Number of model parameters: {}'.format(sum([p.data.nelement() for p in model.parameters()])))
  
  optimizer = optim.Adam(model.parameters(), lr=0.001, betas=(0.9, 0.999))
  
  def test(imgL,imgR,disp_true):
  
          model.eval()
    
          if args.cuda:
              imgL, imgR, disp_true = imgL.cuda(), imgR.cuda(), disp_true.cuda()
  
          mask = disp_true < 192
          
  
          if imgL.shape[2] % 16 != 0:
              times = imgL.shape[2]//16       
              top_pad = (times+1)*16 -imgL.shape[2]
          else:
              top_pad = 0
  
          if imgL.shape[3] % 16 != 0:
              times = imgL.shape[3]//16                       
              right_pad = (times+1)*16-imgL.shape[3]
          else:
              right_pad = 0  
  
          imgL = F.pad(imgL,(0,right_pad, top_pad,0))
          imgR = F.pad(imgR,(0,right_pad, top_pad,0))
  
          with torch.no_grad():
              output3 = model(imgL,imgR)
              output3 = torch.squeeze(output3,dim=1)
              
          
          if top_pad !=0:
              img = 1.15*output3[:,top_pad:,:]
          else:
              img = 1.15*output3
          
          
          if len(disp_true[mask])==0:
              loss = 0
          else:
              loss = F.l1_loss(img[mask],disp_true[mask]) #torch.mean(torch.abs(img[mask]-disp_true[mask]))  # end-point-error
  
          return loss.data.cpu()
  
  
  
  
  
  def main():
  
     
     total_test_loss = 0
     for batch_idx, (imgL, imgR, disp_L) in enumerate(TestImgLoader):
         test_loss = test(imgL,imgR, disp_L)
         print('Iter %d test loss = %.3f' %(batch_idx, test_loss))
         total_test_loss += test_loss
     print('total test loss = %.3f' %(total_test_loss/len(TestImgLoader)))
      
      
  if __name__ == '__main__':
     main()
      
  