"mask cannot be scalar" in keras.max() function

Viewed 837

When I used Keras.max(box_scores,keep_dims=False) in an assignment, I got an error, and it was "mask cannot be scalar". But when I used Keras.max(box_scores,axis=-1,keep_dims=False) , I got the result. But I don't understand it.What is the purpose of axis=-1 in this function to correct this error?

box_scores = box_confidence * box_class_probs
box_classes = K.argmax(box_scores, axis=-1) 
box_class_scores = K.max(box_scores,keepdims=False)
filtering_mask = ((box_class_scores)>=threshold)
scores = tf.boolean_mask(box_class_scores,filtering_mask ,name="filtering_scores")
boxes = tf.boolean_mask(boxes,filtering_mask ,name="filtering_boxes")
classes = tf.boolean_mask(box_classes,filtering_mask ,name="filtering_classes")

Here, box_confidence = tensor of shape (19, 19, 5, 1), boxes -- tensor of shape (19, 19, 5, 4), box_class_probs -- tensor of shape (19, 19, 5, 80), and threshold -- real value, if [ highest class probability score < threshold], then get rid of the corresponding box.

enter image description here

1 Answers

For max function axis parameter specifies a list of dimensions (or one dimension or None for all dimensions) over which max is computed. When negative integers are used they are interpreted similarly to Python negative indicies of array (i.e. -1 means the last dimension, -2 - second from last, etc.).

So when you're not specifying axis argument the default value None is used resulting in scalar output (i.e. maximum of all values in the tensor). When you are specifying axis=-1 only the last dimension is reduced so from tensor of shape (a,b,c,d) you'll get a tensor of shape (a,b,c).

Strangely, keras documentation doesn't specify it here max reference.

Related