GCN模块的实现比较简单,在giuhub上看到两种实现,轻微不同
实现一:https://github.com/ycszen/pytorch-segmentation/blob/master/gcn.py
class GCN(nn.Module): def __init__(self, inplanes, planes, ks=7): super(GCN, self).__init__() self.conv_l1 = nn.Conv2d(inplanes, planes, kernel_size=(ks, 1), padding=(ks/2, 0)) self.conv_l2 = nn.Conv2d(planes, planes, kernel_size=(1, ks), padding=(0, ks/2)) self.conv_r1 = nn.Conv2d(inplanes, planes, kernel_size=(1, ks), padding=(0, ks/2)) self.conv_r2 = nn.Conv2d(planes, planes, kernel_size=(ks, 1), padding=(ks/2, 0)) def forward(self, x): x_l = self.conv_l1(x) x_l = self.conv_l2(x_l) x_r = self.conv_r1(x) x_r = self.conv_r2(x_r) x = x_l + x_r return x
实现二:https://github.com/ogvalt/large_kernel_matters/blob/master/scripts/model.py
class GCN(nn.Module): def __init__(self, inchannels, channels=21, k=3): super(GCN, self).__init__() self.conv_l1 = Conv2D(in_channels=inchannels, out_channels=channels, kernel_size=(k, 1), padding='same') self.conv_l2 = Conv2D(in_channels=channels, out_channels=channels, kernel_size=(1, k), padding='same') self.conv_r1 = Conv2D(in_channels=inchannels, out_channels=channels, kernel_size=(1, k), padding='same') self.conv_r2 = Conv2D(in_channels=channels, out_channels=channels, kernel_size=(k, 1), padding='same') def forward(self, x): x1 = self.conv_l1(x) x1 = self.conv_l2(x1) x2 = self.conv_r1(x) x2 = self.conv_r2(x2) out = x1 + x2 return out
两种实现不同之处在padding的方式,一种是设定值,一种是自动的。