Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #94 from inferno-pytorch/hyper-dev
Browse files Browse the repository at this point in the history
Add anisotropic up/downsampling
  • Loading branch information
nasimrahaman committed Dec 19, 2017
2 parents becd717 + 7c73f92 commit 80f85bf
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions inferno/extensions/layers/sampling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import torch.nn as nn

__all__ = ['AnisotropicUpsample', 'AnisotropicPool']


class AnisotropicUpsample(nn.Module):
def __init__(self, scale_factor):
super(AnisotropicUpsample, self).__init__()
self.upsampler = nn.Upsample(scale_factor=scale_factor)

def forward(self, input):
# input is 3D of shape NCDHW
N, C, D, H, W = input.size()
# Fold C and D axes in one
folded = input.view(N, C * D, H, W)
# Upsample
upsampled = self.upsampler(folded)
# Unfold out the C and D axes
unfolded = upsampled.view(N, C, D,
self.upsampler.scale_factor * H,
self.upsampler.scale_factor * W)
# Done
return unfolded


class AnisotropicPool(nn.MaxPool3d):
def __init__(self, downscale_factor):
ds = downscale_factor
super(AnisotropicPool, self).__init__(kernel_size=(1, ds + 1, ds + 1),
stride=(1, ds, ds),
padding=(0, 1, 1))

0 comments on commit 80f85bf

Please sign in to comment.