YOLO car detection section 3.5 error messages

I have passed the tests on all the graded functions and received 100% from the auto grader, however I keep getting this error message when I run the prediction in section 3.5. Any ideas? Thanks.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-16-43edc87fb9a8> in <module>
----> 1 out_scores, out_boxes, out_classes = predict("test.jpg")

<ipython-input-15-85846e4b09d5> in predict(image_file)
     20     yolo_outputs = yolo_head(yolo_model_outputs, anchors, len(class_names))
     21 
---> 22     out_scores, out_boxes, out_classes = yolo_eval(yolo_outputs, [image.size[1],  image.size[0]], 10, 0.3, 0.5)
     23 
     24     # Print predictions info

<ipython-input-10-93b38129060e> in yolo_eval(yolo_outputs, image_shape, max_boxes, score_threshold, iou_threshold)
     31 
     32     # Use one of the functions you've implemented to perform Score-filtering with a threshold of score_threshold (ā‰ˆ1 line)
---> 33     scores, boxes, classes = yolo_filter_boxes(boxes, box_confidence, box_class_probs, threshold = score_threshold)
     34 
     35     # Scale boxes back to original image shape.

<ipython-input-3-10adbeca2b38> in yolo_filter_boxes(boxes, box_confidence, box_class_probs, threshold)
     40     ## (ā‰ˆ 3 lines)
     41     scores = tf.boolean_mask(box_class_scores, filtering_mask, axis=None)
---> 42     boxes = tf.boolean_mask(boxes, filtering_mask, axis=None)
     43     classes = tf.boolean_mask(box_classes, filtering_mask, axis=None)
     44     ### END CODE HERE

/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)
   1728     if axis_value is not None:
   1729       axis = axis_value
-> 1730       shape_tensor[axis:axis + ndims_mask].assert_is_compatible_with(shape_mask)
   1731 
   1732     leading_size = gen_math_ops.prod(shape(tensor)[axis:axis + ndims_mask], [0])

/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/tensor_shape.py in assert_is_compatible_with(self, other)
   1132     """
   1133     if not self.is_compatible_with(other):
-> 1134       raise ValueError("Shapes %s and %s are incompatible" % (self, other))
   1135 
   1136   def most_specific_compatible_shape(self, other):

ValueError: Shapes (1, 19, 19, 5) and (1, 19, 19, 80) are incompatible

It does seem pretty surprising that your code passes all the tests but fails in this way. One thing to check before debugging further is that your notebook is in a consistent state. Please try this sequence:

Kernel -> Restart and Clear Output
Save
Cell -> Run All

Then carefully scan through all the cells and see if all the tests pass and let us know whether you still get that same error.

Thanks for the quick response! I tried this sequence and got the same error messages. Previous cells still passed. By ā€œSaveā€ I did ā€œFile ā†’ Save and Checkpointā€.

What is ā€œconvert_to_eager_tensorā€? I couldnā€™t find any obvious from a quick google search. It looked as if section 3.5 and the previous cells were parsing the same code in different ways?

I donā€™t see any references to convert_to_eager_tensor in my YOLO notebook. Where did you see that?

OMG I found it through adding some prints to debug. The problem is in my yolo_filter_boxes implementation. When I specified the last dimension in tf.math.argmax() I used axis=3, which worked with the shape of inputs at that time. But in section 3.5 yolo_outputs has another dimension (totally 5 dimensions). I fixed my code with axis=-1 and all is well :slight_smile:

1 Like

Nice work! Thatā€™s great news that you found the solution. Thanks for the explanation.

convert_to_eager_tensor was in the error messages I got, see what I posted above in the large block of error messages. I still donā€™t know what it means but it was a false chase after all.

Ah, ok, that means itā€™s some internal function within the guts of TensorFlow. TF is open source, so weā€™d need to delve into the TF source to understand more details. I have not tried looking at the source, so I donā€™t know if you have access to the version corresponding to the actual TF version we are running here, which is 2.3.0 from sometime in 2021.

But, as you say, itā€™s probably a wild goose chase since you have already found the solution.