Faster RCNN Inception; Tensorflow TensorRT graph; Attribute Error: "Post Processing" has no attribute "score_threshold"

I am trying to convert a Tensorflow detection graph from a pre-trained faster rcnn model to a TensorRT inference graph with Tensorflow 1.15.5.

I use the code from GitHub - NVIDIA-AI-IOT/tf_trt_models: TensorFlow models accelerated with NVIDIA TensorRT.
The TensorRT inference graph is used for inference on a Nvidia Jetson Nano.

When I execute following command:

frozen_graph, input_names, output_names = build_detection_graph(
    config=config_path,
    checkpoint=checkpoint_path,
    score_threshold=0.3,
    iou_threshold=0.5,
    batch_size=1)

I get the following error, which occurs with every rcnn model from the repo.

AttributeError                            Traceback (most recent call last)
<ipython-input-58-be040ed41095> in <module>()
      4     score_threshold=0.3,
      5     iou_threshold=0.5,
----> 6     batch_size=1
      7 )

<ipython-input-25-686a48394be8> in build_detection_graph(config, checkpoint, batch_size, score_threshold, iou_threshold, force_nms_cpu, replace_relu6, remove_assert, input_shape, output_dir)
    104     elif config.model.HasField('faster_rcnn'):
    105         if score_threshold is not None:
--> 106             config.model.faster_rcnn.second_stage_post_processing.score_threshold = score_threshold
    107         if input_shape is not None:
    108             config.model.faster_rcnn.image_resizer.fixed_shape_resizer.height = input_shape[0]

AttributeError: 'PostProcessing' object has no attribute 'score_threshold'

Code of build_detection_graph is:

def build_detection_graph(config, checkpoint,
        batch_size=1,
        score_threshold=None,
        iou_threshold=None,
        force_nms_cpu=True,
        replace_relu6=True,
        remove_assert=True,
        input_shape=None,
        output_dir='.generated_model'):
    """Builds a frozen graph for a pre-trained object detection model"""
    
    config_path = config
    checkpoint_path = checkpoint

    # parse config from file
    config = pipeline_pb2.TrainEvalPipelineConfig()
    with open(config_path, 'r') as f:
        text_format.Merge(f.read(), config, allow_unknown_extension=True)

...

    elif config.model.HasField('faster_rcnn'):

        if score_threshold is not None:
            config.model.faster_rcnn.second_stage_post_processing.score_threshold = score_threshold

        if input_shape is not None:
            config.model.faster_rcnn.image_resizer.fixed_shape_resizer.height = input_shape[0]
            config.model.faster_rcnn.image_resizer.fixed_shape_resizer.width = input_shape[1]

Hi,

The GitHub is not updated for a while.
So it might not work correctly on the latest software or latest model.

Do you want a TF-TRT model or a pure TensorRT engine that doesn’t depend on TensorFlow?
If a pure TensorRT engine is acceptable, you can find another example below:

Thanks.