Skip to content

Instantly share code, notes, and snippets.

@justheuristic
Created October 20, 2016 20:20
Show Gist options
  • Select an option

  • Save justheuristic/b11b0b972dfaf0cd7e65f2f15ede2f1b to your computer and use it in GitHub Desktop.

Select an option

Save justheuristic/b11b0b972dfaf0cd7e65f2f15ede2f1b to your computer and use it in GitHub Desktop.
from lasagne.layers import *
import theano
import numpy as np
def build_resmodule3(inp,filter_size=(3,3)):
assert(len(inp.output_shape))==4
n_filters = inp.output_shape[1]
nn = Conv2DLayer(inp,n_filters,filter_size,pad='same')
nn = batch_norm(nn) #inserts batchnorm before relu
nn = ElemwiseSumLayer([nn,inp])
return nn
nn = l0 = InputLayer((None,3,32,32))
nn = Conv2DLayer(nn,32,(3,3)) #first convolution
nn = build_resmodule3(nn,(3,3)) #resnet block
nn = build_resmodule3(nn,(3,3)) #resnet block
nn = Conv2DLayer(nn,64,(1,1)) #1x1 convolution to increase num units
nn = Pool2DLayer(nn,(2,2))
nn = build_resmodule3(nn,(3,3)) #resnet block
nn = build_resmodule3(nn,(3,3)) #resnet block
nn = DenseLayer(nn,1,nonlinearity=lambda a:1./(1+2.71**a))
predict = theano.function([l0.input_var],get_output(nn))
predict(np.zeros((10,3,32,32),dtype=theano.config.floatX))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment