Guest User

Untitled

a guest
Mar 17th, 2016
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. import lasagne as nn
  2. Conv2DLayer = nn.layers.Conv2DDNNLayer
  3.  
  4. def inception_module(l_in, num_1x1, reduce_3x3, num_3x3, reduce_5x5, num_5x5, gain=1.0, bias=0.1):
  5. """
  6. inception module (without the 3x3s1 pooling and projection because that's difficult in Theano right now)
  7. """
  8. shape = l_in.get_output_shape()
  9. out_layers = []
  10.  
  11. # 1x1
  12. if num_1x1 > 0:
  13. l_1x1 = nn.layers.NINLayer(l_in, num_units=num_1x1, W=nn.init.Orthogonal(gain), b=nn.init.Constant(bias))
  14. out_layers.append(l_1x1)
  15.  
  16. # 3x3
  17. if num_3x3 > 0:
  18. if reduce_3x3 > 0:
  19. l_reduce_3x3 = nn.layers.NINLayer(l_in, num_units=reduce_3x3, W=nn.init.Orthogonal(gain), b=nn.init.Constant(bias))
  20. else:
  21. l_reduce_3x3 = l_in
  22. 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))
  23. out_layers.append(l_3x3)
  24.  
  25. # 5x5
  26. if num_5x5 > 0:
  27. if reduce_5x5 > 0:
  28. l_reduce_5x5 = nn.layers.NINLayer(l_in, num_units=reduce_5x5, W=nn.init.Orthogonal(gain), b=nn.init.Constant(bias))
  29. else:
  30. l_reduce_5x5 = l_in
  31. 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))
  32. out_layers.append(l_5x5)
  33.  
  34. # stack
  35. l_out = nn.layers.concat(out_layers)
  36. return l_out
Add Comment
Please, Sign In to add comment