Skip to content

Instantly share code, notes, and snippets.

@rosenfeldamir
Last active September 26, 2017 20:22
Show Gist options
  • Save rosenfeldamir/471b157f2081e38e672d11bc91479e1d to your computer and use it in GitHub Desktop.
Save rosenfeldamir/471b157f2081e38e672d11bc91479e1d to your computer and use it in GitHub Desktop.
create multiple convolutions to work on a single input in parallel.
def makeSomeLayers(in_channels,out_channels,resolutions):
layers = []
for r in resolutions:
layers.append(nn.Conv2d(in_channels=in_channels,out_channels=out_channels,kernel_size=r))
return layers
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
in_channels = 3
out_channels = 64
resolutions = [3,5,7,9,11]
self.convs = nn.ModuleList(makeSomeLayers(in_channels,out_channels,resolutions))
def forward(self,x):
# call the various defined operations on the input...
outs = [op(x) for op in self.convs]
# do something with output...
x = .....
return x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment