1.一般论文都是有github连接的
2.如何阅读github
1.文章运行所需环境
2.训练和评估过程,翻译一下这里,简单看看
1.首先遇到的就是 import argparse 这个库带来的问题
parser = argparse.ArgumentParser(description='PSMNet')
parser.add_argument('--KITTI', default='2015',
help='KITTI version')
parser.add_argument('--datapath', default='/media/jiaren/ImageNet/data_scene_flow_2015/testing/',
help='select model')
parser.add_argument('--loadmodel', default='./trained/pretrained_model_KITTI2015.tar',
help='loading model')
parser.add_argument('--leftimg', default= './VO04_L.png',
help='load model')
parser.add_argument('--rightimg', default= './VO04_R.png',
help='load model')
parser.add_argument('--model', default='stackhourglass',
help='select model')
parser.add_argument('--maxdisp', type=int, default=192,
help='maxium disparity')
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()
2.下载KITTI2015数据集
KITTI2015
if args.cuda:
torch.cuda.manual_seed(args.seed)
if args.model == 'stackhourglass':
model = stackhourglass(args.maxdisp)
elif args.model == 'basic':
model = basic(args.maxdisp)
else:
print('no model')
*将模型放在GPU中
model = nn.DataParallel(model, device_ids=[0])
model.cuda()
3.加载预训练模型
if args.loadmodel is not None:
print('load PSMNet')
state_dict = torch.load(args.loadmodel)
model.load_state_dict(state_dict['state_dict'])
def test(imgL,imgR):
*模型为预测模式
model.eval()
*将数据放入GPU中
if args.cuda:
imgL = imgL.cuda()
imgR = imgR.cuda()
*由于是测试,我们使用了预训练模型,不需要反向传播
with torch.no_grad():
disp = model(imgL,imgR)
disp = torch.squeeze(disp)
pred_disp = disp.data.cpu().numpy()
return pred_disp
def main():
*图像预处理部分
normal_mean_var = {'mean': [0.485, 0.456, 0.406],
'std': [0.229, 0.224, 0.225]}
infer_transform = transforms.Compose([transforms.ToTensor(),
transforms.Normalize(**normal_mean_var)])
imgL_o = Image.open(args.leftimg).convert('RGB')
imgR_o = Image.open(args.rightimg).convert('RGB')
imgL = infer_transform(imgL_o)
imgR = infer_transform(imgR_o)
# pad to width and hight to 16 times
if imgL.shape[1] % 16 != 0:
times = imgL.shape[1]//16
top_pad = (times+1)*16 -imgL.shape[1]
else:
top_pad = 0
if imgL.shape[2] % 16 != 0:
times = imgL.shape[2]//16
right_pad = (times+1)*16-imgL.shape[2]
else:
right_pad = 0
imgL = F.pad(imgL,(0,right_pad, top_pad,0)).unsqueeze(0)
imgR = F.pad(imgR,(0,right_pad, top_pad,0)).unsqueeze(0)
*测试部分
start_time = time.time()
pred_disp = test(imgL,imgR)
print('time = %.2f' %(time.time() - start_time))
if top_pad !=0 or right_pad != 0:
img = pred_disp[top_pad:,:-right_pad]
else:
img = pred_disp
img = (img*256).astype('uint16')
img = Image.fromarray(img)
img.save('Test_disparity.png')
parser.add_argument('--leftimg', default= './VO04_L.png',
help='load model')
parser.add_argument('--rightimg', default= './VO04_R.png',
help='load model')
unindent does not match any outer indentation level
local variable xxx referenced before assignment
RuntimeError: CUDA out of memory. Tried to allocate 352.00 MiB (GPU 0; 7.80 GiB total capacity; 6.45
nvidia-smi
Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 984 G /usr/lib/xorg/Xorg 35MiB |
| 0 1567 G /usr/lib/xorg/Xorg 114MiB |
| 0 1700 G /usr/bin/gnome-shell 192MiB |
| 0 337434 G /usr/lib/xorg/Xorg 35MiB |
| 0 744440 G /usr/lib/firefox/firefox 2MiB |
| 0 744477 G /usr/lib/firefox/firefox 2MiB |
| 0 747520 G /home/yht/anaconda3/bin/python 2MiB |
| 0 747595 C /home/yht/anaconda3/bin/python 4515MiB |
| 0 767429 G /usr/lib/firefox/firefox 2MiB |
| 0 776208 G /usr/lib/firefox/firefox 2MiB |
| 0 776395 G /usr/lib/firefox/firefox 2MiB |
+-----------------------------------------------------------------------------+
-如果训练或测试停止,就关掉他
通过PID关闭进程,比如:
kill -9 747595