Models: absl.flags._exceptions.UnparsedFlagAccessError: Trying to access flag --model_dir before flags were parsed.

Created on 17 Jul 2018  ·  14Comments  ·  Source: tensorflow/models

when I run python research/object_detection/model_main.py --pipeline_config_path='./research/object_detection/trainmodels/ssd_mobilenet_v1_pets.config' --model_dir='./research/object_detection/trained2012/'

Traceback (most recent call last):
File "research/object_detection/model_main.py", line 103, in
tf.app.run()
File "/home/hd/.local/lib/python3.5/site-packages/tensorflow/python/platform/app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "research/object_detection/model_main.py", line 57, in main
config = tf.estimator.RunConfig(model_dir=FLAGS.model_dir)
File "/home/hd/.local/lib/python3.5/site-packages/absl/flags/_flagvalues.py", line 488, in __getattr__
raise _exceptions.UnparsedFlagAccessError(error_message)
absl.flags._exceptions.UnparsedFlagAccessError: Trying to access flag --model_dir before flags were parsed.

stalled awaiting response

Most helpful comment

FLAGS arguments should be used in main() function where they are parsed, like:

flags.DEFINE_string('x', "", "some explation")
FLAGS = flags.FLAGS

x = FLAGS.x    # produce such error

def main(unused_argv):
  x = FLAGS.x  # work fine!

All 14 comments

Thank you for your post. We noticed you have not filled out the following field in the issue template. Could you update them if they are relevant in your case, or leave them as N/A? Thanks.
What is the top-level directory of the model you are using
Have I written custom code
OS Platform and Distribution
TensorFlow installed from
TensorFlow version
Bazel version
CUDA/cuDNN version
GPU model and memory
Exact command to reproduce

I had the same issue, it got resolved by using the flags = tf.app.flags instead of absl

@pkulzc I'm facing the same issue. @sujaybabruwad could you tell me more how exactly you fixed this issue?

ERROR:
absl.flags._exceptions.UnparsedFlagAccessError: Trying to access flag --model_dir before flags were parsed.

What is the top-level directory of the model you are using: models/
Have I written custom code: No
OS Platform and Distribution: OSX 10.13.6
TensorFlow installed from: Official Website
TensorFlow version: 1.4.0
Bazel version: 0.13.0-homebrew
CUDA/cuDNN version: N/A
GPU model and memory: N/A
Exact command to reproduce

python object_detection/model_main.py --pipeline_config_path=$PIPELINE_CONFIG_PATH --model_dir=$MODEL_DIR --num_train_steps=$NUM_TRAIN_STEPS --num_eval_steps=$NUM_EVAL_STEPS --alsologtostderr

Thank you @sujaybabruwad,I have solved the problem!
I modified the model_main.py as follows:
comment:from absl import flags
change:flags.DEFINE_string => tf.app.flags.DEFINE_string
add:FLAGS = tf.app.flags.FLAGS
comment:flags.mark_flag_as_required('model_dir')
comment:flags.mark_flag_as_required('pipeline_config_path')
add:
if not FLAGS.model_dir:
raise ValueError('You must supply the model_dir')
if not FLAGS.pipeline_config_path:
raise ValueError('You must supply the pipeline_config_path')

Thanks @AlloyMe for the solution.

There are more errors from other modules.

object_detection/builders/dataset_builder.py", line 76, in read_dataset tf.contrib.data.parallel_interleave( AttributeError: 'module' object has no attribute 'parallel_interleave'

object_detection/model_lib.py", line 217, in model_fn labels[fields.InputDataFields.groundtruth_boxes].get_shape() TypeError: 'NoneType' object has no attribute '__getitem__'

hello @ajinkyapuar,I also meet this problem,
AttributeError: module 'tensorflow.contrib.data' has no attribute 'parallel_interleave'
I find a solution in a blog that says you should update your tensorflow version.

@AlloyMei @pkulzc After updating tensorflow 1.9

$ python object_detection/model_main.py --pipeline_config_path=$PIPELINE_CONFIG_PATH --model_dir=$MODEL_DIR --num_train_steps=$NUM_TRAIN_STEPS --num_eval_steps=$NUM_EVAL_STEPS --alsologtostderr

