svpino / tf_object_detection_cm

Confusion Matrix in Object Detection with TensorFlow
78 stars 36 forks source link

ValueError in confusion_matrix_tf2.py #35

Open ananda1996ai opened 3 years ago

ananda1996ai commented 3 years ago

I tried to run the confusion_matrix_tf2.py script to get CM on a trained model, but it runs into a ValueError. I also noticed the --inference_graph flag requires the path to the directory of saved_model.pb. This isn't clear from the documentation. I tried executing: !python confusion_matrix_tf2.py \ --input_tfrecord_path=/path/to/test.record \ --inference_graph=/path/to/directory/Models/saved_model \ --class_labels=/path/to/label_map.pbtxt \ --output_path=confusion_matrix.csv

After loading of the model and as evaluation starts, I get the following error:

Traceback (most recent call last):
  File "confusion_matrix_tf2.py", line 303, in <module>
    tf.compat.v1.app.run()
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/platform/app.py", line 40, in run
    _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
  File "/usr/local/lib/python3.6/dist-packages/absl/app.py", line 300, in run
    _run_main(main, args)
  File "/usr/local/lib/python3.6/dist-packages/absl/app.py", line 251, in _run_main
    sys.exit(main(argv))
  File "confusion_matrix_tf2.py", line 294, in main
    confusion_matrix = process_detections(input_tfrecord_path, model, categories, draw_option, draw_save_path)
  File "confusion_matrix_tf2.py", line 126, in process_detections
    detections          = model(input_tensor) # Run model inference
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/saved_model/load.py", line 668, in _call_attribute
    return instance.__call__(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/def_function.py", line 828, in __call__
    result = self._call(*args, **kwds)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/def_function.py", line 892, in _call
    *args, **kwds)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/function.py", line 2704, in canonicalize_function_inputs
    inputs, self._input_signature, self._flat_input_signature)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/function.py", line 2806, in _convert_inputs_to_signature
    format_error_message(inputs, input_signature))
ValueError: Python inputs incompatible with input_signature:
  inputs: (
    [[[4 4 4 ... 3 3 3]
  [4 4 4 ... 3 3 3]
  [4 4 4 ... 3 3 3]
  ...
  [4 4 4 ... 3 3 3]
  [4 4 4 ... 1 1 1]
  [1 1 1 ... 0 0 0]]])
  input_signature: (
    TensorSpec(shape=(1, None, None, 3), dtype=tf.uint8, name='input_tensor'))

The TFRecord file is created using the generate_tfrecord.py script from the official docs. The inference graph is created using exporter_main_V2.py.

Any help would be much appreciated since I need an urgent solution.

harshit-777 commented 3 years ago

I tried to run the confusion_matrix_tf2.py script to get CM on a trained model, but it runs into a ValueError. I also noticed the --inference_graph flag requires the path to the directory of saved_model.pb. This isn't clear from the documentation. I tried executing: !python confusion_matrix_tf2.py \ --input_tfrecord_path=/path/to/test.record \ --inference_graph=/path/to/directory/Models/saved_model \ --class_labels=/path/to/label_map.pbtxt \ --output_path=confusion_matrix.csv

After loading of the model and as evaluation starts, I get the following error:

Traceback (most recent call last):
  File "confusion_matrix_tf2.py", line 303, in <module>
    tf.compat.v1.app.run()
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/platform/app.py", line 40, in run
    _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
  File "/usr/local/lib/python3.6/dist-packages/absl/app.py", line 300, in run
    _run_main(main, args)
  File "/usr/local/lib/python3.6/dist-packages/absl/app.py", line 251, in _run_main
    sys.exit(main(argv))
  File "confusion_matrix_tf2.py", line 294, in main
    confusion_matrix = process_detections(input_tfrecord_path, model, categories, draw_option, draw_save_path)
  File "confusion_matrix_tf2.py", line 126, in process_detections
    detections          = model(input_tensor) # Run model inference
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/saved_model/load.py", line 668, in _call_attribute
    return instance.__call__(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/def_function.py", line 828, in __call__
    result = self._call(*args, **kwds)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/def_function.py", line 892, in _call
    *args, **kwds)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/function.py", line 2704, in canonicalize_function_inputs
    inputs, self._input_signature, self._flat_input_signature)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/function.py", line 2806, in _convert_inputs_to_signature
    format_error_message(inputs, input_signature))
ValueError: Python inputs incompatible with input_signature:
  inputs: (
    [[[4 4 4 ... 3 3 3]
  [4 4 4 ... 3 3 3]
  [4 4 4 ... 3 3 3]
  ...
  [4 4 4 ... 3 3 3]
  [4 4 4 ... 1 1 1]
  [1 1 1 ... 0 0 0]]])
  input_signature: (
    TensorSpec(shape=(1, None, None, 3), dtype=tf.uint8, name='input_tensor'))

The TFRecord file is created using the generate_tfrecord.py script from the official docs. The inference graph is created using exporter_main_V2.py.

Any help would be much appreciated since I need an urgent solution.

Hey do you got solution?? Am facing same issue

ananda1996ai commented 3 years ago

@harshit-777 No, I abandoned this codebase long ago. Try scripting your confusion matrix code using the bbox coors from the model outputs.