for循环版本:
import numpy as np
x = np.array([[-1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, 1, -1, -1, -1, -1, -1, 1, -1],
[-1, -1, 1, -1, -1, -1, 1, -1, -1],
[-1, -1, -1, 1, -1, 1, -1, -1, -1],
[-1, -1, -1, -1, 1, -1, -1, -1, -1],
[-1, -1, -1, 1, -1, 1, -1, -1, -1],
[-1, -1, 1, -1, -1, -1, 1, -1, -1],
[-1, 1, -1, -1, -1, -1, -1, 1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1]])
print("x=\n", x)
Kernel = [[0 for i in range(0, 3)] for j in range(0, 3)]
Kernel[0] = np.array([[1, -1, -1],
[-1, 1, -1],
[-1, -1, 1]])
Kernel[1] = np.array([[1, -1, 1],
[-1, 1, -1],
[1, -1, 1]])
Kernel[2] = np.array([[-1, -1, 1],
[-1, 1, -1],
[1, -1, -1]])
stride = 1
feature_map_h = 7
feature_map_w = 7
feature_map = [0 for i in range(0, 3)]
for i in range(0, 3):
feature_map[i] = np.zeros((feature_map_h, feature_map_w))
for h in range(feature_map_h):
for w in range(feature_map_w):
v_start = h * stride
v_end = v_start + 3
h_start = w * stride
h_end = h_start + 3
window = x[v_start:v_end, h_start:h_end]
for i in range(0, 3):
feature_map[i][h, w] = np.divide(np.sum(np.multiply(window, Kernel[i][:, :])), 9)
print("feature_map:\n", np.around(feature_map, decimals=2))
pooling_stride = 2
pooling_h = 4
pooling_w = 4
feature_map_pad_0 = [[0 for i in range(0, 8)] for j in range(0, 8)]
for i in range(0, 3):
feature_map_pad_0[i] = np.pad(feature_map[i], ((0, 1), (0, 1)), 'constant', constant_values=(0, 0))
pooling = [0 for i in range(0, 3)]
for i in range(0, 3):
pooling[i] = np.zeros((pooling_h, pooling_w))
for h in range(pooling_h):
for w in range(pooling_w):
v_start = h * pooling_stride
v_end = v_start + 2
h_start = w * pooling_stride
h_end = h_start + 2
for i in range(0, 3):
pooling[i][h, w] = np.max(feature_map_pad_0[i][v_start:v_end, h_start:h_end])
print("pooling:\n", np.around(pooling[0], decimals=2))
print("pooling:\n", np.around(pooling[1], decimals=2))
print("pooling:\n", np.around(pooling[2], decimals=2))
def relu(x):
return (abs(x) + x) / 2
relu_map_h = 7
relu_map_w = 7
relu_map = [0 for i in range(0, 3)]
for i in range(0, 3):
relu_map[i] = np.zeros((relu_map_h, relu_map_w))
for i in range(0, 3):
relu_map[i] = relu(feature_map[i])
print("relu map :\n",np.around(relu_map[0], decimals=2))
print("relu map :\n",np.around(relu_map[1], decimals=2))
print("relu map :\n",np.around(relu_map[2], decimals=2))
输入:
x=
[[-1 -1 -1 -1 -1 -1 -1 -1 -1]
[-1 1 -1 -1 -1 -1 -1 1 -1]
[-1 -1 1 -1 -1 -1 1 -1 -1]
[-1 -1 -1 1 -1 1 -1 -1 -1]
[-1 -1 -1 -1 1 -1 -1 -1 -1]
[-1 -1 -1 1 -1 1 -1 -1 -1]
[-1 -1 1 -1 -1 -1 1 -1 -1]
[-1 1 -1 -1 -1 -1 -1 1 -1]
[-1 -1 -1 -1 -1 -1 -1 -1 -1]]
输出
feature_map:
[[[ 0.78 -0.11 0.11 0.33 0.56 -0.11 0.33]
[-0.11 1. -0.11 0.33 -0.11 0.11 -0.11]
[ 0.11 -0.11 1. -0.33 0.11 -0.11 0.56]
[ 0.33 0.33 -0.33 0.56 -0.33 0.33 0.33]
[ 0.56 -0.11 0.11 -0.33 1. -0.11 0.11]
[-0.11 0.11 -0.11 0.33 -0.11 1. -0.11]
[ 0.33 -0.11 0.56 0.33 0.11 -0.11 0.78]]
[[ 0.33 -0.56 0.11 -0.11 0.11 -0.56 0.33]
[-0.56 0.56 -0.56 0.33 -0.56 0.56 -0.56]
[ 0.11 -0.56 0.56 -0.78 0.56 -0.56 0.11]
[-0.11 0.33 -0.78 1. -0.78 0.33 -0.11]
[ 0.11 -0.56 0.56 -0.78 0.56 -0.56 0.11]
[-0.56 0.56 -0.56 0.33 -0.56 0.56 -0.56]
[ 0.33 -0.56 0.11 -0.11 0.11 -0.56 0.33]]
[[ 0.33 -0.11 0.56 0.33 0.11 -0.11 0.78]
[-0.11 0.11 -0.11 0.33 -0.11 1. -0.11]
[ 0.56 -0.11 0.11 -0.33 1. -0.11 0.11]
[ 0.33 0.33 -0.33 0.56 -0.33 0.33 0.33]
[ 0.11 -0.11 1. -0.33 0.11 -0.11 0.56]
[-0.11 1. -0.11 0.33 -0.11 0.11 -0.11]
[ 0.78 -0.11 0.11 0.33 0.56 -0.11 0.33]]]
pooling:
[[1. 0.33 0.56 0.33]
[0.33 1. 0.33 0.56]
[0.56 0.33 1. 0.11]
[0.33 0.56 0.11 0.78]]
pooling:
[[0.56 0.33 0.56 0.33]
[0.33 1. 0.56 0.11]
[0.56 0.56 0.56 0.11]
[0.33 0.11 0.11 0.33]]
pooling:
[[0.33 0.56 1. 0.78]
[0.56 0.56 1. 0.33]
[1. 1. 0.11 0.56]
[0.78 0.33 0.56 0.33]]
relu map :
[[0.78 0. 0.11 0.33 0.56 0. 0.33]
[0. 1. 0. 0.33 0. 0.11 0. ]
[0.11 0. 1. 0. 0.11 0. 0.56]
[0.33 0.33 0. 0.56 0. 0.33 0.33]
[0.56 0. 0.11 0. 1. 0. 0.11]
[0. 0.11 0. 0.33 0. 1. 0. ]
[0.33 0. 0.56 0.33 0.11 0. 0.78]]
relu map :
[[0.33 0. 0.11 0. 0.11 0. 0.33]
[0. 0.56 0. 0.33 0. 0.56 0. ]
[0.11 0. 0.56 0. 0.56 0. 0.11]
[0. 0.33 0. 1. 0. 0.33 0. ]
[0.11 0. 0.56 0. 0.56 0. 0.11]
[0. 0.56 0. 0.33 0. 0.56 0. ]
[0.33 0. 0.11 0. 0.11 0. 0.33]]
relu map :
[[0.33 0. 0.56 0.33 0.11 0. 0.78]
[0. 0.11 0. 0.33 0. 1. 0. ]
[0.56 0. 0.11 0. 1. 0. 0.11]
[0.33 0.33 0. 0.56 0. 0.33 0.33]
[0.11 0. 1. 0. 0.11 0. 0.56]
[0. 1. 0. 0.33 0. 0.11 0. ]
[0.78 0. 0.11 0.33 0.56 0. 0.33]]
Pytorch版本
import numpy as np
import torch
import torch.nn as nn
x = torch.tensor([[[[-1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, 1, -1, -1, -1, -1, -1, 1, -1],
[-1, -1, 1, -1, -1, -1, 1, -1, -1],
[-1, -1, -1, 1, -1, 1, -1, -1, -1],
[-1, -1, -1, -1, 1, -1, -1, -1, -1],
[-1, -1, -1, 1, -1, 1, -1, -1, -1],
[-1, -1, 1, -1, -1, -1, 1, -1, -1],
[-1, 1, -1, -1, -1, -1, -1, 1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1]]]], dtype=torch.float)
print(x.shape)
print(x)
print("--------------- 卷积 ---------------")
conv1 = nn.Conv2d(1, 1, (3, 3), 1)
conv1.weight.data = torch.Tensor([[[[1, -1, -1],
[-1, 1, -1],
[-1, -1, 1]]
]])
conv2 = nn.Conv2d(1, 1, (3, 3), 1)
conv2.weight.data = torch.Tensor([[[[1, -1, 1],
[-1, 1, -1],
[1, -1, 1]]
]])
conv3 = nn.Conv2d(1, 1, (3, 3), 1)
conv3.weight.data = torch.Tensor([[[[-1, -1, 1],
[-1, 1, -1],
[1, -1, -1]]
]])
feature_map1 = conv1(x)
feature_map2 = conv2(x)
feature_map3 = conv3(x)
print(feature_map1 / 9)
print(feature_map2 / 9)
print(feature_map3 / 9)
print("--------------- 池化 ---------------")
max_pool = nn.MaxPool2d(2, padding=0, stride=2)
zeroPad = nn.ZeroPad2d(padding=(0, 1, 0, 1))
feature_map_pad_0_1 = zeroPad(feature_map1)
feature_pool_1 = max_pool(feature_map_pad_0_1)
feature_map_pad_0_2 = zeroPad(feature_map2)
feature_pool_2 = max_pool(feature_map_pad_0_2)
feature_map_pad_0_3 = zeroPad(feature_map3)
feature_pool_3 = max_pool(feature_map_pad_0_3)
print(feature_pool_1.size())
print(feature_pool_1 / 9)
print(feature_pool_2 / 9)
print(feature_pool_3 / 9)
print("--------------- 激活 ---------------")
activation_function = nn.ReLU()
feature_relu1 = activation_function(feature_map1)
feature_relu2 = activation_function(feature_map2)
feature_relu3 = activation_function(feature_map3)
print(feature_relu1 / 9)
print(feature_relu2 / 9)
print(feature_relu3 / 9)
torch.Size([1, 1, 9, 9])
tensor([[[[-1., -1., -1., -1., -1., -1., -1., -1., -1.],
[-1., 1., -1., -1., -1., -1., -1., 1., -1.],
[-1., -1., 1., -1., -1., -1., 1., -1., -1.],
[-1., -1., -1., 1., -1., 1., -1., -1., -1.],
[-1., -1., -1., -1., 1., -1., -1., -1., -1.],
[-1., -1., -1., 1., -1., 1., -1., -1., -1.],
[-1., -1., 1., -1., -1., -1., 1., -1., -1.],
[-1., 1., -1., -1., -1., -1., -1., 1., -1.],
[-1., -1., -1., -1., -1., -1., -1., -1., -1.]]]])
--------------- 卷积 ---------------
tensor([[[[ 0.7503, -0.1385, 0.0837, 0.3059, 0.5281, -0.1385, 0.3059],
[-0.1385, 0.9726, -0.1385, 0.3059, -0.1385, 0.0837, -0.1385],
[ 0.0837, -0.1385, 0.9726, -0.3608, 0.0837, -0.1385, 0.5281],
[ 0.3059, 0.3059, -0.3608, 0.5281, -0.3608, 0.3059, 0.3059],
[ 0.5281, -0.1385, 0.0837, -0.3608, 0.9726, -0.1385, 0.0837],
[-0.1385, 0.0837, -0.1385, 0.3059, -0.1385, 0.9726, -0.1385],
[ 0.3059, -0.1385, 0.5281, 0.3059, 0.0837, -0.1385, 0.7503]]]],
grad_fn=<DivBackward0>)
tensor([[[[ 0.3379, -0.5510, 0.1157, -0.1066, 0.1157, -0.5510, 0.3379],
[-0.5510, 0.5601, -0.5510, 0.3379, -0.5510, 0.5601, -0.5510],
[ 0.1157, -0.5510, 0.5601, -0.7732, 0.5601, -0.5510, 0.1157],
[-0.1066, 0.3379, -0.7732, 1.0045, -0.7732, 0.3379, -0.1066],
[ 0.1157, -0.5510, 0.5601, -0.7732, 0.5601, -0.5510, 0.1157],
[-0.5510, 0.5601, -0.5510, 0.3379, -0.5510, 0.5601, -0.5510],
[ 0.3379, -0.5510, 0.1157, -0.1066, 0.1157, -0.5510, 0.3379]]]],
grad_fn=<DivBackward0>)
tensor([[[[ 0.3643, -0.0802, 0.5865, 0.3643, 0.1421, -0.0802, 0.8087],
[-0.0802, 0.1421, -0.0802, 0.3643, -0.0802, 1.0309, -0.0802],
[ 0.5865, -0.0802, 0.1421, -0.3024, 1.0309, -0.0802, 0.1421],
[ 0.3643, 0.3643, -0.3024, 0.5865, -0.3024, 0.3643, 0.3643],
[ 0.1421, -0.0802, 1.0309, -0.3024, 0.1421, -0.0802, 0.5865],
[-0.0802, 1.0309, -0.0802, 0.3643, -0.0802, 0.1421, -0.0802],
[ 0.8087, -0.0802, 0.1421, 0.3643, 0.5865, -0.0802, 0.3643]]]],
grad_fn=<DivBackward0>)
--------------- 池化 ---------------
torch.Size([1, 1, 4, 4])
tensor([[[[0.9726, 0.3059, 0.5281, 0.3059],
[0.3059, 0.9726, 0.3059, 0.5281],
[0.5281, 0.3059, 0.9726, 0.0837],
[0.3059, 0.5281, 0.0837, 0.7503]]]], grad_fn=<DivBackward0>)
tensor([[[[0.5601, 0.3379, 0.5601, 0.3379],
[0.3379, 1.0045, 0.5601, 0.1157],
[0.5601, 0.5601, 0.5601, 0.1157],
[0.3379, 0.1157, 0.1157, 0.3379]]]], grad_fn=<DivBackward0>)
tensor([[[[0.3643, 0.5865, 1.0309, 0.8087],
[0.5865, 0.5865, 1.0309, 0.3643],
[1.0309, 1.0309, 0.1421, 0.5865],
[0.8087, 0.3643, 0.5865, 0.3643]]]], grad_fn=<DivBackward0>)
--------------- 激活 ---------------
tensor([[[[0.7503, 0.0000, 0.0837, 0.3059, 0.5281, 0.0000, 0.3059],
[0.0000, 0.9726, 0.0000, 0.3059, 0.0000, 0.0837, 0.0000],
[0.0837, 0.0000, 0.9726, 0.0000, 0.0837, 0.0000, 0.5281],
[0.3059, 0.3059, 0.0000, 0.5281, 0.0000, 0.3059, 0.3059],
[0.5281, 0.0000, 0.0837, 0.0000, 0.9726, 0.0000, 0.0837],
[0.0000, 0.0837, 0.0000, 0.3059, 0.0000, 0.9726, 0.0000],
[0.3059, 0.0000, 0.5281, 0.3059, 0.0837, 0.0000, 0.7503]]]],
grad_fn=<DivBackward0>)
tensor([[[[0.3379, 0.0000, 0.1157, 0.0000, 0.1157, 0.0000, 0.3379],
[0.0000, 0.5601, 0.0000, 0.3379, 0.0000, 0.5601, 0.0000],
[0.1157, 0.0000, 0.5601, 0.0000, 0.5601, 0.0000, 0.1157],
[0.0000, 0.3379, 0.0000, 1.0045, 0.0000, 0.3379, 0.0000],
[0.1157, 0.0000, 0.5601, 0.0000, 0.5601, 0.0000, 0.1157],
[0.0000, 0.5601, 0.0000, 0.3379, 0.0000, 0.5601, 0.0000],
[0.3379, 0.0000, 0.1157, 0.0000, 0.1157, 0.0000, 0.3379]]]],
grad_fn=<DivBackward0>)
tensor([[[[0.3643, 0.0000, 0.5865, 0.3643, 0.1421, 0.0000, 0.8087],
[0.0000, 0.1421, 0.0000, 0.3643, 0.0000, 1.0309, 0.0000],
[0.5865, 0.0000, 0.1421, 0.0000, 1.0309, 0.0000, 0.1421],
[0.3643, 0.3643, 0.0000, 0.5865, 0.0000, 0.3643, 0.3643],
[0.1421, 0.0000, 1.0309, 0.0000, 0.1421, 0.0000, 0.5865],
[0.0000, 1.0309, 0.0000, 0.3643, 0.0000, 0.1421, 0.0000],
[0.8087, 0.0000, 0.1421, 0.3643, 0.5865, 0.0000, 0.3643]]]],
grad_fn=<DivBackward0>)
可视化:了解数字与图像之间的关系
import torch
import torch.nn as nn
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False
x = torch.tensor([[[[-1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, 1, -1, -1, -1, -1, -1, 1, -1],
[-1, -1, 1, -1, -1, -1, 1, -1, -1],
[-1, -1, -1, 1, -1, 1, -1, -1, -1],
[-1, -1, -1, -1, 1, -1, -1, -1, -1],
[-1, -1, -1, 1, -1, 1, -1, -1, -1],
[-1, -1, 1, -1, -1, -1, 1, -1, -1],
[-1, 1, -1, -1, -1, -1, -1, 1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1]]]], dtype=torch.float)
print(x.shape)
print(x)
img = x.data.squeeze().numpy()
plt.imshow(img, cmap='gray')
plt.title('原图')
plt.show()
print("--------------- 卷积 ---------------")
conv1 = nn.Conv2d(1, 1, (3, 3), 1)
conv1.weight.data = torch.Tensor([[[[1, -1, -1],
[-1, 1, -1],
[-1, -1, 1]]
]])
img = conv1.weight.data.squeeze().numpy()
plt.imshow(img, cmap='gray')
plt.title('Kernel 1')
plt.show()
conv2 = nn.Conv2d(1, 1, (3, 3), 1)
conv2.weight.data = torch.Tensor([[[[1, -1, 1],
[-1, 1, -1],
[1, -1, 1]]
]])
img = conv2.weight.data.squeeze().numpy()
plt.imshow(img, cmap='gray')
plt.title('Kernel 2')
plt.show()
conv3 = nn.Conv2d(1, 1, (3, 3), 1)
conv3.weight.data = torch.Tensor([[[[-1, -1, 1],
[-1, 1, -1],
[1, -1, -1]]
]])
img = conv3.weight.data.squeeze().numpy()
plt.imshow(img, cmap='gray')
plt.title('Kernel 3')
plt.show()
feature_map1 = conv1(x)
feature_map2 = conv2(x)
feature_map3 = conv3(x)
print(feature_map1 / 9)
print(feature_map2 / 9)
print(feature_map3 / 9)
img = feature_map1.data.squeeze().numpy()
plt.imshow(img, cmap='gray')
plt.title('卷积后的特征图1')
plt.show()
print("--------------- 池化 ---------------")
max_pool = nn.MaxPool2d(2, padding=0, stride=2)
zeroPad = nn.ZeroPad2d(padding=(0, 1, 0, 1))
feature_map_pad_0_1 = zeroPad(feature_map1)
feature_pool_1 = max_pool(feature_map_pad_0_1)
feature_map_pad_0_2 = zeroPad(feature_map2)
feature_pool_2 = max_pool(feature_map_pad_0_2)
feature_map_pad_0_3 = zeroPad(feature_map3)
feature_pool_3 = max_pool(feature_map_pad_0_3)
print(feature_pool_1.size())
print(feature_pool_1 / 9)
print(feature_pool_2 / 9)
print(feature_pool_3 / 9)
img = feature_pool_1.data.squeeze().numpy()
plt.imshow(img, cmap='gray')
plt.title('卷积池化后的特征图1')
plt.show()
print("--------------- 激活 ---------------")
activation_function = nn.ReLU()
feature_relu1 = activation_function(feature_map1)
feature_relu2 = activation_function(feature_map2)
feature_relu3 = activation_function(feature_map3)
print(feature_relu1 / 9)
print(feature_relu2 / 9)
print(feature_relu3 / 9)
img = feature_relu1.data.squeeze().numpy()
plt.imshow(img, cmap='gray')
plt.title('卷积 + relu 后的特征图1')
plt.show()
运行结果
torch.Size([1, 1, 9, 9])
tensor([[[[-1., -1., -1., -1., -1., -1., -1., -1., -1.],
[-1., 1., -1., -1., -1., -1., -1., 1., -1.],
[-1., -1., 1., -1., -1., -1., 1., -1., -1.],
[-1., -1., -1., 1., -1., 1., -1., -1., -1.],
[-1., -1., -1., -1., 1., -1., -1., -1., -1.],
[-1., -1., -1., 1., -1., 1., -1., -1., -1.],
[-1., -1., 1., -1., -1., -1., 1., -1., -1.],
[-1., 1., -1., -1., -1., -1., -1., 1., -1.],
[-1., -1., -1., -1., -1., -1., -1., -1., -1.]]]])
--------------- 卷积 ---------------
tensor([[[[ 0.7500, -0.1389, 0.0833, 0.3055, 0.5278, -0.1389, 0.3055],
[-0.1389, 0.9722, -0.1389, 0.3055, -0.1389, 0.0833, -0.1389],
[ 0.0833, -0.1389, 0.9722, -0.3611, 0.0833, -0.1389, 0.5278],
[ 0.3055, 0.3055, -0.3611, 0.5278, -0.3611, 0.3055, 0.3055],
[ 0.5278, -0.1389, 0.0833, -0.3611, 0.9722, -0.1389, 0.0833],
[-0.1389, 0.0833, -0.1389, 0.3055, -0.1389, 0.9722, -0.1389],
[ 0.3055, -0.1389, 0.5278, 0.3055, 0.0833, -0.1389, 0.7500]]]],
grad_fn=<DivBackward0>)
tensor([[[[ 0.3406, -0.5483, 0.1184, -0.1038, 0.1184, -0.5483, 0.3406],
[-0.5483, 0.5629, -0.5483, 0.3406, -0.5483, 0.5629, -0.5483],
[ 0.1184, -0.5483, 0.5629, -0.7705, 0.5629, -0.5483, 0.1184],
[-0.1038, 0.3406, -0.7705, 1.0073, -0.7705, 0.3406, -0.1038],
[ 0.1184, -0.5483, 0.5629, -0.7705, 0.5629, -0.5483, 0.1184],
[-0.5483, 0.5629, -0.5483, 0.3406, -0.5483, 0.5629, -0.5483],
[ 0.3406, -0.5483, 0.1184, -0.1038, 0.1184, -0.5483, 0.3406]]]],
grad_fn=<DivBackward0>)
tensor([[[[ 0.3218, -0.1227, 0.5440, 0.3218, 0.0995, -0.1227, 0.7662],
[-0.1227, 0.0995, -0.1227, 0.3218, -0.1227, 0.9884, -0.1227],
[ 0.5440, -0.1227, 0.0995, -0.3449, 0.9884, -0.1227, 0.0995],
[ 0.3218, 0.3218, -0.3449, 0.5440, -0.3449, 0.3218, 0.3218],
[ 0.0995, -0.1227, 0.9884, -0.3449, 0.0995, -0.1227, 0.5440],
[-0.1227, 0.9884, -0.1227, 0.3218, -0.1227, 0.0995, -0.1227],
[ 0.7662, -0.1227, 0.0995, 0.3218, 0.5440, -0.1227, 0.3218]]]],
grad_fn=<DivBackward0>)
--------------- 池化 ---------------
torch.Size([1, 1, 4, 4])
tensor([[[[0.9722, 0.3055, 0.5278, 0.3055],
[0.3055, 0.9722, 0.3055, 0.5278],
[0.5278, 0.3055, 0.9722, 0.0833],
[0.3055, 0.5278, 0.0833, 0.7500]]]], grad_fn=<DivBackward0>)
tensor([[[[0.5629, 0.3406, 0.5629, 0.3406],
[0.3406, 1.0073, 0.5629, 0.1184],
[0.5629, 0.5629, 0.5629, 0.1184],
[0.3406, 0.1184, 0.1184, 0.3406]]]], grad_fn=<DivBackward0>)
tensor([[[[0.3218, 0.5440, 0.9884, 0.7662],
[0.5440, 0.5440, 0.9884, 0.3218],
[0.9884, 0.9884, 0.0995, 0.5440],
[0.7662, 0.3218, 0.5440, 0.3218]]]], grad_fn=<DivBackward0>)
--------------- 激活 ---------------
tensor([[[[0.7500, 0.0000, 0.0833, 0.3055, 0.5278, 0.0000, 0.3055],
[0.0000, 0.9722, 0.0000, 0.3055, 0.0000, 0.0833, 0.0000],
[0.0833, 0.0000, 0.9722, 0.0000, 0.0833, 0.0000, 0.5278],
[0.3055, 0.3055, 0.0000, 0.5278, 0.0000, 0.3055, 0.3055],
[0.5278, 0.0000, 0.0833, 0.0000, 0.9722, 0.0000, 0.0833],
[0.0000, 0.0833, 0.0000, 0.3055, 0.0000, 0.9722, 0.0000],
[0.3055, 0.0000, 0.5278, 0.3055, 0.0833, 0.0000, 0.7500]]]],
grad_fn=<DivBackward0>)
tensor([[[[0.3406, 0.0000, 0.1184, 0.0000, 0.1184, 0.0000, 0.3406],
[0.0000, 0.5629, 0.0000, 0.3406, 0.0000, 0.5629, 0.0000],
[0.1184, 0.0000, 0.5629, 0.0000, 0.5629, 0.0000, 0.1184],
[0.0000, 0.3406, 0.0000, 1.0073, 0.0000, 0.3406, 0.0000],
[0.1184, 0.0000, 0.5629, 0.0000, 0.5629, 0.0000, 0.1184],
[0.0000, 0.5629, 0.0000, 0.3406, 0.0000, 0.5629, 0.0000],
[0.3406, 0.0000, 0.1184, 0.0000, 0.1184, 0.0000, 0.3406]]]],
grad_fn=<DivBackward0>)
tensor([[[[0.3218, 0.0000, 0.5440, 0.3218, 0.0995, 0.0000, 0.7662],
[0.0000, 0.0995, 0.0000, 0.3218, 0.0000, 0.9884, 0.0000],
[0.5440, 0.0000, 0.0995, 0.0000, 0.9884, 0.0000, 0.0995],
[0.3218, 0.3218, 0.0000, 0.5440, 0.0000, 0.3218, 0.3218],
[0.0995, 0.0000, 0.9884, 0.0000, 0.0995, 0.0000, 0.5440],
[0.0000, 0.9884, 0.0000, 0.3218, 0.0000, 0.0995, 0.0000],
[0.7662, 0.0000, 0.0995, 0.3218, 0.5440, 0.0000, 0.3218]]]],
grad_fn=<DivBackward0>)