oawiles / X2Face

Pytorch code for ECCV 2018 paper
MIT License
246 stars 58 forks source link

RuntimeError: uniform_ expects to return a [from, to) range, but found from=1 > to=0.02 #25

Closed afung-git closed 5 years ago

afung-git commented 5 years ago

When I try to load the model I get the following error. Any insight into how I can fix this would be of great help. I am relatively new to deep learning.

initialization method [xavier]

RuntimeError Traceback (most recent call last)

in 2 state_dict = torch_load_model(BASE_MODEL + 'x2face_model.pth') 3 ----> 4 model = UnwrappedFaceWeightedAverage(output_num_channels=2, input_num_channels=3, inner_nc=128) 5 model.load_state_dict(state_dict['state_dict']) 6 model = model.to(device) E:\Alberto_MSR_WORK\UnwrapMosaic\UnwrappedFace.py in __init__(self, output_num_channels, input_num_channels, inner_nc) 19 super(UnwrappedFaceWeightedAverage, self).__init__() 20 ---> 21 self.pix2pixUnwrapped = Pix2PixModel(3) 22 23 self.pix2pixSampler = NoSkipPix2PixModel(input_num_channels, output_num_channels, inner_nc=inner_nc) E:\Alberto_MSR_WORK\UnwrapMosaic\SkipNet.py in __init__(self, output_nc, input_nc) 183 184 gpu = [] --> 185 if torch.cuda.is_available(): 186 gpu = [0] 187 self.netG = define_G(input_nc, output_nc, 64, 'unet_256', 'batch', False, 'xavier', gpu) E:\Alberto_MSR_WORK\UnwrapMosaic\SkipNet.py in define_G(input_nc, output_nc, ngf, which_model_netG, norm, use_dropout, init_type, gpu_ids) 163 else: 164 raise NotImplementedError('Generator model name [%s] is not recognized' % which_model_netG) --> 165 if len(gpu_ids) > 0: 166 netG.cuda() 167 init_weights(netG, init_type=init_type) E:\Alberto_MSR_WORK\UnwrapMosaic\SkipNet.py in init_weights(net, init_type) 107 print('initialization method [%s]' % init_type) 108 if init_type == 'normal': --> 109 net.apply(weights_init_normal) 110 elif init_type == 'xavier': 111 net.apply(weights_init_xavier) d:\users\alberto\miniconda3\envs\pytorch\lib\site-packages\torch\nn\modules\module.py in apply(self, fn) 291 """ 292 for module in self.children(): --> 293 module.apply(fn) 294 fn(self) 295 return self d:\users\alberto\miniconda3\envs\pytorch\lib\site-packages\torch\nn\modules\module.py in apply(self, fn) 291 """ 292 for module in self.children(): --> 293 module.apply(fn) 294 fn(self) 295 return self d:\users\alberto\miniconda3\envs\pytorch\lib\site-packages\torch\nn\modules\module.py in apply(self, fn) 291 """ 292 for module in self.children(): --> 293 module.apply(fn) 294 fn(self) 295 return self d:\users\alberto\miniconda3\envs\pytorch\lib\site-packages\torch\nn\modules\module.py in apply(self, fn) 291 """ 292 for module in self.children(): --> 293 module.apply(fn) 294 fn(self) 295 return self d:\users\alberto\miniconda3\envs\pytorch\lib\site-packages\torch\nn\modules\module.py in apply(self, fn) 292 for module in self.children(): 293 module.apply(fn) --> 294 fn(self) 295 return self 296 E:\Alberto_MSR_WORK\UnwrapMosaic\SkipNet.py in weights_init_xavier(m) 74 init.xavier_normal(m.weight.data, gain=1) 75 elif classname.find('BatchNorm2d') != -1: ---> 76 init.uniform(m.weight.data, 1.0, 0.02) 77 init.constant(m.bias.data, 0.0) 78 d:\users\alberto\miniconda3\envs\pytorch\lib\site-packages\torch\nn\init.py in deprecated_init(*args, **kwargs) 434 warnings.warn("nn.init.{} is now deprecated in favor of nn.init.{}." 435 .format(old_name, new_name), stacklevel=2) --> 436 return meth(*args, **kwargs) 437 438 deprecated_init.__doc__ = r""" d:\users\alberto\miniconda3\envs\pytorch\lib\site-packages\torch\nn\init.py in uniform_(tensor, a, b) 86 >>> nn.init.uniform_(w) 87 """ ---> 88 return _no_grad_uniform_(tensor, a, b) 89 90 d:\users\alberto\miniconda3\envs\pytorch\lib\site-packages\torch\nn\init.py in _no_grad_uniform_(tensor, a, b) 12 def _no_grad_uniform_(tensor, a, b): 13 with torch.no_grad(): ---> 14 return tensor.uniform_(a, b) 15 16 RuntimeError: uniform_ expects to return a [from, to) range, but found from=1 > to=0.02
oawiles commented 5 years ago

I assume it's a pytorch version issue.

tlatlbtle commented 5 years ago

I assume it's a pytorch version issue.

The same issue. Would you mind provide a valid download link for installing torch==0.2.0_4 correctly? I do not find any satisfied version on: https://pytorch.org/get-started/previous-versions/ All of the Linux binaries are compiled with CUDA 7.5, but my machine is built with CUDA-10.0. It seems it is impossible to inference it.

Thanks.

afung-git commented 5 years ago

I assume it's a pytorch version issue.

It is indeed a pytorch version. If you are using a newer version of pytorch just change the order of the ranges in your uniform function from init.uniform(m.weight.data, 1.0, 0.02) ==> init.uniform(m.weight.data, 0.02, 1.0).