在这段代码中如何执行互相关

时间:2019-04-03 03:19:04

标签: batch-processing pytorch cross-correlation

我正在阅读暹罗网络的源代码。但是我不明白互相关代码中正在发生什么。代码是:

def xcorr(self, z, x):
    """
    correlation layer as in the original SiamFC (convolution process in fact)
    """
    batch_size_x, channel_x, w_x, h_x = x.shape
    x = torch.reshape(x, (1, batch_size_x * channel_x, w_x, h_x))

    # group convolution
    out = F.conv2d(x, z, groups = batch_size_x)

    batch_size_out, channel_out, w_out, h_out = out.shape
    xcorr_out = torch.reshape(out, (channel_out, batch_size_out, w_out, h_out))

    return xcorr_out

Complete Source Code

我可以看到可以使用conv操作执行xcorr。但是,这里进行两次重塑的想法是什么? (xcorr函数的两个输入在#batch-size和#channel上具有相同的大小)

0 个答案:

没有答案