/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/h5py/__init__.py:36: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
from ._conv import register_converters as _register_converters
/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/h5py/__init__.py:45: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
from . import h5a, h5d, h5ds, h5f, h5fd, h5g, h5r, h5s, h5t, h5p, h5z
/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/h5py/_hl/group.py:22: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
from .. import h5g, h5i, h5o, h5r, h5t, h5l, h5p
/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/matplotlib/__init__.py:1405: UserWarning:
This call to matplotlib.use() has no effect because the backend has already
been chosen; matplotlib.use() must be called before pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.

warnings.warn(_use_error_msg)
WARNING:tensorflow:Estimator's model_fn () includes params argument, but params are not passed to Estimator.
2018-07-31 19:17:36.553418: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
Traceback (most recent call last):
File "object_detection/model_main.py", line 105, in
tf.app.run()
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 125, in run
_sys.exit(main(argv))
File "object_detection/model_main.py", line 101, in main
tf.estimator.train_and_evaluate(estimator, train_spec, eval_specs[0])
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/estimator/training.py", line 447, in train_and_evaluate
return executor.run()
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/estimator/training.py", line 531, in run
return self.run_local()
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/estimator/training.py", line 681, in run_local
eval_result, export_results = evaluator.evaluate_and_export()
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/estimator/training.py", line 886, in evaluate_and_export
hooks=self._eval_spec.hooks)
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/estimator/estimator.py", line 460, in evaluate
output_dir=self.eval_dir(name))
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/estimator/estimator.py", line 1386, in _evaluate_run
config=self._session_config)
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/training/evaluation.py", line 209, in _evaluate_once
session_creator=session_creator, hooks=hooks) as session:
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/training/monitored_session.py", line 826, in __init__
stop_grace_period_secs=stop_grace_period_secs)
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/training/monitored_session.py", line 549, in __init__
self._sess = _RecoverableSession(self._coordinated_creator)
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/training/monitored_session.py", line 1012, in __init__
_WrappedSession.__init__(self, self._create_session())
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/training/monitored_session.py", line 1017, in _create_session
return self._sess_creator.create_session()
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/training/monitored_session.py", line 706, in create_session
self.tf_sess = self._session_creator.create_session()
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/training/monitored_session.py", line 477, in create_session
init_fn=self._scaffold.init_fn)
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/training/session_manager.py", line 281, in prepare_session
config=config)
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/training/session_manager.py", line 195, in _restore_checkpoint
saver.restore(sess, checkpoint_filename_with_path)
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/training/saver.py", line 1752, in restore
{self.saver_def.filename_tensor_name: save_path})
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 900, in run
run_metadata_ptr)
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1135, in _run
feed_dict_tensor, options, run_metadata)
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1316, in _do_run
run_metadata)
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1335, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Assign requires shapes of both tensors to match. lhs shape= [1,1,512,6] rhs shape= [1,1,512,273]
[[Node: save/Assign_3 = Assign[T=DT_FLOAT, _class=["loc:@BoxPredictor_0/ClassPredictor/weights"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](BoxPredictor_0/ClassPredictor/weights, save/RestoreV2:3)]]

Caused by op u'save/Assign_3', defined at:
File "object_detection/model_main.py", line 105, in
tf.app.run()
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 125, in run
_sys.exit(main(argv))
File "object_detection/model_main.py", line 101, in main
tf.estimator.train_and_evaluate(estimator, train_spec, eval_specs[0])
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/estimator/training.py", line 447, in train_and_evaluate
return executor.run()
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/estimator/training.py", line 531, in run
return self.run_local()
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/estimator/training.py", line 681, in run_local
eval_result, export_results = evaluator.evaluate_and_export()
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/estimator/training.py", line 886, in evaluate_and_export
hooks=self._eval_spec.hooks)
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/estimator/estimator.py", line 460, in evaluate
output_dir=self.eval_dir(name))
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/estimator/estimator.py", line 1386, in _evaluate_run
config=self._session_config)
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/training/evaluation.py", line 209, in _evaluate_once
session_creator=session_creator, hooks=hooks) as session:
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/training/monitored_session.py", line 826, in __init__
stop_grace_period_secs=stop_grace_period_secs)
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/training/monitored_session.py", line 549, in __init__
self._sess = _RecoverableSession(self._coordinated_creator)
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/training/monitored_session.py", line 1012, in __init__
_WrappedSession.__init__(self, self._create_session())
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/training/monitored_session.py", line 1017, in _create_session
return self._sess_creator.create_session()
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/training/monitored_session.py", line 706, in create_session
self.tf_sess = self._session_creator.create_session()
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/training/monitored_session.py", line 468, in create_session
self._scaffold.finalize()
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/training/monitored_session.py", line 212, in finalize
self._saver = training_saver._get_saver_or_default() # pylint: disable=protected-access
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/training/saver.py", line 856, in _get_saver_or_default
saver = Saver(sharded=True, allow_empty=True)
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/training/saver.py", line 1284, in __init__
self.build()
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/training/saver.py", line 1296, in build
self._build(self._filename, build_save=True, build_restore=True)
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/training/saver.py", line 1333, in _build
build_save=build_save, build_restore=build_restore)
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/training/saver.py", line 775, in _build_internal
restore_sequentially, reshape)
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/training/saver.py", line 453, in _AddShardedRestoreOps
name="restore_shard"))
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/training/saver.py", line 422, in _AddRestoreOps
assign_ops.append(saveable.restore(saveable_tensors, shapes))
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/training/saver.py", line 113, in restore
self.op.get_shape().is_fully_defined())
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/state_ops.py", line 219, in assign
validate_shape=validate_shape)
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/gen_state_ops.py", line 60, in assign
use_locking=use_locking, name=name)
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 3414, in create_op
op_def=op_def)
File "/Users/username/anaconda/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1740, in __init__
self._traceback = self._graph._extract_stack() # pylint: disable=protected-access

