python - 如何查看卷积层的第一个过滤器
问题描述
从这篇博文中,据说如果您想直接查看内核过滤器矩阵,我们可以获取权重张量并相应地对其进行索引。现在我想看看我层的第一个过滤器的第一个内核。
从博客中,有人提到我可以使用这个conv1.weight[1,1,:,:]
How do use this for the following model architecture。
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)
解决方案
如果您通过以下方式创建模型:
model = Cifar10CnnModel()
那么您的权重将存储在顺序模型中,并且可以通过选择顺序模型列表的第一个元素来访问:
model.network[0].weights
推荐阅读
- image - VSTO 自定义功能区图标图像质量
- nginx - “/run/nginx.pid”中的无效PID号“”
- asp.net-mvc - 从单个 MVC 方法返回 Response.Redirect 或 ActionResult
- r - R中的ValueBox - 仅显示数字
- swift - Swift 4 Codable - API 有时提供 Int 有时提供 String
- neo4j - 基于字符串和数组的NEO4j / Cyhper配对节点
- docker - 如何使用 Jenkins 将镜像推送到 DTR Docker 可信存储库
- selenium - 如何将浏览器名称附加到黄瓜范围报告左侧的特征
- spring - 在 Spring 中安排多个任务
- nginx - 如何使用 Nginx 和 Docker 代理应用程序