PSMNet代码的一些理解

作为入坑进深度学习的小白,第一篇复现的论文是《Pyramid Stereo Matching Network》,代码已经由作者开源,链接:https://github.com/JiaRenChang/PSMNet
代码大致读懂,将一些代码po出,做简单注释。代码 、注释、下面的备注要结合看哦。代码只针对KITTI2015,其他训练集没有用到。

数据预处理

讲一下KITT2015的预处理部分。
dataloader/KITTIloader2015.py

class myImageFloder(data.Dataset):
    def __init__(self, left, right, left_disparity, training, loader=default_loader, dploader= disparity_loader):
        self.left = left
        self.right = right

        self.disp_L = left_disparity
        self.loader = loader
        self.dploader = dploader
        self.training = training

    def __getitem__(self, index):
        left  = self.left[index]
        right = self.right[index]
        disp_L= self.disp_L[index]

        left_img = self.loader(left)
        right_img = self.loader(right)
        dataL = self.dploader(disp_L)


        if self.training:

           w, h = left_img.size
           th, tw = 256, 512
 
           x1 = random.randint(0, w - tw)
           y1 = random.randint(0, h - th)

           left_img = left_img.crop((x1, y1, x1 + tw, y1 + th))

           right_img = right_img.crop((x1, y1, x1 + tw, y1 + th))
           left_img = np.array(left_img, dtype=np.uint8)
           right_img = np.array(right_img, dtype=np.uint8)

           dataL = np.ascontiguousarray(dataL,dtype=np.float32)/256
           dataL = dataL[y1:y1 + th, x1:x1 + tw]
           processed = preprocess.get_transform(augment=False)
           left_img   = processed(left_img)
           right_img  = processed(right_img)
           return left_img, right_img, dataL
        else:

           """
           w, h = left_img.size

           left_img = left_img.crop((w - 1232, h - 368, w, h))
           right_img = right_img.crop((w - 1232, h - 368, w, h))
           #w1, h1 = left_img.size

           dataL = dataL.crop((w - 1232, h - 368, w, h))
           dataL = np.ascontiguousarray(dataL, dtype=np.float32)/ 256

           processed = preprocess.get_transform(augment=False)
           left_img = processed(left_img)
           right_img = processed(right_img)
           """
           w, h = left_img.size
           th, tw = 256, 512

           x1 = random.randint(0, w - tw)
           y1 = random.randint(0, h - th)

           left_img = left_img.crop((x1, y1, x1 + tw, y1 + th))

           right_img = right_im
  • 7
    点赞
  • 63
    收藏
    觉得还不错? 一键收藏
  • 47
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 47
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值