Query regarding AdaptiveAvgPool3d

I have an input tensor like x = torch.rand(2,3,13,224,224) and after passing through this tensor from my model I get an output shape as torch.Size([2, 512, 13, 14, 14]). I then further want to reduce 14x14 to 1x1 so it looks like this torch.Size([2, 512, 13, 1, 1]) and then have a max of the 13 features to get an output tensor like torch.Size([2, 512, 1, 1, 1]).

I am pretty new to PyTorch and I found way to do this,

gap = torch.nn.AdaptiveAvgPool3d((None,1,1))
x = model(torch.rand(2,3,13,224,224))
x = gap(x)
x = torch.max(x, 2, keepdim=True)[0]

I want to know if this is the correct way to do this or not. I want to reduce all the 14x14 values to 1x1 using average pooling, my question is am i using AdaptiveAvgPool3d in a correct way or should I use AdaptiveAvgPool2d in some way for reducing 14x14?

Your code looks alright.
Alternatively, since your desired output shape after the average pooling operation is [batch_size, 512, 13, 1, 1], you could also directly apply the mean() operation on dim3 and dim4 in a similar way as you’ve already done for torch.max (but this should yield the same output as your current approach).