Skip to content

Instantly share code, notes, and snippets.

@benanne
Created January 28, 2015 13:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save benanne/ae2a7adaab133c61a059 to your computer and use it in GitHub Desktop.
Save benanne/ae2a7adaab133c61a059 to your computer and use it in GitHub Desktop.
Inception module in Lasagne (without 3x3s1 pooling)
import lasagne as nn
Conv2DLayer = nn.layers.Conv2DDNNLayer
def inception_module(l_in, num_1x1, reduce_3x3, num_3x3, reduce_5x5, num_5x5, gain=1.0, bias=0.1):
"""
inception module (without the 3x3s1 pooling and projection because that's difficult in Theano right now)
"""
shape = l_in.get_output_shape()
out_layers = []
# 1x1
if num_1x1 > 0:
l_1x1 = nn.layers.NINLayer(l_in, num_units=num_1x1, W=nn.init.Orthogonal(gain), b=nn.init.Constant(bias))
out_layers.append(l_1x1)
# 3x3
if num_3x3 > 0:
if reduce_3x3 > 0:
l_reduce_3x3 = nn.layers.NINLayer(l_in, num_units=reduce_3x3, W=nn.init.Orthogonal(gain), b=nn.init.Constant(bias))
else:
l_reduce_3x3 = l_in
l_3x3 = Conv2DLayer(l_reduce_3x3, num_filters=num_3x3, filter_size=(3, 3), border_mode="same", W=nn.init.Orthogonal(gain), b=nn.init.Constant(bias))
out_layers.append(l_3x3)
# 5x5
if num_5x5 > 0:
if reduce_5x5 > 0:
l_reduce_5x5 = nn.layers.NINLayer(l_in, num_units=reduce_5x5, W=nn.init.Orthogonal(gain), b=nn.init.Constant(bias))
else:
l_reduce_5x5 = l_in
l_5x5 = Conv2DLayer(l_reduce_5x5, num_filters=num_5x5, filter_size=(5, 5), border_mode="same", W=nn.init.Orthogonal(gain), b=nn.init.Constant(bias))
out_layers.append(l_5x5)
# stack
l_out = nn.layers.concat(out_layers)
return l_out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment