DS4-W3 Yolo non_max_suppression

Yolo_non_max_suppression code>

I need help. I tried many different ways, but still unable to fix it. It seems to me that two assertions are through. The output is attached.

iou: 0.22780233025311375
tf.Tensor([0.855 0.828], shape=(2,), dtype=float32)
tf.Tensor([0.855 0.828], shape=(2,), dtype=float32)
tf.Tensor(0.855, shape=(), dtype=float32)

InvalidArgumentError Traceback (most recent call last)
in
23
24 # If both boxes belongs to the same class, one box is suppressed if iou is under the iou_threshold
β€”> 25 scores2, boxes2, classes2 = yolo_non_max_suppression(scores, boxes, classes, iou_threshold = 0.15)
26
27 assert np.allclose(scores2.numpy(), [0.855]), f"Wrong value on scores {scores2.numpy()}"

in yolo_non_max_suppression(scores, boxes, classes, max_boxes, iou_threshold)
74
75 # Sort by scores and return the top max_boxes
β€”> 76 sort_order = tf.argsort(scores, direction=β€˜DESCENDING’).numpy()
77 scores = tf.gather(scores, sort_order[0:max_boxes])
78 boxes = tf.gather(boxes, sort_order[0:max_boxes])

/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/sort_ops.py in argsort(failed resolving arguments)
110 del stable # Unused.
111 with framework_ops.name_scope(name, β€˜argsort’):
β†’ 112 return _sort_or_argsort(values, axis, direction, return_argsort=True)
113
114

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/sort_ops.py in _sort_or_argsort(values, axis, direction, return_argsort)
141 values = framework_ops.convert_to_tensor(values, name=β€˜values’)
142
β†’ 143 return _SORT_IMPL[direction](values, axis_static, return_argsort)
144
145

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/sort_ops.py in _descending_sort(values, axis, return_argsort)
156 The sorted values.
157 β€œβ€"
β†’ 158 k = array_ops.shape(values)[axis]
159 rank = array_ops.rank(values)
160 static_rank = values.shape.ndims

/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 _slice_helper(tensor, slice_spec, var)
1022 ellipsis_mask=ellipsis_mask,
1023 var=var,
β†’ 1024 name=name)
1025
1026

/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 strided_slice(input_, begin, end, strides, begin_mask, end_mask, ellipsis_mask, new_axis_mask, shrink_axis_mask, var, name)
1194 ellipsis_mask=ellipsis_mask,
1195 new_axis_mask=new_axis_mask,
β†’ 1196 shrink_axis_mask=shrink_axis_mask)
1197
1198 parent_name = name

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/gen_array_ops.py in strided_slice(input, begin, end, strides, begin_mask, end_mask, ellipsis_mask, new_axis_mask, shrink_axis_mask, name)
10318 return _result
10319 except _core._NotOkStatusException as e:

10320 _ops.raise_from_not_ok_status(e, name)
10321 except _core._FallbackException:
10322 pass

/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in raise_from_not_ok_status(e, name)
6841 message = e.message + (" name: " + name if name is not None else β€œβ€)
6842 # pylint: disable=protected-access
β†’ 6843 six.raise_from(core._status_to_exception(e.code, message), None)
6844 # pylint: enable=protected-access
6845

/opt/conda/lib/python3.7/site-packages/six.py in raise_from(value, from_value)

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

I would guess that your code for scores = ... is incorrect.

Yes, the score value is correct.

The IoU/boxes values are also correct.

Thank you for all the helps. I managed to get the solutions and all tests passed.

2 Likes