Nvidia DIGITS - more than top 5 predicted classes - neural-network

I am using nvidia-digits to train a CNN and get predictions. However the .../classify_one.json returns top 5 predictions by default. I need a larger n, how can I modify my request param to get the top n for example?
I couldn't find anything in DIGITS documentation.

Try modifying the accuracy_param of your top "Accuracy" layer of the model's prototxt file. You should have something like
accuracy_param {
top_k: 5
}
Change the top_k: 5 to the number you wish to get, e.g., top_k: 10 for getting top 10 classes.

Related

Swift MPSCNNConvolution -- weights all set to 1, shouldn't the output look just like the input?

Trying to figure out how to use MPSCNNConvolution. I have a 4 x 3 image, and a 4 x 3 kernel. I'm setting all the weights to 1, and all the inputs to 1, and I sort of expected to get all 1's back. What I get instead is
12 9 6 3
8 6 4 2
4 3 2 1
The problem is that I don't know whether it's supposed to behave like this or not. I've been all over every shred of Apple doc I can find, every online article, every github repo, and I can't find anything that says what kind of output to expect when the layer is set up correctly.
The pattern holds for differently sized images. A 3 x 2 gives me
6 4 2
3 2 1
And a 2 x 2 gives me
4 2
2 1
I've pushed my "minimal" example to github. It's not small. Xcode 12.4 no longer supports Float16, so there's utility code for floating between Float16 and Float32, plus all the convoluted setup for convolution, and yet more code for trying to un-headache un-safe pointers.
My specific questions: is this output "just the normal behavior" for MPSCNNConvolution? Is there a name for this function/algorithm, something I can look up?
The documentation for MPSCNNConvolution is slightly confusing. To the uninitiated, it might seem that MPSCNNConvolution is a kind of container that holds convolution kernels. This is not the case. MPSCNNConvolution is itself a kernel. Specifically, it weights and sums all the input values under the kernel window. Just a straight sum, no averaging or maxing. What you're seeing is the result of the kernel starting at (0, 0) and sliding way off the right edge, and eventually way off the bottom edge.
Set your kernel offset and your clip rectangle on the input image, and MPSCNNConvolution will work the same way as MPSCNNPooling* kernels and all the others

Multi-Output Multi-Class Keras Model

