ValueError: 'images' must have either 3 or 4 dimensions.
Hi, I am trying to run detections on a video (mp4) following the code from: link on a Colab document. I am getting the error in the title after a couple of iterations.
The following is the code I'm using (tried pasting code but it was showing bad):

Error: ` ValueError: in user code:
<ipython-input-12-a0f927373045>:28 detect_fn *
image, shapes = model.preprocess(image)
/usr/local/lib/python3.7/dist-packages/object_detection/meta_architectures/ssd_meta_arch.py:484 preprocess *
normalized_inputs, self._image_resizer_fn)
/usr/local/lib/python3.7/dist-packages/object_detection/utils/shape_utils.py:492 resize_images_and_return_shapes *
outputs = static_or_dynamic_map_fn(
/usr/local/lib/python3.7/dist-packages/object_detection/utils/shape_utils.py:246 static_or_dynamic_map_fn *
outputs = [fn(arg) for arg in tf.unstack(elems)]
/usr/local/lib/python3.7/dist-packages/object_detection/core/preprocessor.py:3242 resize_image *
new_image = tf.image.resize_images(
/usr/local/lib/python3.7/dist-packages/tensorflow/python/util/dispatch.py:201 wrapper **
return target(*args, **kwargs)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/image_ops_impl.py:1468 resize_images
skip_resize_if_same=True)
/usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/image_ops_impl.py:1320 _resize_images_common
raise ValueError('\'images\' must have either 3 or 4 dimensions.')
ValueError: 'images' must have either 3 or 4 dimensions.`
The error occurs on this line:
detections, predictions_dict, shapes = detect_fn(input_tensor)
I tried with and without the VideoWriter lines and I still get an error (albeit it takes longer without VideoWriter). Anyone know why this could be happening?
Thanks for the help!
So, I fixed my issue (hopefully).
The issue (for anyone else in the same situation) is that following the tutorial of TensorFlow, the line:
image_np_expanded = np.expand_dims(frame, axis=0)
Is called but not used in any subsequent calls. I noticed that the following line was doing the numpy expansion yet again. So, I change the following line to use the "image_np_expanded" instead of doing the np.expand yet again. You could also remove the first line instead.
I'm not entirely sure if that was the whole issue, but today it let me run through random videos and complete.
ValueError: 'images' must have either 3 or 4 dimensions.`
i too have same error while detect image by real time video camera , did you find the solution???
This usually means your camera is inaccessible or is already currently in use. Try shutting down anything that might be accessing the camera or restart the computer and then restart it.