1 year ago
#245521
HATEM EL-AZAB
How to traverse model layers as a tree in theano/lasagne?
I need to traverse the model's layers by tree levels, such that getting the ancestor(input) and predecessor(output) layers and the adjacent layers in the same level.
here's a model as an example:
import lasagne
def toy_model():
l_input = lasagne.layers.InputLayer(shape=(None, inp_len, n_inputs))
l_dim_a = lasagne.layers.DimshuffleLayer(l_input, (0, 2, 1))
l_conv_a = lasagne.layers.Conv1DLayer(
incoming=l_dim_a, num_filters=16, pad='same',
filter_size=3, stride=1, nonlinearity=lasagne.nonlinearities.rectify)
l_conv_a_b = lasagne.layers.batch_norm(l_conv_a)
l_conv_b = lasagne.layers.Conv1DLayer(
incoming=l_dim_a, num_filters=16, pad='same',
filter_size=3, stride=1, nonlinearity=lasagne.nonlinearities.rectify)
l_conv_b_b = lasagne.layers.batch_norm(l_conv_b)
l_conv_c = lasagne.layers.Conv1DLayer(
incoming=l_dim_a, num_filters=16, pad='same',
filter_size=3, stride=1, nonlinearity=lasagne.nonlinearities.rectify)
l_conv_c_b = lasagne.layers.batch_norm(l_conv_c)
l_c_a = lasagne.layers.ConcatLayer([l_conv_a_b, l_conv_b_b, l_conv_c_b], axis=1)
l_dim_b = lasagne.layers.DimshuffleLayer(l_conv_c, (0, 2, 1))
l_c_b = lasagne.layers.ConcatLayer([l_input, l_dim_b], axis=2)
l_reshape = lasagne.layers.ReshapeLayer(l_c_b, (batch_size* inp_len, n_inputs + (3*3) ))
l_FC = lasagne.layers.DenseLayer(l_reshape, num_units=200, nonlinearity=lasagne.nonlinearities.rectify)
l_prop = lasagne.layers.DenseLayer(l_FC, num_units=n_classes, nonlinearity=lasagne.nonlinearities.softmax)
l_output = lasagne.layers.ReshapeLayer(l_prop, (batch_size, inp_len, n_classes))
return l_input, l_output
providing an example, if any, will be helpful.
python
tensorflow
deep-learning
theano
lasagne
0 Answers
Your Answer