Transpose tensorboard embedding projections - tensorflow

My model is trying to predict scores for 163 items using variety of inputs. It uses keras on tensorflow backend.
Following the approach in Keras - Save image embedding of the mnist data set to capture layer weights, I am capturing embedding data for final layer which is Dense(163). Since final dense layer is getting 128 inputs, weights matrix is 128x163. In Tensorboard Projector, I can see it visualizes 128 points very well.
However when I try to map it to my real world items using meta data, I have 163 items names but Tensorboard Projecter is visualizing 128x163 weight matrix by dimension 0 i.e. 128 points. Is there any way to make it visualize points by dimension 1 (163 points) in Tensorboard Projector?

Related

Convert 2D Convolutionary Neural Networks to 1D Convolutionary Neural Networks in Tensorflow

Say I have some feature extracted and it is 10x10 data(maybe image or cepstrogram).
Usually I would feed this into my 2DConv and i ll be on my way.
My quesiton is if I had to convert this into 1D of 100 inputs what disadvantages would I get besides the obvious part where my filter would not be detecting the surrounding neighboors but only the previous and the next ones to detect pattern, which might lead to a worse performance.
And If I had to do this though, would I just reshape ,use reshape layer or use permute layer ?
Thanks
Yes, you are correct regarding the GNA, our Intel GNA hardware is natively support only 1D convolution and 2D convolutions is experimental.
This article (GNA Plugin - OpenVINO™ Toolkit) specifies the steps to add Permute layers before or after convolutions.
You could try both methods and see which one works for you.
Generally,the 1d convolution in TensorFlow is created with 2d convolution wrapping in reshape layers to add H dimension before 2d convolution and remove it after that.
At the same time MO inserts permutes before and after reshape layers since they change the interpretation of data.
For advantages & disadvantages of 2D/1D CNN you may refer to this detailed thread
In TensorFlow, these are the process to build CNN architecture:
Reshape input if necessary using tf.reshape() to match the convolutional layer you intend to build (for example, if using a 2D convolution, reshape it into three-dimensional format)
Create a convolutional layer using tf.nn.conv1d(), tf.nn.conv2d(), or tf.nn.conv3d, depending on the dimensionality of the input.
Create a poling layer using tf.nn.maxpool()
Repeat steps 2 and 3 for additional convolution and pooling layers
Reshape output of convolution and pooling layers, flattening it to prepare for the fully connected layer
Create a fully connected layer using tf.matmul() function, add an activation using, for example, tf.nn.relu() and apply a dropout using tf.nn.dropout()
Create a final layer for class prediction, again using tf.matmul()
Store weights and biases using TensorFlow variables These are just the basic steps to create the CNN model, there are additional steps to define training and evaluation, execute the model and tune it
In step 2 of CNN development you create convolutional layer of 2D using tf.nn.conv2d() - this function Computes a 2-D convolution given 4-D input and filters tensors.
So if you have 1D vector as found in examples of MNIST datadet with 784 features, you can convert 1D vector to 4D input required for conv2d() function using the tensorflow reshape method, Reshape method converts to match picture format [Height x Width x Channel], then Tensor input become 4-D: [Batch Size, Height, Width, Channel]:
x = tf.reshape(x, shape=[-1, 28, 28, 1])
where x is placeholder vector
x = tf.placeholder(tf.float32, [None, num_input])
You may refer to the official Tensorflow documentation

visualizing 2nd convolutional layer

