Mask cannot be scalar

ValueError Traceback (most recent call last)
in
4 boxes = tf.random.normal([19, 19, 5, 4], mean=1, stddev=4, seed = 1)
5 box_class_probs = tf.random.normal([19, 19, 5, 80], mean=1, stddev=4, seed = 1)
----> 6 scores, boxes, classes = yolo_filter_boxes(boxes, box_confidence, box_class_probs, threshold = 0.5)
7 print("scores[2] = " + str(scores[2].numpy()))
8 print("boxes[2] = " + str(boxes[2].numpy()))

in yolo_filter_boxes(boxes, box_confidence, box_class_probs, threshold)
41 # Step 4: Apply the mask to box_class_scores, boxes and box_classes
42 ## (≈ 3 lines)
—> 43 scores = tf.boolean_mask(box_class_scores, filtering_mask,axis = None)
44 boxes = tf.boolean_mask(boxes, filtering_mask,axis = None)
45 classes = tf.boolean_mask(box_classes, filtering_mask,axis = None)

/opt/conda/lib/python3.7/site-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
199 “”“Call target, and fall back on dispatchers if there is a TypeError.”""
200 try:
→ 201 return target(*args, **kwargs)
202 except (TypeError, ValueError):
203 # Note: convert_to_eager_tensor currently raises a ValueError, not a

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/array_ops.py in boolean_mask_v2(tensor, mask, axis, name)
1801 ```
1802 “”"
→ 1803 return boolean_mask(tensor, mask, name, axis)
1804
1805

/opt/conda/lib/python3.7/site-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
199 “”“Call target, and fall back on dispatchers if there is a TypeError.”""
200 try:
→ 201 return target(*args, **kwargs)
202 except (TypeError, ValueError):
203 # Note: convert_to_eager_tensor currently raises a ValueError, not a

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/array_ops.py in boolean_mask(tensor, mask, name, axis)
1719 shape_tensor = tensor.get_shape()
1720 if ndims_mask == 0:
→ 1721 raise ValueError(“mask cannot be scalar.”)
1722 if ndims_mask is None:
1723 raise ValueError(

ValueError: mask cannot be scalar.

Help pls

Hey, there seems to be an issue with how you’ve created the filtering_mask, how have you created the said mask?

1 Like

solved it thanx for quick reply

Hi there,

I have the same ValueError.

I suspect the bug is in step 3: filtering_mask.
The tf.boolean_mask documentation says:

tf.boolean_mask( tensor, mask, axis=None, name='boolean_mask')

‘tensor’ would be ‘box_class_scores’, which we are told to base this filter on/have the same dimension as…
box_class_scores has dimensions (19, 19, 5, 80), it is not a scalar.
‘mask’ has to keep the boxes which satisfy the conditions to be true (True), as laid out in the notes for step 3 (>=threshold).
For ‘axis’ the notes say we can keep the default axis=None
The tf.boolean_mask documentation says:
’ A 0-D int Tensor representing the axis in tensor to mask from. By default, axis is 0 which will mask from the first dimension.’
I would expect the mask to be masking the [2] axis, which is where Pc, the probability is.
‘axis=None’, ‘axis=0’, ‘axis=1’, ‘axis=2’ and ‘axis=3’ all throw the following Value Error:
(Error shown here is for ‘None’)


(and the tf notes state that a name is optional)
I cannot understand why ndims_mask == 0 here
Please advise