Пример #1
0
 def inference(self, left, right):
     cost_volume = compute_cost_volume(right, left)
     linear = self.linear(cost_volume)
     en = self.en(linear)
     up_en = self.upconv(en)
     de = self.de(torch.cat((up_en, linear), dim=1))
     scale_pred = self.regress(de)
     return scale_pred
Пример #2
0
    def inference(self, left, right):
        cost_volume = compute_cost_volume(right, left)
        x = self.linear(cost_volume)

        # encoder
        x2s = self.en1(x)
        fc = self.fc(x2s)

        x2s = self.de1(torch.cat([fc, x2s], dim=1))
        de_x = F.interpolate(x2s, scale_factor=2, mode='bilinear')

        scale_pred = self.scale_pred(torch.cat([de_x, x], dim=1))
        return F.softmax(scale_pred, dim=1)
Пример #3
0
    def forward(self, left, right, kps1, images1, scales):
        """
        left: [B, D, H0, W0]
        right: [B, D, H1, W1]
        kps1: [B, N, 2], belongs to images1
        images1: [B, D, H1', W1']
        scales: [B, D, H1', W1']
        """
        # [b, h0*w0, h1, w1]
        cost_volume = compute_cost_volume(right, left)
        scales_pred = self.regress(cost_volume)

        scale_loss = self.scale_evaluator(scales_pred, scales, kps1, images1)

        return scales_pred, scale_loss
Пример #4
0
    def forward(self, left, right, scale, msk):
        """
        left: [B, D, H0, W0]
        right: [B, D, H1, W1]
        scale: [B, D, H1', W1']
        msk: [B, H1', W1']
        """
        # [b, h0*w0, h1, w1]
        cost_volume = compute_cost_volume(right, left)

        x = self.linear(cost_volume)

        # encoder
        x2s = self.en1(x)
        fc = self.fc(x2s)

        x2s = self.de1(torch.cat([fc, x2s], dim=1))
        de_x = F.interpolate(x2s, scale_factor=2, mode='bilinear')

        scale_pred = self.scale_pred(torch.cat([de_x, x], dim=1))

        # encoder
        # x2s = self.en1(x)
        # x4s = self.en2(x2s)
        # fc = self.fc(x4s)

        # decoder
        # x4s = self.de1(torch.cat([fc, x4s], dim=1))
        # de_x2s = F.interpolate(x4s, scale_factor=2, mode='bilinear')
        # x2s = self.de2(torch.cat([de_x2s, x2s], dim=1))
        # de_x = F.interpolate(x2s, scale_factor=2, mode='bilinear')

        # scale_pred = self.scale_pred(de_x)

        h1, w1 = right.shape[2:]
        scale = F.interpolate(scale.unsqueeze(1), (h1, w1), mode='bilinear')
        scale[scale > 1.5] = 2
        scale[(scale >= 0.75) * (scale <= 1.5)] = 1
        scale[scale < 0.75] = 0
        scale_loss = self.scale_evaluator(scale_pred, scale.long().squeeze(1))

        msk = F.interpolate(msk.unsqueeze(1), (h1, w1),
                            mode='bilinear').squeeze(1)
        scale_loss = torch.sum(scale_loss * msk) / torch.sum(msk)
        return F.softmax(scale_pred, dim=1), scale_loss
Пример #5
0
    def forward(self, left, right, scale, msk):
        """
        left: [B, D, H0', W0']
        right: [B, D, H1', W1']
        scale: [B, 1, H1, W1]
        msk: [B, 1, H1, W1]
        """
        # [b, h0*w0, h1, w1]
        cost_volume = compute_cost_volume(right, left)
        scale_pred = self.regress(cost_volume)

        h1, w1 = right.shape[2:]
        scale = F.interpolate(scale, (h1, w1), mode='bilinear')
        scale[scale > 1.5] = 2
        scale[(scale >= 0.75) * (scale <= 1.5)] = 1
        scale[scale < 0.75] = 0
        scale_loss = self.scale_evaluator(scale_pred, scale.long().squeeze(1))

        msk = F.interpolate(msk, (h1, w1), mode='bilinear').squeeze(1)
        scale_loss = torch.sum(scale_loss * msk) / torch.sum(msk)
        return F.softmax(scale_pred, dim=1), scale_loss
Пример #6
0
    def forward(self, left, right, scale, msk):
        """
        left: [B, D, H0, W0]
        right: [B, D, H1, W1]
        scale: [B, D, H1', W1']
        msk: [B, H1', W1']
        """
        # [b, h0*w0, h1, w1]
        cost_volume = compute_cost_volume(right, left)

        linear = self.linear(cost_volume)
        en = self.en(linear)
        up_en = self.upconv(en)
        de = self.de(torch.cat((up_en, linear), dim=1))
        scale_pred = self.regress(de)

        h1, w1 = right.shape[2:]
        scale = F.interpolate(scale.unsqueeze(1), (h1, w1), mode='bilinear')
        msk = F.interpolate(msk.unsqueeze(1), (h1, w1), mode='bilinear').long().float()
        scale_loss = self.scale_evaluator(scale_pred, scale, msk)

        return scale_pred, scale_loss
Пример #7
0
 def inference(self, left, right):
     cost_volume = compute_cost_volume(right, left)
     scale_pred = self.regress(cost_volume)
     return scale_pred