So via tf.summary I visualized the first convolutional layer in my model, of shape [5,5,3,32], as a set of individual images, one per filter. so this layer has a filter of 5x5 dimensions, of depth 3, and there are 32 of them. Im viewing these filters as 5x5 color(RGB) images.
Im wondering how to generalize this to a second convolutional layer, and third and on...
shape of the second convolutional layer is [5,5,32,64].
my questions is how would I transform that tensor into individual 5x5x3 images?
with the first conv layer of shape [5,5,3,32] I visualize it by transposing first tf.transpose(W_conv1,(3,0,1,2)), and then having 32 5x5x3 images.
doing a tf.transpose(W_conv2,(3,0,1,2)) would produce a shape [64,5,5,32]. how would I then use those "32 color channels"? (Im know its not that simple :) ).
Visualization of higher level filters is usually done indirectly. To visualize a particular filter, you look for images that the filter would respond the most to. For that you perform gradient ascent in the space of images (instead of changing the parameters of the network like when you train the network, you change the input image).
You will understand it easier if you play with the following Keras code: https://github.com/keras-team/keras/blob/master/examples/conv_filter_visualization.py

How to modify the tensorflow loss function to suit multi labels on the same image

Tensorflow is fairly new to me and the way i would have the loss calculated on the mnist dataset was using the softmax_cross_entropy_with_logits function.
This function worked on that dataset due to the label input being a single label on each image
What im trying to do is to train a CNN on the mscoco dataset which has multiple labels on the same image with 80 classes total.
Is there a function that makes that possible?
My label input is currently somewhat a modified onehot representation, meaning that for each image i have a list of 80 elements having 0 for categories not in the image and 1 for categories present in an image
I.e. an image with a human and a dog would have a list of [0,1,0,0,1] assuming i have 5 classes with dogs and humans being in index 1 and 4
For multi-label classification problem, you can use the sigmoid function available in tensorflow (tf.nn.sigmoid_cross_entropy_with_logits). It would take the onehot encoded label input along with the final logits layer as its input.

Tensorflow autoencoders with one vector per input neuron

I'm new to tensorflow and Deep neural networks.
I'm currently trying to do anomaly detection on trajectories using autoencoders and i'm having an issue with my model.
I'm not able to get the right weight matrix / not sure how to do it.
Here is my model:
each input neuron of my encoder receive a vector with 4 features (this vector correspond to an observation which is a part of my trajectory).
The number of the input neurons correspond to the number of observation (which is 289).
I have a total of 336 trajectories which correspond to my batch
Therefore my input data shape is like (336,289,4)
I have two hidden layers; on each one we divide the number of the previous neurons by 2 so for h1 we have 144 neurons and h2 72 neurons
For my weights, i have:
weights = {
'encoder_h1': tf.Variable(tf.random_normal([336, n_hidden_1, 289])),
'encoder_h2': tf.Variable(tf.random_normal([336, n_hidden_2, n_hidden_1])),
'decoder_h1': tf.Variable(tf.random_normal([336, n_hidden_1, n_hidden_2])),
'decoder_h2': tf.Variable(tf.random_normal([336, n_input, n_hidden_1 ])),
}
and my activation function is a sigmoid like
tf.nn.sigmoid(tf.add(tf.matmul(weights['encoder_h1'],x),
biases['encoder_b1'])
But i'm afraid this gives a wheight matrix by trajectory or what i want is a weight matrix for all my trajectories, it should be a 2d tensor but i don't know how to proceed.
I tried many thing such as removing the 336 part from my weight shape but tensorflow says tha its not possible to do matmul on 3d and 2d tensor.
Do you have any idea on how to do?
Thanks in advance for your help

Possible to train Tensorflow Inception V3 models with images greater than 299x299?

Is it possible to train a Tensorflow Inception V3 model with an image size greater than size 299x299? Seems that the Inception V3 CNN is designed for this image size only.
As long as you do not include the fully connected (Dense) layers at the top, it should be fine to use a different image size.
You can do that by adding this argument while loading the model
base_model = InceptionV3(weights=weights, include_top=False)
The convolutional layer weights should be independent of the image size in general and hence you can use those weights. The FC layer of the pre-trained network with n fully connected nodes would have a weight matrix of size[m X n]. This layer will expect the input to that layer to be of size m. However, due to the change in image size, you will end up with a different value for m when you feed the image from the new dataset(convolution filter convolving on a different image size).
After adding new dense layers, you can fine-tune the network to train on the top layers alone (keeping the weights of the conv-blocks below it fixed).