C4 week 3: YOLO: Problem with yolo_non_max_suppression

I have a problem in the yolo assignment. I have ended up with the error:

InvalidArgumentError: slice index -1 of dimension 0 out of bounds. [Op:StridedSlice] name: strided_slice/

I think it is due to an error when appending nms_indices.

The complete error:

Thanks for helping

Does this help?

Performing nms for class with label 0
nms_indices this loop= [0]
nms_indices so far i.e. after append = [<tf.Tensor: shape=(1,), dtype=int64, numpy=array([0])>]
Performing nms for class with label 1
nms_indices this loop= [1]
nms_indices so far i.e. after append = [<tf.Tensor: shape=(1,), dtype=int64, numpy=array([0])>, <tf.Tensor: shape=(1,), dtype=int64, numpy=array([1])>]
end of test


Performing nms for class with label 0
nms_indices this loop= [0]
nms_indices so far i.e. after append = [<tf.Tensor: shape=(1,), dtype=int64, numpy=array([0])>]
Performing nms for class with label 1
nms_indices this loop= [1]
nms_indices so far i.e. after append = [<tf.Tensor: shape=(1,), dtype=int64, numpy=array([0])>, <tf.Tensor: shape=(1,), dtype=int64, numpy=array([1])>]
end of test


Performing nms for class with label 0
nms_indices this loop= [0]
nms_indices so far i.e. after append = [<tf.Tensor: shape=(1,), dtype=int64, numpy=array([0])>]
end of test


scores:  	[0.855]
boxes:  	[[0.45 0.2  1.01 2.6 ]]
classes:	[0]
Performing nms for class with label 0
nms_indices this loop= [0 1]
nms_indices so far i.e. after append = [<tf.Tensor: shape=(2,), dtype=int64, numpy=array([0, 1])>]
end of test


Performing nms for class with label 1
nms_indices this loop= [ 0 11 18  6 47 17  9 43 36 25  8 35 27]
nms_indices so far i.e. after append = [<tf.Tensor: shape=(13,), dtype=int64, numpy=array([ 0, 11, 18,  6, 47, 17,  9, 43, 36, 25,  8, 35, 27])>]
Performing nms for class with label 2
nms_indices this loop= [19  1 40 53 29 51 12 34 42]
nms_indices so far i.e. after append = [<tf.Tensor: shape=(13,), dtype=int64, numpy=array([ 0, 11, 18,  6, 47, 17,  9, 43, 36, 25,  8, 35, 27])>, <tf.Tensor: shape=(9,), dtype=int64, numpy=array([19,  1, 40, 53, 29, 51, 12, 34, 42])>]
Performing nms for class with label 0
nms_indices this loop= [50 38 33 48  2 24  3 16 22 20 44]
nms_indices so far i.e. after append = [<tf.Tensor: shape=(13,), dtype=int64, numpy=array([ 0, 11, 18,  6, 47, 17,  9, 43, 36, 25,  8, 35, 27])>, <tf.Tensor: shape=(9,), dtype=int64, numpy=array([19,  1, 40, 53, 29, 51, 12, 34, 42])>, <tf.Tensor: shape=(11,), dtype=int64, numpy=array([50, 38, 33, 48,  2, 24,  3, 16, 22, 20, 44])>]
end of test


Performing nms for class with label 2
nms_indices this loop= [34  0 12 21 45 24 30 47 18 26 32 43  2  5 11  8 44 46]
nms_indices so far i.e. after append = [<tf.Tensor: shape=(18,), dtype=int64, numpy=
array([34,  0, 12, 21, 45, 24, 30, 47, 18, 26, 32, 43,  2,  5, 11,  8, 44,
       46])>]
Performing nms for class with label 1
nms_indices this loop= [16 10 49 48 31 19 50 28 40 33  4 36 25 51  9 27 41 38  1]
nms_indices so far i.e. after append = [<tf.Tensor: shape=(18,), dtype=int64, numpy=
array([34,  0, 12, 21, 45, 24, 30, 47, 18, 26, 32, 43,  2,  5, 11,  8, 44,
       46])>, <tf.Tensor: shape=(19,), dtype=int64, numpy=
array([16, 10, 49, 48, 31, 19, 50, 28, 40, 33,  4, 36, 25, 51,  9, 27, 41,
       38,  1])>]
Performing nms for class with label 0
nms_indices this loop= [37  3 23 42 39 35 52 13  7 22 20  6 15 53 14 17 29]
nms_indices so far i.e. after append = [<tf.Tensor: shape=(18,), dtype=int64, numpy=
array([34,  0, 12, 21, 45, 24, 30, 47, 18, 26, 32, 43,  2,  5, 11,  8, 44,
       46])>, <tf.Tensor: shape=(19,), dtype=int64, numpy=
array([16, 10, 49, 48, 31, 19, 50, 28, 40, 33,  4, 36, 25, 51,  9, 27, 41,
       38,  1])>, <tf.Tensor: shape=(17,), dtype=int64, numpy=array([37,  3, 23, 42, 39, 35, 52, 13,  7, 22, 20,  6, 15, 53, 14, 17, 29])>]
end of test
2 Likes

Not very much. I know I have to combind the selected_indices with the nms_indices_label for each label in the for loop.

I have tried to using the tf.gather function as descripted. But I don’t really know to combine them as they have two different shapes.

If I just put them directly into the tf.gather function I get an error:

indices[1] = 1 is not in [0, 1) [Op:GatherV2]

If I just print out selected_indices and nms_indices_label I get:

selected indices
tf.Tensor([0], shape=(1,), dtype=int64)
nms_indices_label
tf.Tensor([0 1], shape=(2,), dtype=int32)

Thank you Balaji, I managed to solve it. The mistake was in the generation of the nms_indices_label where I just used the boxes and labels in stead of the boxes_label.

2 Likes