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

Commit

Permalink
Add fallback for torch < 0.4.1 to Upsample
Browse files Browse the repository at this point in the history
  • Loading branch information
constantinpape committed Aug 27, 2018
1 parent 3649afd commit e47b86a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions inferno/extensions/layers/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,21 @@ def __init__(self, size=None, scale_factor=None, mode='nearest', align_corners=N
self.mode = mode
self.align_corners = align_corners
super(Upsample, self).__init__()
# interpolate was only introduced in torch 0.4.1 for backward compatibility
# we check if we have the attribute here and fall back to Upsample otherwise
if hasattr(nn.functional, 'interpolate'):
self.have_interpolate = True
else:
self.have_interpolate = False
self.sampler = nn.Upsample(size=size, scale_factor=scale_factor,
mode=mode, align_corners=align_corners)

def forward(self, input):
return nn.functional.interpolate(input, self.size, self.scale_factor,
self.mode, self.align_corners)
if self.have_interpolate:
return nn.functional.interpolate(input, self.size, self.scale_factor,
self.mode, self.align_corners)
else:
return self.sampler(input)


class AnisotropicUpsample(nn.Module):
Expand Down Expand Up @@ -46,5 +57,3 @@ def __init__(self, downscale_factor):
padding=(0, 1, 1))




0 comments on commit e47b86a

Please sign in to comment.