For each input I have, I have a 49x2 matrix associated. Here's what 1 input-output couple looks like
input :
[Car1, Car2, Car3 ..., Car118]
output :
[[Label1 Label2]
[Label1 Label2]
...
[Label1 Label2]]
Where both Label1 and Label2 are LabelEncode and they have respectively 1200 and 1300 different classes.
Just to make sure this is what we call a multi-output multi-class problem?
I tried to flatten the output but I feared the model wouldn't understand that all similar Label share the same classes.
Is there a Keras layer that handle output this peculiar array shape?
Generally, multi-class problems correspond with models outputting a probability distribution over the set of classes (that is typically scored against the one-hot encoding of the actual class through cross-entropy). Now, independently of whether you are structuring it as one single output, two outputs, 49 outputs or 49 x 2 = 98 outputs, that would mean having 1,200 x 49 + 1,300 x 49 = 122,500 output units - which is not something a computer cannot handle, but maybe not the most convenient thing to have. You could try having each class output to be a single (e.g. linear) unit and round it's value to choose the label, but, unless the labels have some numerical meaning (e.g. order, sizes, etc.), that is not likely to work.
If the order of the elements in the input has some meaning (that is, shuffling it would affect the output), I think I'd approach the problem through an RNN, like an LSTM or a bidirectional LSTM model, with two outputs. Use return_sequences=True and TimeDistributed Dense softmax layers for the outputs, and for each 118-long input you'd have 118 pairs of outputs; then you can just use temporal sample weighting to drop, for example, the first 69 (or maybe do something like dropping the 35 first and the 34 last if you're using a bidirectional model) and compute the loss with the remaining 49 pairs of labellings. Or, if that makes sense for your data (maybe it doesn't), you could go with something more advanced like CTC (although Keras does not have it, I'm trying to integrate TensorFlow implementation into it without much sucess), which is also implemented in Keras (thanks #indraforyou)!.
If the order in the input has no meaning but the order of the outputs does, then you could have an RNN where your input is the original 118-long vector plus a pair of labels (each one-hot encoded), and the output is again a pair of labels (again two softmax layers). The idea would be that you get one "row" of the 49x2 output on each frame, and then you feed it back to the network along with the initial input to get the next one; at training time, you would have the input repeated 49 times along with the "previous" label (an empty label for the first one).
If there are no sequential relationships to exploit (i.e. the order of the input and the output do not have a special meaning), then the problem would only be truly represented by the initial 122,500 output units (plus all the hidden units you may need to get those right). You could also try some kind of middle ground between a regular network and a RNN where you have the two softmax outputs and, along with the 118-long vector, you include the "id" of the output that you want (e.g. as a 49-long one-hot encoded vector); if the "meaning" of each label at each of the 49 outputs is similar, or comparable, it may work.

How do I interpret pycaffe classify.py output?

I created a GoogleNet Model via Nvidia DIGITS with two classes (called positive and negative).
If I classify an image with DIGITS, it shows me a nice result like positive: 85.56% and negative: 14.44%.
If it pass that model it into pycaffe's classify.py with the same image, I get a result like array([[ 0.38978559, -0.06033826]], dtype=float32)
So, how do I read/interpret this result? How do I calculate the confidence levels (not sure if this is the right term) shown by DIGITS from the results shown by classify.py?
This issue led me to the solution.
As the log shows, the network produces three outputs. Classifier#classify only returns the first output. So e.g. by changing predictions = out[self.outputs[0]] to predictions = out[self.outputs[2]], I get the desired values.

What would be a good neural net model for pick 3 lotteries?

This is just for fun to see if neural network predictions increase my odds of getting pick 3 lotteries correct.
Right now i just have a simple model of 30 input units, 30 hidden units, and 30 output units.
30 because if the pick 3 result was something like 124, i would make so that all my inputs are 0's except input[1] = 1 (because i assign 0 to 9 for the first digit), input[12] = 1 (because i assign 10 to 19 for the middle digit), input[24] = 1 (because i assign 20 to 29 for the last digit). I just do that so that my inputs are able store placement of digits.
i am training it so that if enter inputs for one draw, it gives me outputs for the next draw.
Do you know of a better model (if you have had experience with neural networks that dealt with pick3 lotteries)?

Why newff() does not work properly when I use its arguments!

My data-set includes 29 inputs and 6 outputs. When I use
net = newff(minmax(Pl),[14 12 8 6]);
to build my feed forward MLP network and train it by
net.trainParam.epochs=50;
net=train(net,Pl,Tl);
the network can not learn my data-set and its error does not decrease below 0.7, but when I use arguments of newff function like this:
net=newff(minmax(Pl),[14 12 8 6],{'tansig' 'tansig' 'tansig' 'purelin'},'trainlm');
the error is decreased very fast and it comes below 0.0001! The unusual note is that when I use the previous code using only one layer including 2 neurons:
net=newff(minmax(Pl),[2 6],{'tansig' 'purelin'},'trainlm');
the error is decreased below 0.2 again and it is doubtful!
Please give me some tips and help me to know what is difference between:
net = newff(minmax(Pl),[14 12 8 6]);
and
net=newff(minmax(Pl),[14 12 8 myANN.m],{'tansig' 'tansig' 'tansig' 'purelin'},'trainlm');
?
I think that the second argument to NEWFF (link requires login) is supposed to be the target vectors, not the size of hidden layers (which is the third argument).
Note that the default transfer function for hidden layers is tansig and for output layer is purelin, and the default training algorithm is trainlm.
Finally, remember that if you want to get reproducible results, you have to manually reset the random number generator to a fixed state at the beginning of each run.