Created
November 14, 2017 17:03
-
-
Save nishnik/f9041eff871d269eada6decb9454b5d2 to your computer and use it in GitHub Desktop.
Basic implementation of maxpool2d in pytorch, based on it you can create kmaxpool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stride = 3 | |
new_var = Variable(torch.zeros([x.shape[0], x.shape[1]//stride, x.shape[2]//stride])) | |
for dim1 in range(x.shape[0]): | |
tmp = Variable(torch.zeros([x.shape[1]//stride, x.shape[2]//stride, 1])) | |
for i in range(0, x.shape[1], stride): | |
for j in range(0, x.shape[2], stride): | |
tmp_max = x[dim1][i][j] | |
for k in range(stride): | |
for m in range(stride): | |
tmp_max = torch.max(tmp_max, x[dim1][i+k][j+m]) | |
tmp[i//stride, j//stride] = tmp_max | |
new_var[dim1] = tmp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment