Hi there,

I have the ValueError ‘mask cannot be scalar’. I posted on the earlier ‘mask cannot be scalar’ topic, but got no reply.

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, but maybe I am misunderstanding ‘mask’ in this context.

‘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 “name” is optional)

I cannot understand why ndims_mask == 0 here

If my code for ‘mask’ is returning a scalar instead of selecting >=threshold, then please suggest where I can read more on this, as it is unclear from the tf.boolean_mask documentation.

Please advise

Have you tried printing out the shape of your mask value?

If you’ve been looking at other threads on this topic, you’ve probably already seen this, but I added a bunch of print statements in my *yolo_filter_boxes* function. Here’s what I get when I run the test cell for that function:

```
boxes.shape (19, 19, 5, 4)
boxes.dtype <dtype: 'float32'>
box_scores.shape (19, 19, 5, 80)
box_scores.dtype <dtype: 'float32'>
box_classes.shape (19, 19, 5)
box_classes.dtype <dtype: 'int64'>
box_class_scores.shape (19, 19, 5)
box_class_scores.dtype <dtype: 'float32'>
filtering_mask.shape (19, 19, 5)
filtering_mask.dtype <dtype: 'bool'>
scores[2] = 9.270486
boxes[2] = [ 4.6399336 3.2303846 4.431282 -2.202031 ]
classes[2] = 8
scores.shape = (1789,)
boxes.shape = (1789, 4)
classes.shape = (1789,)
All tests passed!
```

An entry in `filtering_mask`

should be `True`

when the corresponding entry in `box_class_scores`

is more than the `threshold`

and `False`

otherwise.

Once you get the `filtering_mask`

, you can get the `box_class_scores`

satisfying the `filtering_mask`

by using `tf.boolean_mask`

Thanks once again Paul.

All tests passed.

My error was that I was attempting to apply tf.boolean_mask in step 3, rather than step 4.

As a result I was struggling to find an argument for ‘mask’ that would satisfy all three cases.

Onward(s)

Thanks Balaji.

When I first read your reply I thought it was unhelpful.

Once I solved the problem I reread it and your reply makes perfect sense.

As a result I have addressed my error in my reply to Paul.

Thank you