Skip to content

ValueError: 'images' must have either 3 or 4 dimensions in step 10.Real Time Detections from your Webcam¶ #163

@zuhhh03

Description

@zuhhh03

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

Screenshot 2024-03-07 153526
Screenshot 2024-03-07 153544
Screenshot 2024-03-07 153558
Screenshot 2024-03-07 153609
Screenshot 2024-03-07 153526
Screenshot 2024-03-07 153544
Screenshot 2024-03-07 153558
Screenshot 2024-03-07 153609


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..tf__detect_fn(image)
8 do_return = 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..tf__preprocess(self, inputs)
33 try:
34 do_return = 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..tf__resize_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..tf__static_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, ('do_return', 'outputs', 'retval_'), 3)
188 def get_state_12():
189 return (do_return, retval_)

File ~\AppData\Local\Temp_autograph_generated_fileddmjfylv.py:179, in outer_factory..inner_factory..tf__static_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, ('do_return', 'outputs', 'retval_'), 3)

File ~\AppData\Local\Temp_autograph_generated_fileddmjfylv.py:177, in outer_factory..inner_factory..tf__static_or_dynamic_map_fn..else_body_5..else_body_4()
175 def else_body_4():
176 nonlocal do_return, 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 do_return, 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..tf__resize_image(image, masks, new_height, new_width, method, align_corners)
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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions