我的意思并不是整个层到另一个整个层的跳跃连接,我的意思是某个层 L1 中的单个神经元到某个层 L2 中的另一个神经元的单个连接。
我想,你可以选择相应的张量通道。从经典的ResNet开始, https://github.com/pytorch/vision/blob/a9a8220e0bcb4ce66a733f8c03a1c2f6c68d22cb/torchvision/models/resnet.py#L56-L72
def forward(self, x):
identity = x
out = self.conv1(x)
...
if self.downsample is not None:
identity = self.downsample(x)
out += identity
...
将更改为
# NCHW layout assumed
out[:, C2,:,:] += identity[:, C1,:,:]
这里 C2 是所需目标通道(神经元)的索引,C1 - 源通道。