【问题标题】:How can I see the first filters of a convolution layer如何查看卷积层的第一个过滤器
【发布时间】:2021-06-21 03:35:02
【问题描述】:

来自blog post,据说如果你想直接看内核过滤矩阵,我们可以得到权重张量并相应地索引它。现在我想看看我层的第一个过滤器的第一个内核。

从博客中,提到我可以使用这个conv1.weight[1,1,:,:] 如何将它用于以下模型架构。

class Cifar10CnnModel(ImageClassificationBase):
    def __init__(self):
        super().__init__()
        self.network = nn.Sequential(
            nn.Conv2d(3, 32, kernel_size=3, padding=1),
            nn.ReLU(),
            nn.Conv2d(32, 64, kernel_size=3, stride=1, padding=1),
            nn.ReLU(),
            nn.MaxPool2d(2, 2), # output: 64 x 16 x 16

            nn.Conv2d(64, 128, kernel_size=3, stride=1, padding=1),
            nn.ReLU(),
            nn.Conv2d(128, 128, kernel_size=3, stride=1, padding=1),
            nn.ReLU(),
            nn.MaxPool2d(2, 2), # output: 128 x 8 x 8

            nn.Conv2d(128, 256, kernel_size=3, stride=1, padding=1),
            nn.ReLU(),
            nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1),
            nn.ReLU(),
            nn.MaxPool2d(2, 2), # output: 256 x 4 x 4

            nn.Flatten(), 
            nn.Linear(256*4*4, 1024),
            nn.ReLU(),
            nn.Linear(1024, 512),
            nn.ReLU(),
            nn.Linear(512, 10))
        
    def forward(self, xb):
        return self.network(xb)

【问题讨论】:

    标签: python neural-network pytorch conv-neural-network


    【解决方案1】:

    如果您通过以下方式创建模型:

    model = Cifar10CnnModel()
    

    然后您的权重将存储在顺序模型中,并且可以通过选择顺序模型列表的第一个元素来访问:

    model.network[0].weights
    

    【讨论】:

      猜你喜欢
      • 2019-11-28
      • 1970-01-01
      • 2021-09-11
      • 1970-01-01
      • 2017-11-22
      • 1970-01-01
      • 2018-11-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多