According to the error guide (ValueError: 'images' must have either 3 or 4 dimensions) for this error told to restart the notebook but still i'm getting this error and not able to run real time webcam detection . Please guide me through the process. Help me solve this issue
ValueError Traceback (most recent call last)
Cell In[80], line 11
7 image_np = np.array(frame)
10 input_tensor = tf.convert_to_tensor(np.expand_dims(image_np,0), dtype=tf.float32)
---> 11 detections = detect_fn(input_tensor)
13 num_detections = int(detections.pop('num_detections'))
14 detections = {key: value[0, :num_detections].numpy()
15 for key, value in detections.items()}
File Z:\OD\TFODCourse\od\lib\site-packages\tensorflow\python\util\traceback_utils.py:153, in filter_traceback..error_handler(*args, **kwargs)
151 except Exception as e:
152 filtered_tb = _process_traceback_frames(e.traceback)
--> 153 raise e.with_traceback(filtered_tb) from None
154 finally:
155 del filtered_tb
File "C:\Users\Zubair\AppData\Local\Temp\ipykernel_7212\1654050223.py", line 11, in detect_fn *
image, shapes = detection_model.preprocess(image)
File "Z:\OD\TFODCourse\od\lib\site-packages\object_detection-0.1-py3.10.egg\object_detection\meta_architectures\ssd_meta_arch.py", line 485, in preprocess *
normalized_inputs, self._image_resizer_fn)
File "Z:\OD\TFODCourse\od\lib\site-packages\object_detection-0.1-py3.10.egg\object_detection\utils\shape_utils.py", line 492, in resize_images_and_return_shapes *
outputs = static_or_dynamic_map_fn(
File "Z:\OD\TFODCourse\od\lib\site-packages\object_detection-0.1-py3.10.egg\object_detection\utils\shape_utils.py", line 246, in static_or_dynamic_map_fn *
outputs = [fn(arg) for arg in tf.unstack(elems)]
File "Z:\OD\TFODCourse\od\lib\site-packages\object_detection-0.1-py3.10.egg\object_detection\core\preprocessor.py", line 3330, in resize_image *
new_image = tf.image.resize_images(
ValueError: 'images' must have either 3 or 4 dimensions.
According to the error guide (ValueError: 'images' must have either 3 or 4 dimensions) for this error told to restart the notebook but still i'm getting this error and not able to run real time webcam detection . Please guide me through the process. Help me solve this issue
ValueError Traceback (most recent call last) Cell In[80], line 11 7 image_np = np.array(frame) 10 input_tensor = tf.convert_to_tensor(np.expand_dims(image_np,0), dtype=tf.float32) ---> 11 detections = detect_fn(input_tensor) 13 num_detections = int(detections.pop('num_detections')) 14 detections = {key: value[0, :num_detections].numpy() 15 for key, value in detections.items()}
File Z:\OD\TFODCourse\od\lib\site-packages\tensorflow\python\util\traceback_utils.py:153, in filter_traceback..error_handler(*args, **kwargs)
151 except Exception as e:
152 filtered_tb = _process_traceback_frames(e.traceback)
--> 153 raise e.with_traceback(filtered_tb) from None
154 finally:
155 del filtered_tb
File ~\AppData\Local\Temp__autograph_generated_file5hb9upkq.py:10, in outer_factory..inner_factory..tfdetect_fn(image)
8 doreturn = False
9 retval = ag.UndefinedReturnValue()
---> 10 (image, shapes) = ag.converted_call(ag.ld(detection_model).preprocess, (ag.ld(image),), None, fscope)
11 prediction_dict = ag__.converted_call(ag.ld(detection_model).predict, (ag.ld(image), ag.ld(shapes)), None, fscope)
12 detections = ag.converted_call(ag__.ld(detection_model).postprocess, (ag.ld(prediction_dict), ag__.ld(shapes)), None, fscope)
File ~\AppData\Local\Temp__autograph_generated_filele9x467a.py:35, in outer_factory..inner_factory..tfpreprocess(self, inputs)
33 try:
34 doreturn = True
---> 35 retval = ag.converted_call(ag.ld(shape_utils).resize_images_and_return_shapes, (ag__.ld(normalized_inputs), ag.ld(self)._image_resizer_fn), None, fscope)
36 except:
37 do_return = False
File ~\AppData\Local\Temp__autograph_generated_filecxz4zk41.py:37, in outer_factory..inner_factory..tfresize_images_and_return_shapes(inputs, image_resizer_fn)
35 pass
36 ag.if_stmt(ag.ld(inputs).dtype is not ag.ld(tf).float32, if_body, else_body, get_state, set_state, (), 0)
---> 37 outputs = ag.converted_call(ag.ld(static_or_dynamic_map_fn), (ag.ld(image_resizer_fn),), dict(elems=ag.ld(inputs), dtype=[ag.ld(tf).float32, ag__.ld(tf).int32]), fscope)
38 resized_inputs = ag.ld(outputs)[0]
39 true_image_shapes = ag__.ld(outputs)[1]
File ~\AppData\Local\Temp__autograph_generated_fileddmjfylv.py:186, in outer_factory..inner_factory..tfstatic_or_dynamic_map_fn(fn, elems, dtype, parallel_iterations, back_prop)
184 elems_shape = ag__.Undefined('elems_shape')
185 outputs = ag.Undefined('outputs')
--> 186 ag.if_stmt(ag__.converted_call(ag.ld(isinstance), (ag.ld(elems), ag.ld(list)), None, fscope), if_body_5, else_body_5, get_state_7, set_state_7, ('doreturn', 'outputs', 'retval'), 3)
188 def get_state_12():
189 return (doreturn, retval)
File ~\AppData\Local\Temp__autograph_generated_fileddmjfylv.py:179, in outer_factory..inner_factory..tfstatic_or_dynamic_map_fn..else_body_5()
177 outputs = [ag .converted_call(ag.ld(fn), (ag.ld(arg),), None, fscope) for arg in ag.converted_call(ag.ld(tf).unstack, (ag.ld(elems),), None, fscope)]
178 outputs = ag.Undefined('outputs')
--> 179 ag.if_stmt(ag.or_(lambda : ag.not_(ag__.ld(elems_shape)), lambda : ag.not_(ag__.ld(elems_shape)[0])), if_body_4, else_body_4, get_state_6, set_state_6, ('doreturn', 'outputs', 'retval'), 3)
File ~\AppData\Local\Temp__autograph_generated_fileddmjfylv.py:177, in outer_factory..inner_factory..tfstatic_or_dynamic_map_fn..else_body_5..else_body_4()
175 def else_body_4():
176 nonlocal doreturn, retval, outputs
--> 177 outputs = [ag .converted_call(ag.ld(fn), (ag.ld(arg),), None, fscope) for arg in ag__.converted_call(ag.ld(tf).unstack, (ag.ld(elems),), None, fscope)]
File ~\AppData\Local\Temp__autograph_generated_fileddmjfylv.py:177, in(.0)
175 def else_body_4():
176 nonlocal doreturn, retval, outputs
--> 177 outputs = [ag.converted_call(ag.ld(fn), (ag.ld(arg),), None, fscope) for arg in ag__.converted_call(ag.ld(tf).unstack, (ag__.ld(elems),), None, fscope)]
File ~\AppData\Local\Temp__autograph_generated_filebncszcul.py:34, in outer_factory..inner_factory..tfresize_image(image, masks, new_height, new_width, method, aligncorners)
32 retval = ag.UndefinedReturnValue()
33 with ag.ld(tf).name_scope('ResizeImage', values=[ag.ld(image), ag.ld(new_height), ag__.ld(new_width), ag.ld(method), ag.ld(align_corners)]):
---> 34 new_image = ag.converted_call(ag.ld(tf).image.resize_images, (ag.ld(image), ag.converted_call(ag.ld(tf).stack, ([ag.ld(new_height), ag__.ld(new_width)],), None, fscope)), dict(method=ag.ld(method), align_corners=ag.ld(align_corners)), fscope)
35 image_shape = ag.converted_call(ag__.ld(shape_utils).combined_static_and_dynamic_shape, (ag.ld(image),), None, fscope)
36 result = [ag.ld(new_image)]
ValueError: in user code: