-
参数绑定
在不同的网络之间共享权重
shared = nn.Linear(8, 8) net = nn.Sequential(nn.Linear(4, 8), nn.ReLU(), shared, nn.ReLU(), shared, nn.ReLU(), nn.Linear(8, 1)) print(net[2].weight.data[0] == net[4].weight.data[0]) # tensor([True, True, True, True, True, True, True, True]) net[2].weight.data[0, 0] = 100 print(net[2].weight.data[0] == net[4].weight.data[0]) # tensor([True, True, True, True, True, True, True, True])
16 PyTorch神经网络基础 [动手学深度学习v2]
最新推荐文章于 2024-09-09 17:08:45 发布