from torch_geometric.nn.inits import zeros
时间: 2024-05-12 14:16:16 浏览: 107
PyTorch里面的torch.nn.Parameter()详解
3星 · 编辑精心推荐
The `zeros` function is a weight initialization function from the `torch_geometric.nn.inits` module that initializes the input tensor with zeros. It takes a tensor as an argument and returns a tensor of the same shape initialized with zeros.
For example, suppose we have a tensor `x` of shape (3, 5):
```
import torch
from torch_geometric.nn.inits import zeros
x = torch.randn(3, 5)
print("Before initialization:", x)
zeros(x)
print("After initialization:", x)
```
Output:
```
Before initialization: tensor([[ 0.5984, -0.4796, -0.3161, -1.4763, -0.8963],
[-0.2313, -0.0387, -0.6889, -1.1324, -1.2184],
[ 0.5594, 0.9734, -1.5858, 0.9216, -0.2421]])
After initialization: tensor([[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0.]])
```
As we can see, the `zeros` function has initialized the tensor `x` with zeros. This function is commonly used for bias initialization in neural networks.
阅读全文