DuplicateFlagError: The flag 'pipeline_config_path' is defined twice. First from model_main_tf2.py, Second from model_main_tf2.py. Description from first occurrence: Path to pipeline config file

Hi, I’m trying to run model_main_tf2.py from tensorflow object_detection repo and I’m facing the below issue.

---------------------------------------------------------------------------
DuplicateFlagError                        Traceback (most recent call last)
File ~/Documents/Indian_License_Plate_Recognition/models/research/object_detection/model_main_tf2.py:33
     30 import tensorflow.compat.v2 as tf
     31 from object_detection import model_lib_v2
---> 33 flags.DEFINE_string('pipeline_config_path', None, 'Path to pipeline config '
     34                     'file.')
     35 flags.DEFINE_integer('num_train_steps', None, 'Number of train steps.')
     36 flags.DEFINE_bool('eval_on_train_data', False, 'Enable evaluating on train '
     37                   'data (only supported in distributed training).')

File ~/anaconda3/envs/tfsetup/lib/python3.10/site-packages/absl/flags/_defines.py:301, in DEFINE_string(name, default, help, flag_values, required, **args)
    299 parser = _argument_parser.ArgumentParser()
    300 serializer = _argument_parser.ArgumentSerializer()
--> 301 return DEFINE(
    302     parser,
    303     name,
    304     default,
    305     help,
    306     flag_values,
    307     serializer,
    308     required=required,
    309     **args)

File ~/anaconda3/envs/tfsetup/lib/python3.10/site-packages/absl/flags/_defines.py:100, in DEFINE(parser, name, default, help, flag_values, serializer, module_name, required, **args)
     65 def DEFINE(  # pylint: disable=invalid-name
     66     parser,
     67     name,
   (...)
     73     required=False,
     74     **args):
     75   """Registers a generic Flag object.
     76 
     77   NOTE: in the docstrings of all DEFINE* functions, "registers" is short
   (...)
     98     a handle to defined flag.
     99   """
--> 100   return DEFINE_flag(
    101       _flag.Flag(parser, serializer, name, default, help, **args), flag_values,
    102       module_name, required)

File ~/anaconda3/envs/tfsetup/lib/python3.10/site-packages/absl/flags/_defines.py:136, in DEFINE_flag(flag, flag_values, module_name, required)
    134 # Copying the reference to flag_values prevents pychecker warnings.
    135 fv = flag_values
--> 136 fv[flag.name] = flag
    137 # Tell flag_values who's defining the flag.
    138 if module_name:

File ~/anaconda3/envs/tfsetup/lib/python3.10/site-packages/absl/flags/_flagvalues.py:430, in FlagValues.__setitem__(self, name, flag)
    424   if (self.find_module_defining_flag(name) == module_name and
    425       id(module) != self.find_module_id_defining_flag(name)):
    426     # If the flag has already been defined by a module with the same name,
    427     # but a different ID, we can stop here because it indicates that the
    428     # module is simply being imported a subsequent time.
    429     return
--> 430   raise _exceptions.DuplicateFlagError.from_flag(name, self)
    431 short_name = flag.short_name
    432 # If a new flag overrides an old one, we need to cleanup the old flag's
    433 # modules if it's not registered.

DuplicateFlagError: The flag 'pipeline_config_path' is defined twice. First from model_main_tf2.py, Second from model_main_tf2.py.  Description from first occurrence: Path to pipeline config file.

Can someone please help me understand on where I’m making a mistake.

@Leelaram_Jayaram,

Can you try to delete all the flags before declaring?

We are not supporting research models and request you to refer to official models for assistance.

Please refer to the Object Detection with Model Garden using tensorflow_models.

Thank you!

I resolved this error. earlier I was running using the below command

%run model_main_tf2.py --pipeline_config_path={PIPELINE_CONFING_FILEPATH} --model_dir={CHECKPOINTS_DIR} --sample_1_of_n_eval_examples=40 --checkpoint_every_n=100 --alsologtostderr

when I changed to the below command, the error disappeared.

!python model_main_tf2.py --pipeline_config_path={PIPELINE_CONFING_FILEPATH} --model_dir={CHECKPOINTS_DIR} --sample_1_of_n_eval_examples=40 --checkpoint_every_n=100 --alsologtostderr