Tag Archives: tf.nn.top_k(input

tf.nn.top_k(input, k, name=None) & tf.nn.in_top_k(predictions, targets, k, name=None)

tf.nn.top_ k(input, k, name=None)

This function returns the maximum number of K input rows and the index of their location

Input: a tensor. The data type must be one of the following: float32, float64, int32, Int64, uint8, int16, int8. The data dimension is batch_ Multiply size by X categories
k: an integer must be & gt= 1。 In each row, find the largest K values
Name: give this operation a name<

output: a tuple tensor, and the data element is (values, indexes), as follows:
values: a tensor, and the data type is the same as input. The data dimension is batch_ Size multiplied by K maximum
indicators: a tensor whose data type is int32. The index position of each maximum value in input

tf.nn.in_ top_ k(predictions, targets, k, name=None)

It is to compare whether predictions and targets are the same, return true if they are the same, and return false if they are different. Next, tf.cast (correct, TF. Floatxx) can be used to calculate the accuracy
predictions: the prediction result, and the prediction matrix size is the number of samples × Two dimensional matrix of the number of labeled label classes
targets: the actual tag size is the number of samples
k: whether the first k largest numbers of the prediction results of each sample contain the tags in the targets prediction is generally taken as 1, that is, the index of the maximum probability of prediction is taken to compare with the tags
Name: name