Programming Assignment: Car detection with YOLO Section 3.5 - Error Running YOLO on an image

Link to the classroom item you are referring to: https://www.coursera.org/learn/convolutional-neural-networks/programming/3VCFG/car-detection-with-yolo

Description
Error at section 3.5 - Run the YOLO on an Image at :
out_scores, out_boxes, out_classes = predict("test.jpg")

---------------------------------------------------------------------------
InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-17-fb6b7cad9cd5> in <module>
----> 1 out_scores, out_boxes, out_classes = predict("car_image.jpeg")

<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-b275b60b3937> in yolo_eval(yolo_outputs, image_shape, max_boxes, score_threshold, iou_threshold)
     38     # Use one of the functions you've implemented to perform Non-max suppression with
     39     # maximum number of boxes set to max_boxes and a threshold of iou_threshold (≈1 line)
---> 40     scores, boxes, classes = yolo_non_max_suppression(scores, boxes, classes, max_boxes = max_boxes, iou_threshold = 1.0)
     41     ### END CODE HERE
     42 

<ipython-input-7-0ac3ebaa382d> in yolo_non_max_suppression(scores, boxes, classes, max_boxes, iou_threshold)
     61     # Flatten the list of indices and concatenate
     62     # Use tf.concat() with 'nms_indices' and `axis=0`
---> 63     nms_indices = tf.concat( nms_indices, 0)
     64 
     65     # Use tf.gather() to select only nms_indices from scores, boxes and classes

/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 concat(values, axis, name)
   1652           dtype=dtypes.int32).get_shape().assert_has_rank(0)
   1653       return identity(values[0], name=name)
-> 1654   return gen_array_ops.concat_v2(values=values, axis=axis, name=name)
   1655 
   1656 

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/gen_array_ops.py in concat_v2(values, axis, name)
   1205       return _result
   1206     except _core._NotOkStatusException as e:
-> 1207       _ops.raise_from_not_ok_status(e, name)
   1208     except _core._FallbackException:
   1209       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: OpKernel 'ConcatV2' has constraint on attr 'T' not in NodeDef '[N=0, Tidx=DT_INT32]', KernelDef: 'op: "ConcatV2" device_type: "CPU" constraint { name: "T" allowed_values { list { type: DT_UINT64 } } } host_memory_arg: "axis"' [Op:ConcatV2] name: concat

I did receive 100% on submission, so i am assuming code is correct.
Am I missing something here?
Thanks.

You probably need to convert that image into a tensor!

Interesting. You’re right that preprocess_image returns image_data as a numpy array, but that did not cause any problem in my notebook. I notice that on the tf.concat call, you are treating the axis parameter as a positional parameter, but it’s actually a keyword parameter. But I tried making that same mistake in my notebook and that did not cause any problems.

One other question: are you running this on the course website or on your own local environment? If the latter, then it could be a “versionitis” issue.

If you’re running this on the course website, then the theory would have to be that there is some other subtle problem with your implementation. Given that it still passes the unit tests and the grader, it would be worth looking at your code to understand what happened. Maybe we need to suggest some enhancements to the tests. Please check your DMs for a message from me about how to share the code privately.

1 Like