Skip to content

Instantly share code, notes, and snippets.

@ajbrock
Last active March 16, 2020 13:19
Show Gist options
  • Save ajbrock/989426336f2d7e37414ed09a6fd4692f to your computer and use it in GitHub Desktop.
Save ajbrock/989426336f2d7e37414ed09a6fd4692f to your computer and use it in GitHub Desktop.
import theano
import lasagne.layers
from lasagne.layers import Conv2DLayer as C2D
from lasagne.nonlinearities import rectify as relu
from lasagne.layers import NonlinearityLayer as NL
from lasagne.layers import ElemwiseSumLayer as ESL
from lasagne.layers import batch_norm as BN
l_in = lasagne.layers.InputLayer(shape=(None,3,64,64)) # Assume incoming shape is a batch x RGB x W x H image
encoder_stem = C2D(
incoming = l_in,
num_filters = 128,
filter_size = [5,5],
stride = [2,2],
pad = (2,2),
nonlinearity = None,
name = 'encoder_stem'
)
encoder_residual_block1 = ESL([C2D(incoming = NL(BN(C2D(
incoming = NL(BN(encoder_stem,name='encoder_stem_bnorm'),relu),
num_filters = 128,
filter_size = [3,3],
stride = [1,1],
pad = (1,1),
nonlinearity = None,
name = 'enc_res1_1'),name='enc_res1_bnorm'),relu),
num_filters = 128,
filter_size = [3,3],
stride = [1,1],
pad = (1,1),
nonlinearity = None,
name = 'enc_res1_2'),
encoder_stem])
encoder_downsample1=C2D(
incoming = encoder_residual_block1,
num_filters = 256,
filter_size = [5,5],
stride = [2,2],
pad = (2,2),
nonlinearity = None,
name = 'encoder_downsample1'
)
encoder_residual_block2 = ESL([C2D(incoming = NL(BN(C2D(
incoming = NL(BN(encoder_downsample1,name='encoder_downsample1_bnorm'),relu),
num_filters = 128,
filter_size = [3,3],
stride = [1,1],
pad = (1,1),
nonlinearity = None,
name = 'enc_res2_1'),name='enc_res2_bnorm'),relu),
num_filters = 128,
filter_size = [3,3],
stride = [1,1],
pad = (1,1),
nonlinearity = None,
name = 'enc_res2_2'),
encoder_stem])
encoder_mlp = BN(lasagne.layers.DenseLayer(NL(BN(encoder_residual_block2,name='enc_resblock2_bnorm'),relu),num_units=500,nonlinearity=relu),name='enc_mlp_bnorm')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment