I have a series of matrices 30x30 matrices that contain elements ranging from 0 to 75 (input matrices) and each one has a 30x30 matrix containing only 1s and 0s (output matrices). I am trying to train a classifier on the input matrices to predict the output matrices, however I am not sure how to best represent the input matrices for the classifier (ideally sk-learn). I can't abstract the matrices to another form as each element from the input matrix must map to the element in the same location of the output matrix. Has anyone tried to something similar?
Option 1: Multi label classifier
You can flatten the 30X30 matrix into a 900 element vector and feed it to a neural network for multi label classification
https://en.wikipedia.org/wiki/Multi-label_classification
Treat 30X30 matrix as a single channel image and model a CNN with proper loss function for multi label classification.
Option 2: Sequence to Sequence classifier
Flatten the 30X30 matrix into a 900 element vector and build a LSTM with 900 timesteps with ith element in the vector being input to ith timestep. The LSTM is connected to a Dense layer with sigmoid activation (2 class classification). If you use keras for implementaiton you will have to use return_sequence=True for this.
Related
Image classification of RGB images in a Convolutional Neural Network is usually done by feeding the CNN first layer with a Numpy array with dimensions: pixel array by the number of channels. Example: [256 pixels] x [256 pixels] x [3 channels].
What is the impact on performance if applying a different Numpy array in a different order: say [256 pixels] x [3 channels] x [256 pixels], assuming that the CNN first layer structure is changed?
Does the CNN architecture of the sub-sequent layers need to be changed?
Would the model prediction accuracy be impacted?
My use case is a bit different where I have multiple features in a Numpy Array [ [X pixels],[Y pixels],[RGB channels],[ABC channels],[EF channels] ] and I'm concerned that the order of how the features are entered into the CNN will impact the model training.
I am trying to predict a matrix (size RxC) based on an input matrix (size RxC) and a list of floats L (length P). Essentially, I am trying to create an ML model to replace ray-tracing simulation. For each L, ray-tracing software will spend about 20-30 mins to generate a new matrix, so I was thinking of by-passing the ray-tracing by training an NN to predict the new matrix using a base-line input matrix and a list of float that contains the deviation of ray-tracing parameters from the base-line value.
There is a spatial relationship in the matrix i.e M[0,0] has a relationship with M[1,1]. But since I will also have a list of float as an input, I don't think using CNN will work, won't it?
Is there any known architecture to complete this task?
I am thinking to flatten the input (input dimension becomes R*C+P) and the output layer will also be flattened (dimension R*C).
Thanks a lot and any suggestion will be appreciated! Cheers!
I am trying to solve the problem of:
X*transpose(X) == const matrix
Where I need to find X (which is an N by N matrix).
I cannot figure out a way to represent X as the weights in keras. The dense layer forces a 1D shape. If I use Lambda with Embedding it won't accept the Embedding layer.
I am trying to log AUC during training time of my model.
According to the documentation, tf.metric.auc needs a label and predictions, both of same shape.
But in my case of binary classification, label is a one-dimensional tensor, containing just the classes. And prediction is two-dimensional containing probability for each class of each datapoint.
How to calculate AUC in this case?
Let's have a look at the parameters in the function tf.metrics.auc:
labels: A Tensor whose shape matches predictions. Will be cast to bool.
predictions: A floating point Tensor of arbitrary shape and whose values are in the range [0, 1].
This operation already assumes a binary classification. That is, each element in labels states whether the class is "positive" or "negative" for a single sample. It is not a 1-hot vector, which requires a vector with as many elements as the number of exclusive classes.
Likewise, predictions represents the predicted binary class with some level of certainty (some people may call it a probability), and each element should also refer to one sample. It is not a softmax vector.
If the probabilities came from a neural network with a fully connected layer of 2 neurons and a softmax activation at the head of the network, consider replacing that with a single neuron and a sigmoid activation. The output can now be fed to tf.metrics.auc directly.
Otherwise, you can just slice the predictions tensor to only consider the positive class, which will represent the binary class just the same:
auc_value, auc_op = tf.metrics.auc(labels, predictions[:, 1])
I am trying to classify a bunch of spectrograms into C classes using keras' LSTM (with a Dense Layer at the end). To clarify, each spectrogram belongs to a single class from those C classes. Each spectrogram is basically a matrix. It is constructed by taking (lets say, K) measurements at every second for about 1000 seconds. So the matrix has K rows and 1000 columns.
Considering this, how may I specify the shape of this input for the LSTM layer ?
Thank you!
It doesn't seem to be in the current documentation for LSTM layers, but input_shape can be provided as (timesteps, input_dim).
If each spectrogram to be classified has 1000 time steps and K measurements at each time step, an LSTM layer can be constructed like this:
LSTM(num_units, input_shape=(1000, K))
Then the shape of the input array for all of the spectrograms should have the shape (num_spectrograms, 1000, K).