How to transpose the output of the previous layer in dl4j - machine-learning

I am very new to dl4j and I can't seem to find a layer for transposing the output of the previous layer.
Is this something that is supported in the project or do I need to make a custom layer?

Related

How do you tell a neural network's layer to look for/at specific traits such as eyes, and edges?

In an face recognition image classification, I understand that each layer looks at different key aspects of the image?
For example, layer-1 might look at the edges, and layer-2 might look at the colors, and layer-3 might look at the eyes, etc...
Each layer has an activation function, and takes the output from the previous layer as input.
How do you specifically tell a layer to look for a specific trait in the image?
How do you know what each layer is looking for?
To know what features of the input image a layer of deep CNN is looking for, you can obtain the filters and filter activations/ feature maps of that layer and visualize them by plotting color-maps of the activations and kernel weights. Though we can visualize the activations of a layer and infer what the filter might be looking for, it is rather hard to enforce a network's layer to learn specific traits as the weights are randomly initialized before training such that any filter of the network might choose to learn any random specific feature of the input image.

How to add new vector to Keras embedding matrix

Background
I am using an embedding layer for a categorical data column in Keras.
My understanding is that an embedding layer is simply a matrix which consist of trainable vectors, each mapped to an index.
My problem
After training finished, I want to add a new index-vector pair to the embedding matrix.
(The vector is generated by me, no training involved at this stage.)
How do I do this?
I wish to use the newly added embedding in predictions as well.
Code
keras.layers.Embedding(number_of_categories, embedding_size, input_length=1)
I am especially stuck, since number of categories are coded in the model architecture. Is there any way around this?

Crop specific area in caffe layer

I am building an image classification in caffe. All images are fixed size and I know their nature. Now I want to guide Neural Network to look closer to the specific area, as I know that this area carries a lot of information. And in the end, I want to combine to layer stacks back. This is what I achieved with a custom python layer which crops a specific area for me.
The thing is Python layer even doing its job is very slow. I know about caffe crop layer, but it looks like it doesn't do what I want, as far as I understood it only aligns 1 shape to another, However, I can't specify are direct.
Am I missing something here? It looks like it should be simpler solution here.
The solution is to use Crop layer with DummyData layer as a second bottom layer

What does global pooling do?

I recently found the "global_pooling" flag in the Pooling layer in caffe, however was unable to find sth about it in the documentation here (Layer Catalogue)
nor here (Pooling doxygen doc) .
Is there an easy forward examply explanation to this in comparison to the normal Pool-Layer behaviour?
With Global pooling reduces the dimensionality from 3D to 1D. Therefore Global pooling outputs 1 response for every feature map. This can be the maximum or the average or whatever other pooling operation you use.
It is often used at the end of the backend of a convolutional neural network to get a shape that works with dense layers. Therefore no flatten has to be applied.
Convolutions can work on any image input size (which is big enough). However, if you have a fully connected layer at the end, this layer needs a fixed input size. Hence the complete network needs a fixed image input size.
However, you can remove the fully connected layer and just work with convolutional layers. You can make a convolutional layer at the end which has the same number of filters as you have classes. But you want one value for each class which indicates the probability of that class. Hence you apply a pooling filter over the complete remaining feature map. This pooling is hence "global" as it always is as big as necessary. In contrast, usual pooling layers have a fixed size (e.g. of 2x2 or 3x3).
This is a general concept. You can also find global pooling in other libraries, e.g. Lasagne. If you want a good reference in literature, I recommend reading Network In Network.
We get only one value from entire feature map when we apply GP layer, in which kernel size is the h×w of the feature map. GP layers are used to reduce the spatial dimensions of a three-dimensional feature map. However, GP layers perform a more extreme type of dimensionality reduction, where a feature map with dimensions h×w×d is reduced in size to have dimensions 1×1×d. GP layers reduce each h×w feature map to a single number by simply taking the average of all hw values.
If you are looking for information regarding flags/parameters of caffe, it is best look them up in the comments of '$CAFFE_ROOT/src/caffe/proto/caffe.proto'.
For 'global_pooling' parameter the comment says:
// If global_pooling then it will pool over the size of the bottom by doing
// kernel_h = bottom->height and kernel_w = bottom->width
For more information about caffe layers, see this help pages.

Gradients in deepdream

I'm trying to implement deepdream in theano. As far as I understood I need to choose a layer in a pre-trained neural network to be the objective , then I need to set the activation functions of that layer to be equal to gradients, then backpropagate to the input image and finally apply the changes.
I'm new to theano and I can't think of how to implement it, how can I set the layer's values to be equal to gradients and backpropagate back to image? Is it possible to do in a couple of lines in theano?
Also if my understanding is wrong, please correct me.

Resources