Search code examples
pythonfiletensorflowtf.kerasobject-detection-api

How to read and write of TFOD2 pipeline.config file by python?


As you have already seen in Tensorflow objects detection they provide pipeline.config file with respect to a particular model. But there we need to manually open these config files & change the parameter by hard coding. My query is like how can I read this pipeline.config file by python & change the parameter in runtime. Please help me with that.


Solution

  • There's an example in the tutorial notebook.

    from object_detection.utils import config_util, save_pipeline_config
    
    pipeline_config = 'configs/tf2/ssd_resnet50_v1_fpn_640x640_coco17_tpu-8.config'
    
    configs = config_util.get_configs_from_pipeline_file(pipeline_config)
    configs['model'].ssd.num_classes = 10 # change number of classes
    

    Then, you can save:

    save_pipeline_config(configs, 'path/to/save/dir/')
    

    See the source code.