{"action":"closed","issue":{"url":"https://api.github.com/repos/Lasagne/Lasagne/issues/507","labels_url":"https://api.github.com/repos/Lasagne/Lasagne/issues/507/labels{/name}","comments_url":"https://api.github.com/repos/Lasagne/Lasagne/issues/507/comments","events_url":"https://api.github.com/repos/Lasagne/Lasagne/issues/507/events","html_url":"https://github.com/Lasagne/Lasagne/issues/507","id":118024162,"number":507,"title":"Transfer learning in lasagne","user":{"login":"shashankg7","id":3889592,"avatar_url":"https://avatars.githubusercontent.com/u/3889592?v=3","gravatar_id":"","url":"https://api.github.com/users/shashankg7","html_url":"https://github.com/shashankg7","followers_url":"https://api.github.com/users/shashankg7/followers","following_url":"https://api.github.com/users/shashankg7/following{/other_user}","gists_url":"https://api.github.com/users/shashankg7/gists{/gist_id}","starred_url":"https://api.github.com/users/shashankg7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shashankg7/subscriptions","organizations_url":"https://api.github.com/users/shashankg7/orgs","repos_url":"https://api.github.com/users/shashankg7/repos","events_url":"https://api.github.com/users/shashankg7/events{/privacy}","received_events_url":"https://api.github.com/users/shashankg7/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-20T11:46:26Z","updated_at":"2015-11-20T14:04:34Z","closed_at":"2015-11-20T14:04:34Z","body":"I used following architecture of CNN to train on cifar10 dataset:\r\n```python\r\ndef build_cnn(input_var, input_shape=(3, 32, 32),\r\n              num_crp=3, crp_num_filters=128, crp_filter_size=5,\r\n              num_cr=1,\r\n              num_fc=1, fc_num_units=256,\r\n              output_type='softmax', num_classes=10,\r\n              **junk):\r\n    # input layer\r\n    network = lasagne.layers.InputLayer(shape=(None,) + input_shape,\r\n                                        input_var=input_var)\r\n    # conv-relu-pool layers\r\n    for i in range(num_crp):\r\n        network = lasagne.layers.Conv2DLayer(\r\n            network, num_filters=crp_num_filters,\r\n            filter_size=(crp_filter_size, crp_filter_size),\r\n            pad='same',\r\n            nonlinearity=lasagne.nonlinearities.rectify,\r\n            W=lasagne.init.GlorotUniform(gain='relu'))\r\n        network = lasagne.layers.MaxPool2DLayer(network, pool_size=(2, 2))\r\n    # conv-relu\r\n    for i in range(num_cr):\r\n        network = lasagne.layers.Conv2DLayer(\r\n            network, num_filters=crp_num_filters,\r\n            filter_size=(crp_filter_size, crp_filter_size),\r\n            pad='same',\r\n            nonlinearity=lasagne.nonlinearities.rectify,\r\n            W=lasagne.init.GlorotUniform(gain='relu'))\r\n    # fc-relu\r\n    for i in range(num_fc - 1):\r\n        network = lasagne.layers.DenseLayer(\r\n            lasagne.layers.dropout(network, p=.5),\r\n            num_units=fc_num_units,\r\n            nonlinearity=lasagne.nonlinearities.rectify)\r\n    # output layer\r\n    assert output_type=='softmax'\r\n    network = lasagne.layers.DenseLayer(\r\n        lasagne.layers.dropout(network, p=.5),\r\n        num_units=num_classes,\r\n        nonlinearity=lasagne.nonlinearities.softmax)\r\n    return network\r\n```\r\n\r\nI want to extract features from input once network is trained. Last two layers are fully connected NN for classification. I tried to extract from 3rd last layer using the following code:\r\n```python\r\n    net1 = lasagne.layers.get_all_layers(network)\r\n    feat_layer = lasagne.layers.get_output(net1[len(net1)-3])\r\n    input_variable = net1[0].input_var\r\n    f_output = theano.function([input_variable],feat_layer)\r\n    num_test = X_test.shape[0]\r\n    X = X_test[0][None,:,:]\r\n    instance = f_output(X)\r\n    for i in range(num_test):\r\n        instance = np.vstack((instance,f_output(X_test[i][None,:,:]).flatten()))\r\n```\r\n\r\nBut I am getting tensor of dimension (1,128,4,4) as output everytime I change layer from 3rd last to 4th last and so on. Where I am getting wrong, can anyone help?"}}