def testGenericConfigOverride(self):
    """Tests generic config overrides for all top-level configs."""
    # Set one parameter for each of the top-level pipeline configs:
    pipeline_config = pipeline_pb2.TrainEvalPipelineConfig()
    pipeline_config.model.ssd.num_classes = 1
    pipeline_config.train_config.batch_size = 1
    pipeline_config.eval_config.num_visualizations = 1
    pipeline_config.train_input_reader.label_map_path = "/some/path"
    pipeline_config.eval_input_reader.add().label_map_path = "/some/path"
    pipeline_config.graph_rewriter.quantization.weight_bits = 1

    pipeline_config_path = os.path.join(self.get_temp_dir(), "pipeline.config")
    _write_config(pipeline_config, pipeline_config_path)

    # Override each of the parameters:
    configs = config_util.get_configs_from_pipeline_file(pipeline_config_path)
    hparams = contrib_training.HParams(
        **{
            "model.ssd.num_classes": 2,
            "train_config.batch_size": 2,
            "train_input_config.label_map_path": "/some/other/path",
            "eval_config.num_visualizations": 2,
            "graph_rewriter_config.quantization.weight_bits": 2
        })
    configs = config_util.merge_external_params_with_configs(configs, hparams)

    # Ensure that the parameters have the overridden values:
    self.assertEqual(2, configs["model"].ssd.num_classes)
    self.assertEqual(2, configs["train_config"].batch_size)
    self.assertEqual("/some/other/path",
                     configs["train_input_config"].label_map_path)
    self.assertEqual(2, configs["eval_config"].num_visualizations)
    self.assertEqual(2,
                     configs["graph_rewriter_config"].quantization.weight_bits)
Tests generic config overrides for all top-level configs.
inference_api/src/main/object_detection/utils/config_util_test.py