How can i change this GPU code to CPU?

username: Anthony_Nelson
cooked: <p>parser = argparse.ArgumentParser(description=‘PSMNet’)<br>
parser.add_argument(’–KITTI’, default=‘2015’,<br>
help=‘KITTI version’)<br>
parser.add_argument(’–datapath’, default=’/scratch/datasets/kitti2015/testing/’,<br>
help=‘select model’)<br>
parser.add_argument(’–loadmodel’, default=None,<br>
help=‘loading model’)<br>
parser.add_argument(’–model’, default=‘stackhourglass’,<br>
help=‘select model’)<br>
parser.add_argument(’–maxdisp’, type=int, default=192,<br>
help=‘maxium disparity’)<br>
parser.add_argument(’–no-cuda’, action=‘store_true’, default=False,<br>
help=‘enables CUDA training’)<br>
parser.add_argument(’–seed’, type=int, default=1, metavar=‘S’,<br>
help=‘random seed (default: 1)’)<br>
parser.add_argument(’–save_path’, type=str, default=‘finetune_1000’, metavar=‘S’,<br>
help=‘path to save the predict’)<br>
parser.add_argument(’–save_figure’, action=‘store_true’, help=‘if true, save the numpy file, not the png file’)<br>
args = parser.parse_args()<br>
args.cuda = not args.no_cuda and torch.cuda.is_available()</p>
<p>torch.manual_seed(args.seed)<br>
if args.cuda:<br>
torch.cuda.manual_seed(args.seed)</p>
<p>if args.KITTI == ‘2015’:<br>
from dataloader import KITTI_submission_loader as DA<br>
else:<br>
from dataloader import KITTI_submission_loader2012 as DA</p>
<p>test_left_img, test_right_img = DA.dataloader(args.datapath)</p>
<p>if args.model == ‘stackhourglass’:<br>
model = stackhourglass(args.maxdisp)<br>
elif args.model == ‘basic’:<br>
model = basic(args.maxdisp)<br>
else:<br>
print(‘no model’)</p>
<p>model = nn.DataParallel(model, device_ids=[0])<br>
model.cuda()</p>
<p>if args.loadmodel is not None:<br>
state_dict = torch.load(args.loadmodel)<br>
model.load_state_dict(state_dict[‘state_dict’])</p>
<p>print(‘Number of model parameters: {}’.format(sum([p.data.nelement() for p in model.parameters()])))</p>
<p>def test(imgL,imgR):<br>
model.eval()</p>
<pre><code>    if args.cuda:
       imgL = torch.FloatTensor(imgL).cuda()
       imgR = torch.FloatTensor(imgR).cuda()     

    imgL, imgR= Variable(imgL), Variable(imgR)

    with torch.no_grad():
        output = model(imgL,imgR)
    output = torch.squeeze(output)
    pred_disp = output.data.cpu().numpy()

    return pred_disp
</code></pre>
<p>def main():<br>
processed = preprocess.get_transform(augment=False)<br>
if not os.path.isdir(args.save_path):<br>
os.makedirs(args.save_path)</p>
<p>for inx in range(len(test_left_img)):</p>
<pre><code>   imgL_o = (skimage.io.imread(test_left_img[inx]).astype('float32'))
   imgR_o = (skimage.io.imread(test_right_img[inx]).astype('float32'))
   imgL = processed(imgL_o).numpy()
   imgR = processed(imgR_o).numpy()
   imgL = np.reshape(imgL,[1,3,imgL.shape[1],imgL.shape[2]])
   imgR = np.reshape(imgR,[1,3,imgR.shape[1],imgR.shape[2]])

   # pad to (384, 1248)
   top_pad = 384-imgL.shape[2]
   left_pad = 1248-imgL.shape[3]
   imgL = np.lib.pad(imgL,((0,0),(0,0),(top_pad,0),(0,left_pad)),mode='constant',constant_values=0)
   imgR = np.lib.pad(imgR,((0,0),(0,0),(top_pad,0),(0,left_pad)),mode='constant',constant_values=0)

   start_time = time.time()
   pred_disp = test(imgL,imgR)
   print('time = %.2f' %(time.time() - start_time))

   top_pad   = 384-imgL_o.shape[0]
   left_pad  = 1248-imgL_o.shape[1]
   img = pred_disp[top_pad:,:-left_pad]
   print(test_left_img[inx].split('/')[-1])
   if args.save_figure:
       skimage.io.imsave(args.save_path+'/'+test_left_img[inx].split('/')[-1],(img*256).astype('uint16'))
   else:
       np.save(args.save_path+'/'+test_left_img[inx].split('/')[-1][:-4], img)
</code></pre>
<p>if <strong>name</strong> == ‘<strong>main</strong>’:<br>
main()</p>

username: Megh_Bhalerao
cooked: <p>Please format your code for better legibility using the options at the top of the textbox. Also, you can convert your code to CPU by removing the <code>cuda</code>(s) from your code.</p>