1adrianb / face-alignment

:fire: 2D and 3D Face alignment library build using pytorch
https://www.adrianbulat.com
BSD 3-Clause "New" or "Revised" License
6.99k stars 1.34k forks source link

No interpolate attribue in Torch nn functional #110

Closed Skorkmaz88 closed 5 years ago

Skorkmaz88 commented 5 years ago

When trying to use prediction:

AttributeError: module 'torch.nn.functional' has no attribute 'interpolate'

Pytorch Version: 0.4.0

OS: Windows 10

Python Version: 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 10:22:32) [MSC v.1900 64 bit (AMD64)] Possible reason could something like this ?

I think torch removed the interpolate layer inside the nn.function and created the equivalent methods for Upsampling and other in different modes.

https://pytorch.org/docs/stable/nn.html?highlight=interpolate 70

-- https://discuss.pytorch.org/t/attributeerror-module-torch-nn-functional-has-no-attribute-instance-norm/15997/4

Trace is below : `--------------------------------------------------------------------------- AttributeError Traceback (most recent call last)

in () ----> 1 preds = fa.get_landmarks(input)[-1] 2 def draw_preds(input, preds): 3 fig = plt.figure(figsize=plt.figaspect(.5)) 4 ax = fig.add_subplot(1, 1, 1) 5 ax.imshow(input) ~\Anaconda3\lib\site-packages\face_alignment\api.py in get_landmarks(self, image_or_path, detected_faces) 139 in the image (default: {None}) 140 """ --> 141 return self.get_landmarks_from_image(image_or_path, detected_faces) 142 143 def get_landmarks_from_image(self, image_or_path, detected_faces=None): ~\Anaconda3\lib\site-packages\face_alignment\api.py in get_landmarks_from_image(self, image_or_path, detected_faces) 192 inp.div_(255.0).unsqueeze_(0) 193 --> 194 out = self.face_alignment_net(inp)[-1].detach() 195 if self.flip_input: 196 out += flip(self.face_alignment_net(flip(inp)) ~\Anaconda3\lib\site-packages\torch\nn\modules\module.py in __call__(self, *input, **kwargs) 489 result = self._slow_forward(*input, **kwargs) 490 else: --> 491 result = self.forward(*input, **kwargs) 492 for hook in self._forward_hooks.values(): 493 hook_result = hook(self, input, result) ~\Anaconda3\lib\site-packages\face_alignment\models.py in forward(self, x) 182 outputs = [] 183 for i in range(self.num_modules): --> 184 hg = self._modules['m' + str(i)](previous) 185 186 ll = hg ~\Anaconda3\lib\site-packages\torch\nn\modules\module.py in __call__(self, *input, **kwargs) 489 result = self._slow_forward(*input, **kwargs) 490 else: --> 491 result = self.forward(*input, **kwargs) 492 for hook in self._forward_hooks.values(): 493 hook_result = hook(self, input, result) ~\Anaconda3\lib\site-packages\face_alignment\models.py in forward(self, x) 140 141 def forward(self, x): --> 142 return self._forward(self.depth, x) 143 144 ~\Anaconda3\lib\site-packages\face_alignment\models.py in _forward(self, level, inp) 127 128 if level > 1: --> 129 low2 = self._forward(level - 1, low1) 130 else: 131 low2 = low1 ~\Anaconda3\lib\site-packages\face_alignment\models.py in _forward(self, level, inp) 127 128 if level > 1: --> 129 low2 = self._forward(level - 1, low1) 130 else: 131 low2 = low1 ~\Anaconda3\lib\site-packages\face_alignment\models.py in _forward(self, level, inp) 127 128 if level > 1: --> 129 low2 = self._forward(level - 1, low1) 130 else: 131 low2 = low1 ~\Anaconda3\lib\site-packages\face_alignment\models.py in _forward(self, level, inp) 135 low3 = self._modules['b3_' + str(level)](low3) 136 --> 137 up2 = F.interpolate(low3, scale_factor=2, mode='nearest') 138 139 return up1 + up2 AttributeError: module 'torch.nn.functional' has no attribute 'interpolate'`
Skorkmaz88 commented 5 years ago

My simple solution was : https://github.com/Skorkmaz88/face-alignment/commit/7ca0f9eaa8020110d529b81a6853a6c01e672472 in my fork

1adrianb commented 5 years ago

Hi @Skorkmaz88,

You can either do that (reverting to previous name of the function), or update to the latest pytorch version.

Skorkmaz88 commented 5 years ago

It has to be newer than 0.4 then, as repo's Readme still has the statement:

pytorch (>=0.4)

As Pytorch 0.4.0 , if I am not mistaken , https://pytorch.org/docs/0.4.0/nn.html#torch-nn-functional, doesn't have this function.

1adrianb commented 5 years ago

@Skorkmaz88 Sorry for this, I will update the readme accordingly.

The function was introduced in 0.4.1