我是深度学习和Pytorch的新手。我想在我的CNN模型中可视化滤波器,以便可以迭代我定义的CNN模型中的层。但我遇到了如下错误。
错误信息:'CNN' object is not iterable。
CNN对象是我的模型。
我的迭代代码如下:
for index, layer in enumerate(self.model):
# Forward pass layer by layer
x = layer(x)
我的模型代码如下:
class CNN(nn.Module):
def __init__(self):
super(CNN,self).__init__()
self.Conv1 = nn.Sequential( # input image size (1,28,20)
nn.Conv2d(1, 16, 5, 1, 2), # outputize (16,28,20)
nn.ReLU(),
nn.MaxPool2d(2), #outputize (16,14,10)
)
self.Conv2 = nn.Sequential( # input ize ? (16,,14,10)
nn.Conv2d(16, 32, 5, 1, 2), #output size(32,14,10)
nn.ReLU(),
nn.MaxPool2d(2), #output size (32,7,5)
)
self.fc1 = nn.Linear(32 * 7 * 5, 800)
self.fc2 = nn.Linear(800,500)
self.fc3 = nn.Linear(500,10)
#self.fc4 = nn.Linear(200,10)
def forward(self,x):
x = self.Conv1(x)
x = self.Conv2(x)
x = x.view(x.size(0), -1)
x = self.fc1(x)
x = F.dropout(x)
x = F.relu(x)
x = self.fc2(x)
x = F.dropout(x)
x = F.relu(x)
x = self.fc3(x)
#x = F.relu(x)
#x = self.fc4(x)
return x
有人能告诉我如何解决这个问题吗?