InvalidArgumentError (see above for traceback): Assign requires shapes of both tensors to match. lhs shape= [1,1,512,6] rhs shape= [1,1,512,273]
[[Node: save/Assign_3 = Assign[T=DT_FLOAT, _class=["loc:@BoxPredictor_0/ClassPredictor/weights"], use_locking=true, validate_shape=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](BoxPredictor_0/ClassPredictor/weights, save/RestoreV2:3)]]

@ajinkyapuar maybe this discussion may help you:https://github.com/tensorflow/tensorflow/issues/6883

@AlloyMei I'm facing the same issue.I have modified my code according to your answer, but it raised another problem.
Traceback (most recent call last):
File "D:/2 索恒信息/TensorFlow/tensorflow-models/research/object_detection/model_main.py", line 110, in
tf.app.run()
File "C:\ProgramData\Anaconda3\envs\python35\lib\site-packages\tensorflow\python\platform\app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "D:/2 索恒信息/TensorFlow/tensorflow-models/research/object_detection/model_main.py", line 70, in main
eval_steps=FLAGS.num_eval_steps)
File "C:\ProgramData\Anaconda3\envs\python35\lib\site-packages\object_detection-0.1-py3.5.egg\object_detection\model_lib.py", line 497, in create_estimator_and_inputs
configs = get_configs_from_pipeline_file(pipeline_config_path)
File "C:\ProgramData\Anaconda3\envs\python35\lib\site-packages\object_detection-0.1-py3.5.egg\object_detection\utils\config_util.py", line 94, in get_configs_from_pipeline_file
text_format.Merge(proto_str, pipeline_config)
File "C:\ProgramData\Anaconda3\envs\python35\lib\site-packages\google\protobuf\text_format.py", line 525, in Merge
descriptor_pool=descriptor_pool)
File "C:\ProgramData\Anaconda3\envs\python35\lib\site-packages\google\protobuf\text_format.py", line 579, in MergeLines
return parser.MergeLines(lines, message)
File "C:\ProgramData\Anaconda3\envs\python35\lib\site-packages\google\protobuf\text_format.py", line 612, in MergeLines
self._ParseOrMerge(lines, message)
File "C:\ProgramData\Anaconda3\envs\python35\lib\site-packages\google\protobuf\text_format.py", line 627, in _ParseOrMerge
self._MergeField(tokenizer, message)
File "C:\ProgramData\Anaconda3\envs\python35\lib\site-packages\google\protobuf\text_format.py", line 727, in _MergeField
merger(tokenizer, message, field)
File "C:\ProgramData\Anaconda3\envs\python35\lib\site-packages\google\protobuf\text_format.py", line 815, in _MergeMessageField
self._MergeField(tokenizer, sub_message)
File "C:\ProgramData\Anaconda3\envs\python35\lib\site-packages\google\protobuf\text_format.py", line 727, in _MergeField
merger(tokenizer, message, field)
File "C:\ProgramData\Anaconda3\envs\python35\lib\site-packages\google\protobuf\text_format.py", line 815, in _MergeMessageField
self._MergeField(tokenizer, sub_message)
File "C:\ProgramData\Anaconda3\envs\python35\lib\site-packages\google\protobuf\text_format.py", line 727, in _MergeField
merger(tokenizer, message, field)
File "C:\ProgramData\Anaconda3\envs\python35\lib\site-packages\google\protobuf\text_format.py", line 866, in _MergeScalarField
value = tokenizer.ConsumeString()
File "C:\ProgramData\Anaconda3\envs\python35\lib\site-packages\google\protobuf\text_format.py", line 1229, in ConsumeString
the_bytes = self.ConsumeByteString()
File "C:\ProgramData\Anaconda3\envs\python35\lib\site-packages\google\protobuf\text_format.py", line 1244, in ConsumeByteString
the_list = [self._ConsumeSingleByteString()]
File "C:\ProgramData\Anaconda3\envs\python35\lib\site-packages\google\protobuf\text_format.py", line 1269, in _ConsumeSingleByteString
result = text_encoding.CUnescape(text[1:-1])
File "C:\ProgramData\Anaconda3\envs\python35\lib\site-packages\google\protobuf\text_encoding.py", line 103, in CUnescape
result = ''.join(_cescape_highbit_to_str[ord(c)] for c in result)
File "C:\ProgramData\Anaconda3\envs\python35\lib\site-packages\google\protobuf\text_encoding.py", line 103, in
result = ''.join(_cescape_highbit_to_str[ord(c)] for c in result)
IndexError: list index out of range

