I’m new to Pytorch, I feel puzzled when I run the code:
from torch.nn.init import zeros_
and use it to initialize some veriables:
zeros_(model.bias)
and I got an error: ImportError: cannot import name ‘zeros_’
where torch.version is 0.4.0
I’m new to Pytorch, I feel puzzled when I run the code:
from torch.nn.init import zeros_
and use it to initialize some veriables:
zeros_(model.bias)
and I got an error: ImportError: cannot import name ‘zeros_’
where torch.version is 0.4.0
Hi,
I ran your code, and I did not get any error.
If you want to init with constant values, here is a better approach:
torch.nn.init.constant_(tensor, 0)
Bests
Nik
Hi,
Thanks for your reply!
I will try to use the approach to init with constant values.
I solve this problem by updating the torch version.
when the torch version is 0.4.0
import torch
dir(torch.nn.init)
and can not find ‘zeros_’ in the result. So I updata the torch version(0.4.1).
Thanks !
You are welcome.
I think it is great idea to use latest version. There are a lot of optimization and development now. Furthermore, your code will be usable for different purposes.
Good luck