0
$\begingroup$

I am trying to recreate the model in this paper : BiSeNetV2 There is one module called Context Embedding Block, in which Global Average Pooling is used to embed global information into the feature maps using a residual connection. In the figure provided in the paper, after global pooling and a 1x1 convolution, it mentions a broadcast operation that I traced back to this idea from another paper.

Now, I find myself in front of a relatively easy thing, which is taking a vector of 1x1 feature maps and emulate a feature map of HxW size by repeating the 1x1 element over its entirety. My question is: does it make sense to use Bilinear Upsampling to do so, or will such operation produce a different output from what I have in mind? And moreover, if I were to use Bilinear Upsampling, how should I choose the scale factor in order to accomodate for different input sizes?

$\endgroup$
0

1 Answer 1

1
$\begingroup$

I have found a workaround if anyone is interested. In pytorch in order to perform a global pooling operation one can use:

x = torch.randn(16, 128, 128)
out = F.adaptive_max_pool2d(x.unsqueeze(0), output_size=1)

as it was suggested here

In my case I am actually going to avoid adaptive pooling since it is not supported by onnx and I intend to run inference using onnx runtime later. So I am going to use torch.mean() in the following way:

x = torch.randn(1, 16, 128, 128)
out = torch.mean(x, dim=(2, 3), keepdim=True)

This way I obtain a 1x16x1x1 tensor.

In the end the answer to my original question was rather simple, since if I sum the tensor "out" and the input tensor "x", every element of each 128x128 feature map belonging to x will be summed to the one value of the out tensor corresponding to the index of that map, resulting in a tensor of the same size as x.

x = torch.randn(1, 16, 128, 128)
out = torch.mean(x, dim=(2, 3), keepdim=True)
out = out+x
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.