Monodepth2网络论文解析即训练总结

1. 亮点

  1. 最小重投影loss-处理遮挡问题
  2. 全分辨率多尺度采样-减少视觉伪影
  3. auto-masking loss-忽略违反相机运动假设的像素

2. loss

2.1 重投影误差

    def compute_reprojection_loss(self, pred, target):
        """Computes reprojection loss between a batch of predicted and target images
        """
        abs_diff = torch.abs(target - pred)
        l1_loss = abs_diff.mean(1, True)

        if self.opt.no_ssim:
            reprojection_loss = l1_loss
        else:
            ssim_loss = self.ssim(pred, target).mean(1, True)
            reprojection_loss = 0.85 * ssim_loss + 0.15 * l1_loss

        return reprojection_loss
  1. 每张照片内参K相同
  2. 采用双线性采样对原图进行采样,这种方法是局部可微的

outputs[("sample", frame_id, scale)] = pix_coords
outputs[("color", frame_id, scale)] = F.grid_sample(
                    inputs[("color", frame_id, source_scale)],
                    outputs[("sample", frame_id, scale)],
                    padding_mode="border",align_corners=False)

grid_sample采用双线性差值
3. 边缘感知平滑

def get_smooth_loss(disp, img):
    """Computes the smoothness loss for a disparity image
    The color image is used for edge-aware smoothness
    """
    grad_disp_x = torch.abs(disp[:, :, :, :-1] - disp[:, :, :, 1:])
    grad_disp_y = torch.abs(disp[:, :, :-1, :] - disp[:, :, 1:, :])

    grad_img_x = torch.mean(torch.abs(img[:, :, :, :-1] - img[:, :, :, 1:]), 1, keepdim=True)
    grad_img_y = torch.mean(torch.abs(img[:, :, :-1, :] - img[:, :, 1:, :]), 1, keepdim=True)

    grad_disp_x *= torch.exp(-grad_img_x)
    grad_disp_y *= torch.exp(-grad_img_y)

    return grad_disp_x.mean() + grad_disp_y.mean()

3. 改进步骤

3.1 最小重投影误差

3.2 auto-masking

在loss中对每个像素使用mask u,对每个像素进行加权。其中u是二进制的,在0,1之间。并且在网络前向传播时自动计算。
序列中相邻帧之间保持相同的像素通常表示相机静止,目标与相机运动速度相同,或者低纹理区域。

            if not self.opt.disable_automasking:
                identity_reprojection_losses = []
                for frame_id in self.opt.frame_ids[1:]:
                    pred = inputs[("color", frame_id, source_scale)]
                    identity_reprojection_losses.append(
                        self.compute_reprojection_loss(pred, target))

                identity_reprojection_losses = torch.cat(identity_reprojection_losses, 1)

                if self.opt.avg_reprojection:
                    identity_reprojection_loss = identity_reprojection_losses.mean(1, keepdim=True)
                else:
                    # save both images, and do min all at once below
                    identity_reprojection_loss = identity_reprojection_losses
 if not self.opt.disable_automasking:
                # add random numbers to break ties
                identity_reprojection_loss += torch.randn(
                    identity_reprojection_loss.shape, device=self.device) * 0.00001

                combined = torch.cat((identity_reprojection_loss, reprojection_loss), dim=1)
            else:
                combined = reprojection_loss

3.3 多尺度估计

3.4 网络优化

  1. 输出端使用Sigmoid,在其他地方使用ELU非线性
class ConvBlock(nn.Module):
    """Layer to perform a convolution followed by ELU
    """
    def __init__(self, in_channels, out_channels):
        super(ConvBlock, self).__init__()

        self.conv = Conv3x3(in_channels, out_channels)
        self.nonlin = nn.ELU(inplace=True)

    def forward(self, x):
        out = self.conv(x)
        out = self.nonlin(out)
        return out

    def forward(self, input_features):
        self.outputs = {}

        # decoder
        # print(input_features.shape)
        x = input_features[-1]
        for i in range(4, -1, -1):
            x = self.convs[("upconv", i, 0)](x)
            x = [upsample(x)]
            if self.use_skips and i > 0:
                x += [input_features[i - 1]]
            x = torch.cat(x, 1)
            x = self.convs[("upconv", i, 1)](x)
            if i in self.scales:
                self.outputs[("disp", i)] = self.sigmoid(self.convs[("dispconv", i)](x))

        return self.outputs
  1. 使用D=1/(aσ+b)将深度图输出σ S形投影到深度,其中选择a和b将D限制在0.1到100个单位之间。
def disp_to_depth(disp, min_depth, max_depth):
    """Convert network's sigmoid output into depth prediction
    The formula for this conversion is given in the 'additional considerations'
    section of the paper.
    """
    min_disp = 1 / max_depth
    max_disp = 1 / min_depth
    scaled_disp = min_disp + (max_disp - min_disp) * disp
    depth = 1 / scaled_disp
    return scaled_disp, depth
  1. 在解码器中使用反射填充代替零填充,当样本到达图像边界之外时,返回源图像中最近边界像素的值。显著减少了现有方法中发现的边界伪影。
class Conv3x3(nn.Module):
    """Layer to pad and convolve input
    """
    def __init__(self, in_channels, out_channels, use_refl=True):
        super(Conv3x3, self).__init__()

        if use_refl:
            self.pad = nn.ReflectionPad2d(1)
        else:
            self.pad = nn.ZeroPad2d(1)
        self.conv = nn.Conv2d(int(in_channels), int(out_channels), 3)

    def forward(self, x):
        out = self.pad(x)
        out = self.conv(out)
        return out
  1. 对于单目训练,使用三帧的序列长度,pose network 是由一个ResNet18组成的,修改为接受一对彩色图像(或六个通道)作为输入,并预测单个6自由度相对姿势
  • 0
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
训练monodepth2模型使用自己的数据集,你可以按照以下步骤进行操作: 1. 准备数据集:首先,你需要准备一组包含深度信息的图像作为你的训练集。这些图像可以是双目图像,也可以是包含深度信息的单目图像。 2. 数据预处理:在训练之前,你需要对数据进行预处理。这包括调整图像的大小、对图像进行归一化处理和转换为模型所需的格式。 3. 加载模型:根据monodepth2模型的实战方法,你应该使用stereo training方法。这意味着你需要加载相应的模型并进行初始化。 4. 构建数据加载器:使用torch.utils.data.distributed.DistributedSampler对训练集和验证集进行包装,以实现多卡分配。然后,使用DataLoader将数据集加载到训练过程中。 5. 训练模型:使用加载的模型和构建的数据加载器,开始训练你的monodepth2模型。通过迭代训练和调整模型参数,使其能够准确地估计深度信息。 6. 验证模型:在训练过程中,定期使用验证集评估模型的性能。这可以帮助你了解模型的训练进展和预测精度。 总而言之,你需要准备数据集,进行数据预处理,加载模型,构建数据加载器,训练模型,并在验证集上评估模型的性能。通过这些步骤,你可以使用monodepth2模型训练自己的数据集。引用<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [双目测距系列(七)monodepth2训练前数据集准备过程的简析](https://blog.csdn.net/ltshan139/article/details/105970906)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [深度估计自监督模型monodepth2在自己数据集的实战——单卡/多卡训练、推理、Onnx转换和量化指标评估](https://blog.csdn.net/weixin_43148897/article/details/122729725)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值