Skip to content

Instantly share code, notes, and snippets.

@arunm8489
Created June 4, 2020 02:39
Show Gist options
  • Save arunm8489/97702555006da8362a7d76216b0dd7d2 to your computer and use it in GitHub Desktop.
Save arunm8489/97702555006da8362a7d76216b0dd7d2 to your computer and use it in GitHub Desktop.
# x --> 4D feature map
batch_size = x.size(0)
grid_size = x.size(2)
# factor by which current feature map reduced from input
stride = inp_dim // x.size(2)
bbox_attrs = 5 + num_classes #5 + 80
num_anchors = len(anchors) #3
#eg detection input dimension [1, 255, 13, 13]
prediction = x.view(batch_size, bbox_attrs*num_anchors, grid_size*grid_size) # 1x255x169
prediction = prediction.transpose(1,2).contiguous() #1x169x255
prediction = prediction.view(batch_size, grid_size*grid_size*num_anchors, bbox_attrs) #1x507x85
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment