Search code examples
python-3.xtensorflowobject-detection

python Tensorflow 2.4.0 'input must be 4-dimensional[1,1,371,300,3]' ERROR


im running Nicholas Rennote's TFODCourse. when i execute the Evaluate the model code:

python Tensorflow\models\research\object_detection\model_main_tf2.py --model_dir=Tensorflow\workspace\models\my_ssd_mobnet --pipeline_config_path=Tensorflow\workspace\models\my_ssd_mobnet\pipeline.config --checkpoint_dir=Tensorflow\workspace\models\my_ssd_mobnet

error occurs like this

Traceback (most recent call last):
  File "Tensorflow\models\research\object_detection\model_main_tf2.py", line 115, in <module>
    tf.compat.v1.app.run()
  File "C:\Users\All_Nighter\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\platform\app.py", line 40, in run
    _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
  File "C:\Users\All_Nighter\miniconda3\envs\TF\lib\site-packages\absl\app.py", line 303, in run
    _run_main(main, args)
  File "C:\Users\All_Nighter\miniconda3\envs\TF\lib\site-packages\absl\app.py", line 251, in _run_main
    sys.exit(main(argv))
  File "Tensorflow\models\research\object_detection\model_main_tf2.py", line 82, in main
    model_lib_v2.eval_continuously(
  File "C:\Users\All_Nighter\miniconda3\envs\TF\lib\site-packages\object_detection-0.1-py3.8.egg\object_detection\model_lib_v2.py", line 1151, in eval_continuously
    eager_eval_loop(
  File "C:\Users\All_Nighter\miniconda3\envs\TF\lib\site-packages\object_detection-0.1-py3.8.egg\object_detection\model_lib_v2.py", line 928, in eager_eval_loop
    for i, (features, labels) in enumerate(eval_dataset):
  File "C:\Users\All_Nighter\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\data\ops\iterator_ops.py", line 761, in __next__
    return self._next_internal()
  File "C:\Users\All_Nighter\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\data\ops\iterator_ops.py", line 744, in _next_internal
    ret = gen_dataset_ops.iterator_get_next(
  File "C:\Users\All_Nighter\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\ops\gen_dataset_ops.py", line 2727, in iterator_get_next
    _ops.raise_from_not_ok_status(e, name)
  File "C:\Users\All_Nighter\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\framework\ops.py", line 6897, in raise_from_not_ok_status
    six.raise_from(core._status_to_exception(e.code, message), None)
  File "<string>", line 3, in raise_from
tensorflow.python.framework.errors_impl.InvalidArgumentError: input must be 4-dimensional[1,1,371,300,3]
         [[{{node ResizeImage/resize/ResizeBilinear}}]] [Op:IteratorGetNext]

I can't understand what is input must be 4-dimensional[1,1,371,300,3] means. i tried Labeling again, and downgrade TF to 2.4.0. but still happend.


Solution

  • ssd_mobilenet model expects input

    A three-channel image of variable size - the model does NOT support batching. The input tensor is a tf.uint8 tensor with shape [1, height, width, 3] with values in [0, 255]

    In this case you are giving 4-dimensional input[1,1,371,300,3], Reshape your input data as [1,371,300,3].