Skip to content

Instantly share code, notes, and snippets.

@fmder
Created August 28, 2015 13:19
Show Gist options
  • Save fmder/de72992071a12ddf4c68 to your computer and use it in GitHub Desktop.
Save fmder/de72992071a12ddf4c68 to your computer and use it in GitHub Desktop.
import lasagne
import numpy
import theano
import theano.tensor as T
def get_data():
return numpy.random.randn(200, 32, 32), numpy.random.randint(2, size=(200, 1))
def build_ae(input_shape, input_var):
l_in = lasagne.layers.InputLayer(shape=input_shape, input_var=input_var)
# l_hid = lasagne.layers.Conv1DLayer(l_in, num_filters=32, filter_size=3,
# nonlinearity=lasagne.nonlinearities.rectify,
# W=lasagne.init.GlorotUniform())
l_hid = lasagne.layers.Conv1DLayer(l_in, num_filters=32, filter_size=3, stride=2,
nonlinearity=lasagne.nonlinearities.rectify,
W=lasagne.init.GlorotUniform())
l_out = lasagne.layers.InverseLayer(l_hid, l_hid)
return l_out
def main():
X, y = get_data()
input_var = T.tensor3('inputs')
data_shape = (None, X.shape[1], X.shape[2])
network = build_ae(data_shape, input_var)
prediction = lasagne.layers.get_output(network)
loss = lasagne.objectives.squared_error(prediction, input_var)
loss = loss.mean()
params = lasagne.layers.get_all_params(network, trainable=True)
updates = lasagne.updates.nesterov_momentum(loss, params, learning_rate=0.01, momentum=0.9)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment