1pip install torch===1.5.0 torchvision===0.6.0 -f https://download.pytorch.org/whl/torch_stable.html
1import torch
2
3from torch import nn
4
5conv = nn.Conv2d(1,1,kernel_size=3, padding=1, stride=2, bias=False)
6
7X = torch.FloatTensor([[[
8
9 [4, 2, -1],
10
11 [-6, 0, 5],
12
13 [3, 2, 2]]]])
14
15conv.weight.data = torch.FloatTensor([[[
16
17 [0, 1, 2],
18
19 [1, -1, 0],
20
21 [1, 0, -2]]]])
22
23res = conv(X).data[0,0]
24
25print(res)