Gert Kommer
Gert Kommer

Reputation: 1243

Interpreting Tensorflow output

I have a small tensorflow network based on the pythonprogramming.net tutorial and the training works and the accuracy test is ~ 0.85. That is ok for now. I save the state of the network to a checkpoint. Now I am trying to test the network but I don't understand how to interpret the output. If for training I use 8 output neurons and the output of the test_neural_network is 3 how do I know what 3 corresponds to. My guess is that it is the third output neuron, but how do I know the order of the output neurons and what the third output neuron is?

def test_neural_network():
    prediction = neural_network_model(p_inputdata)
    with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())

        if path.isfile(temp_dir + "\\" + checkpointlabel + ".ckpt.index"):
            saver.restore(sess, temp_dir + "\\" + checkpointlabel + ".ckpt")

        with open(test_data_file, "r") as file:
            for line in file:
                testdata = np.array(re.split(csvseperatorRE, line.rstrip("\n"))[:-1])
                label    = re.split(csvseperatorRE, line.rstrip("\n"))[-1:][0]
                result = sess.run(tf.argmax(prediction.eval(feed_dict={p_inputdata: [testdata]}),1))

EDIT
Here is the training information and the results
Training labels:

Sebastiaan      [1 0 0 0 0 0 0 0]
Rob             [0 1 0 0 0 0 0 0]
Christina       [0 0 1 0 0 0 0 0]
Halleh          [0 0 0 1 0 0 0 0]
Vincent         [0 0 0 0 1 0 0 0]
MisterX         [0 0 0 0 0 1 0 0]
Frank           [0 0 0 0 0 0 1 0]
GerritJan       [0 0 0 0 0 0 0 1]

Results of test_neural_network function: O and X correctness based on the order of the traininglabels. I don't know if this is correct.

O = Correct
X = Not correct
[0-7] = result of test_neural_network
Name = expected result

X   [3] Christina
X   [3] Christina
O   [2] Christina
X   [3] Frank
X   [5] Frank
X   [3] Frank
X   [0] Frank
X   [2] Frank
X   [0] Frank
X   [3] GerritJan
X   [5] GerritJan
X   [1] GerritJan
O   [3] Halleh
O   [3] Halleh
O   [3] Halleh
X   [3] MisterX
X   [3] MisterX
X   [3] MisterX
X   [3] Rob
X   [3] Rob
X   [5] Rob
X   [5] Sebastiaan
X   [5] Sebastiaan
X   [5] Sebastiaan
X   [3] Vincent
X   [5] Vincent
X   [3] Vincent

Upvotes: 1

Views: 1431

Answers (1)

javidcf
javidcf

Reputation: 59681

As you indicate, your model has eight outputs. The meaning of each of these outputs is up to you! Or, more specifically, up to your data. The example seems to be a rather standard feed-forward model with ReLU activations and softmax cross-entropy as loss function (which is the typical choice for multi-class classification problems like the one you are presenting). As you indicate, each of the training examples is labelled with a vector of ones and zeros, each one representing a person, right? So the network will try to learn the right parameters so that, for example, when you give an example that belong to "Sebastiaan", the output is "big" in the first output and "small" in the rest of outputs; what is "big" and "small" depends on a number of things, but basically you will want to have the biggest value in the first position. The same for the rest of names.

If you look at how you compute result in test_neural_network:

result = sess.run(tf.argmax(prediction.eval(feed_dict={p_inputdata: [testdata]}),1))

You are using tf.argmax, which means "what is the index of the biggest value in this vector" (where "this vector" is the output of the neural network); so you are getting what the network "thinks" should be the name associated with the input that you have given, represented as a number (indices are zero-based, so I guess you are adding one to result before printing at some point).

So, in the end, the meaning and order of the outputs depend on the meaning and order of the labels.

Upvotes: 2

Related Questions