class A(nn.Module):
def __init__(self):
super().__init__()
self.conv = nn.Conv2d(in_channels=256, out_channels=32,
kernel_size=9, stride=2, padding=0)
def forward(self, x):
return self.conv(x)
class B(nn.Module):
def __init__(self):
super().__init__()
self.capsules = nn.ModuleList([
nn.Conv2d(in_channels=256, out_channels=32,
kernel_size=9, stride=2, padding=0)
for _ in range(8)])
def forward(self, x):
...
class C(nn.Module):
def __init__(self):
super().__init__()
self.capsules = nn.ModuleList([A() for _ in range(8)])
def forward(self, x):
...
spanev
(Serge Panev)
2
Hi @vainaijr,
The only difference is when you try to access the convolutions.
Let’s say you want to access the first conv.
In C case you have to do:
c.capsules[0].conv
and in B case you can simply do:
b.capsules[0]
Except from that, running them would give you exactly the same result. A is just a wrapper forwarding x
to Conv2d.