tensorflow / models

Models and examples built with TensorFlow
Other
77.21k stars 45.75k forks source link

Failed to convert a series BatchNMS ops to a single combinedNMS op #10784

Open Tengfei09 opened 2 years ago

Tengfei09 commented 2 years ago

Prerequisites

Please answer the following questions for yourself before submitting an issue.

1. The entire URL of the file you are using

https://github.com/tensorflow/models/blob/master/research/object_detection/core/post_processing.py#L998

2. Describe the bug

When converting a series of NMS ops used in a FasterRCNN model to a combinedNMS op. The _research/object_detection/core/postprocessing.py will raise an unexpected error.

3. Steps to reproduce

  1. Download a FasterRCNN model from the TF1 model zoo and install the object_detection API by following the given guideline
  2. unzip your downloaded model and modify the pipeline.config

second_stage_post_processing { batch_non_max_suppression { score_threshold: 0.300000011921 iou_threshold: 0.600000023842 max_detections_per_class: 100 max_total_detections: 100 use_combined_nms: true #add one line } score_converter: SOFTMAX }

  1. convert the FasterRCNN model by using _research/object_detection/export_inferencegraph.py
    python ./object_detection/export_inference_graph.py \
    --input_type image_tensor \
    --pipeline_config_path ./object_detection/faster_rcnn_resnet50_coco_2018_01_28/pipeline.config \
    --trained_checkpoint_prefix ./object_detection/faster_rcnn_resnet50_coco_2018_01_28/model.ckpt \
    --output_directory ./object_detection/faster_rcnn_resnet50_coco_2018_01_28/output/        

    4. Expected behavior

I expect that all NMS ops will be combined into a single CombinedNMS op. However, it raises an unexpected error shown in next part.

According to my own understanding, when setting use_combined_nms=true, these variables, including change_coordinate_frame,num_valid_boxes, use_class_agnostic_nms, soft_nms_sigma, clip_window would be the default values. However, it still raises an error message like ValueError: change_coordinate_frame (normalizing coordinates relative to clip_window) is not supported by combined_nms.**

I also tried to set these above variables to their default values in the pipeline.config explicitly. but it also couldn't work.

5. Additional context

The log I got could be found here.

File "/home/gta/miniconda3/envs/tf1/lib/python3.7/site-packages/object_detection/meta_architectures/faster_rcnn_meta_arch.py", line 1548, in postprocess mask_predictions=mask_predictions) File "/home/gta/miniconda3/envs/tf1/lib/python3.7/site-packages/object_detection/meta_architectures/faster_rcnn_meta_arch.py", line 2133, in _postprocess_box_classifier masks=mask_predictions_batch) File "/home/gta/miniconda3/envs/tf1/lib/python3.7/site-packages/object_detection/core/post_processing.py", line 1000, in batch_multiclass_non_max_suppression 'change_coordinate_frame (normalizing coordinates' ValueError: change_coordinate_frame (normalizing coordinates relative to clip_window) is not supported by combined_nms.

6. System information

Tengfei09 commented 2 years ago

@sushreebarsa The reason why I use TF1.x is the FasterRCNN model is obtained from the TF1.x object detection model zoo. When moving to Tf2.x, it raises an error like

File "/home/gta/miniconda3/envs/tf2/lib/python3.9/site-packages/object_detection/builders/model_builder.py", line 267, in _check_feature_extractor_exists raise ValueError( ValueError: faster_rcnn_resnet50 is not supported for tf version 2. See model_builder.py for features extractors compatible with different versions of Tensorflow

Tengfei09 commented 2 years ago

@sushreebarsa By the way, the TF version I use is TF2.10, Under such an environment, how to convert those models listed in TF1.x model zoo, which have a series of batchNMS ops?