Could you give me any suggestion? Thank you very much. My QQ number is 740052959

FLAGS arguments should be used in main() function where they are parsed, like:

flags.DEFINE_string('x', "", "some explation")
FLAGS = flags.FLAGS

x = FLAGS.x    # produce such error

def main(unused_argv):
  x = FLAGS.x  # work fine!

Traceback (most recent call last):
File "DeepSpeech.py", line 11, in
import absl.app
File "/home/sehar/venv/lib/python3.6/site-packages/absl/app.py", line 40, in
from absl import flags
File "/home/sehar/venv/lib/python3.6/site-packages/absl/flags/init.py", line 41, in
from absl.flags import _defines
File "/home/sehar/venv/lib/python3.6/site-packages/absl/flags/_defines.py", line 31, in
from absl.flags import _flagvalues
File "/home/sehar/venv/lib/python3.6/site-packages/absl/flags/_flagvalues.py", line 27, in
import logging
File "/home/sehar/DeepSpeech/logging.py", line 6, in
from util.flags import FLAGS
File "/home/sehar/DeepSpeech/util/flags.py", line 6, in
FLAGS = absl.flags.FLAGS
AttributeError: module 'absl' has no attribute 'flags'
kindly help me to slove this error

当我运行python research / object_detection / model_main.py --pipeline_config_path ='。/ research / object_detection / trainmodels / ssd_mobilenet_v1_pets.config'--model_dir ='。/ research / object_detection / trained2012 /'

追溯(最近一次通话最近): tf.app.run()中的 文件“ research
/ object_detection / model_main.py”,行103,文件“ /home/hd/.local/lib/python3.5/site-packages/ tensorflow / python / platform / app.py”,第48行,在运行 _sys.exit(main(_sys.argv [:1] + flags_passthrough)) 文件“ research / object_detection / model_main.py”,第57行,在主 配置中= tf.estimator.RunConfig(model_dir = FLAGS.model_dir) 文件“ /home/hd/.local/lib/python3.5/site-packages/absl/flags/_flagvalues.py”,第488行,在getattr中 引发_exceptions。 UnparsedFlagAccessError (error_message)absl.flags._exceptions.UnparsedFlagAccessError:尝试在解析标志之前访问标志--model_dir。


亲,我和你一样的问题,想请问一下您当时是怎么解决的?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you.

Closing as stale. Please reopen if you'd like to work on this further.

Was this page helpful?
0 / 5 - 0 ratings