DuplicateFlagError: The flag 'master' is defined twice. First from E:/project/models/research/object_detection/train.py, Second from E:/project/models/research/object_detection/train.py. Description from first occurrence: Name of the TensorFlow master to use.
Please go to Stack Overflow for help and support:
http://stackoverflow.com/questions/tagged/tensorflow
Also, please understand that many of the models included in this repository are experimental and research-style code. If you open a GitHub issue, here is our policy:
- It must be a bug, a feature request, or a significant problem with documentation (for small docs fixes please send a PR instead).
- The form below must be filled out.
Here's why we have that policy: TensorFlow developers respond to issues. We want to focus on work that benefits the whole community, e.g., fixing bugs and adding features. Support only helps individuals. GitHub also notifies thousands of people when issues are filed. We want them to see you communicating an interesting problem, rather than being redirected to Stack Overflow.
System information
- What is the top-level directory of the model you are using:
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow):
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04):
- TensorFlow installed from (source or binary):
- TensorFlow version (use command below):
- Bazel version (if compiling from source):
- CUDA/cuDNN version:
- GPU model and memory:
- Exact command to reproduce:
You can collect some of this information using our environment capture script:
https://github.com/tensorflow/tensorflow/tree/master/tools/tf_env_collect.sh
You can obtain the TensorFlow version with
python -c "import tensorflow as tf; print(tf.GIT_VERSION, tf.VERSION)"
Describe the problem
Describe the problem clearly here. Be sure to convey here why it's a bug in TensorFlow or a feature request.
Source code / logs
Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached. Try to provide a reproducible test case that is the bare minimum necessary to generate the problem.
can anyone help me
####Delete all flags before declare#####
def del_all_flags(FLAGS):
flags_dict = FLAGS._flags()
keys_list = [keys for keys in flags_dict]
for keys in keys_list:
FLAGS.delattr(keys)
del_all_flags(tf.flags.FLAGS)
Hi There, We are checking to see if you still need help on this, as this seems to be considerably old issue. Please update this issue with the latest information, code snippet to reproduce your issue and error you are seeing. If we don't hear from you in the next 7 days, this issue will be closed automatically. If you don't need help on this issue any more, please consider closing this.
DuplicateFlagError: The flag 'train_label' is defined twice. First from E:\Anaconda3\lib\site-packages\ipykernel_launcher.py, Second from E:\Anaconda3\lib\site-packages\ipykernel_launcher.py. Description from first occurrence: Training label file
can anyone help me
can anyone help me
i am getting the same issue. can you help regarding that how you had solved
can anyone help me
i am getting the same issue. can you help regarding that how you had solved
Delete all the flags before you assign them like this:
for name in list(flags.FLAGS): delattr(flags.FLAGS,name)
can anyone help me
same issue, anyone can help me?
did you delete all the flags?
did you delete all the flags?
just delete all the flags?
here is the code, and the issue is train_dir defined twice. from future import absolute_import from future import division from future import print_function
from datetime import datetime import time
#import tensorflow as tf import tensorflow.compat.v1 as tf tf.disable_v2_behavior() from tensorflow.models.tutorials.image.cifar10 import cifar10,cifar10_input #import cifar10
def del_all_flags(FLAGS):
flags_dict = FLAGS._flags()
keys_list = [keys for keys in flags_dict]
for keys in keys_list:
FLAGS.delattr(keys)
FLAGS = tf.app.flags.FLAGS
tf.app.flags.DEFINE_string('train_dir', 'cifar10_train_xzy', """Directory where to write event logs and checkpoint.""") tf.app.flags.DEFINE_integer('max_steps', 200, """Number of batches to run.""") tf.app.flags.DEFINE_boolean('log_device_placement', False, """Whether to log device placement.""") tf.app.flags.DEFINE_integer('log_frequency', 100, """How often to log results to the console.""")
def train(): """ 多步训练CIFAR-10数据集 """ with tf.Graph().as_default(): global_step = tf.contrib.framework.get_or_create_global_step()
# 指定 CPU:0 进行数据的变形处理
with tf.device('/cpu:0'):
images, labels = cifar10.distorted_inputs()
# inference 前向预测,定义在cifar10.py文件
logits = cifar10.inference(images)
# loss.
loss = cifar10.loss(logits, labels)
# train
train_op = cifar10.train(loss, global_step)
class _LoggerHook(tf.train.SessionRunHook):
"""记录 loss 和 runtime."""
def __init__(self):
self._start_time = time.time()
self._step = -1
def begin(self):
pass
def before_run(self, run_context):
self._step += 1
return tf.train.SessionRunArgs(loss) # 将loss 操作加到Session.run()调用
def after_run(self, run_context, run_values):
if self._step % FLAGS.log_frequency == 0:
current_time = time.time()
duration = current_time - self._start_time
self._start_time = current_time
loss_value = run_values.results
examples_per_sec = FLAGS.log_frequency * FLAGS.batch_size / duration
sec_per_batch = float(duration / FLAGS.log_frequency)
format_str = '%s: step %d, loss = %.2f (%.1f examples/sec; %.3f ' 'sec/batch)'
print(format_str % (datetime.now(), self._step, loss_value,
examples_per_sec, sec_per_batch))
with tf.train.MonitoredTrainingSession(
checkpoint_dir=FLAGS.train_dir,
hooks=[tf.train.StopAtStepHook(last_step=FLAGS.max_steps), # 在运行指定步长后停止
tf.train.NanTensorHook(loss), # 监视loss,如果loss==NaN,停止训练
_LoggerHook()],
# log_device_placement是否打印设备分配日志
config=tf.ConfigProto(log_device_placement=FLAGS.log_device_placement)) as mon_sess:
while not mon_sess.should_stop():
mon_sess.run(train_op)
def main(argv=None): # pylint: disable=unused-argument cifar10.maybe_download_and_extract() # 调用cifar10.py中的方法, 准备数据 if tf.gfile.Exists(FLAGS.train_dir): tf.gfile.DeleteRecursively(FLAGS.train_dir) tf.gfile.MakeDirs(FLAGS.train_dir) train() # 开始训练
if name == 'main': del_all_flags(tf.flags.FLAGS) tf.app.run()
did you delete all the flags?
It is the response above yours but add this after the imports
can anyone help me
i am getting the same issue. can you help regarding that how you had solved
Delete all the flags before you assign them like this:
for name in list(flags.FLAGS): delattr(flags.FLAGS,name)
there are some other ways around this but try this first
I am busy know. Ill look at what I did tonight or tomorrow.
From: jiabinwang [email protected] Sent: Monday, October 12, 2020 3:15 PM To: tensorflow/models [email protected] Cc: robisen1 [email protected]; Comment [email protected] Subject: Re: [tensorflow/models] DuplicateFlagError: The flag 'master' is defined twice. First from E:/project/models/research/object_detection/train.py, Second from E:/project/models/research/object_detection/train.py. Description from first occurrence: Name of
here is the code, and the issue is train_dir defined twice. from future import absolute_import from future import division from future import print_function
from datetime import datetime import time
#import tensorflow as tf import tensorflow.compat.v1 as tf tf.disable_v2_behavior() from tensorflow.models.tutorials.image.cifar10 import cifar10,cifar10_input #import cifar10
def del_all_flags(FLAGS): flags_dict = FLAGS._flags() keys_list = [keys for keys in flags_dict] for keys in keys_list: FLAGS.delattr(keys)
FLAGS = tf.app.flags.FLAGS
tf.app.flags.DEFINE_string('train_dir', 'cifar10_train_xzy', """Directory where to write event logs and checkpoint.""") tf.app.flags.DEFINE_integer('max_steps', 200, """Number of batches to run.""") tf.app.flags.DEFINE_boolean('log_device_placement', False, """Whether to log device placement.""") tf.app.flags.DEFINE_integer('log_frequency', 100, """How often to log results to the console.""")
def train(): """ 多步训练CIFAR-10数据集 """ with tf.Graph().as_default(): global_step = tf.contrib.framework.get_or_create_global_step()
# 指定 CPU:0 进行数据的变形处理
with tf.device('/cpu:0'):
images, labels = cifar10.distorted_inputs()
# inference 前向预测,定义在cifar10.py文件
logits = cifar10.inference(images)
# loss.
loss = cifar10.loss(logits, labels)
# train
train_op = cifar10.train(loss, global_step)
class _LoggerHook(tf.train.SessionRunHook):
"""记录 loss 和 runtime."""
def __init__(self):
self._start_time = time.time()
self._step = -1
def begin(self):
pass
def before_run(self, run_context):
self._step += 1
return tf.train.SessionRunArgs(loss) # 将loss 操作加到Session.run()调用
def after_run(self, run_context, run_values):
if self._step % FLAGS.log_frequency == 0:
current_time = time.time()
duration = current_time - self._start_time
self._start_time = current_time
loss_value = run_values.results
examples_per_sec = FLAGS.log_frequency * FLAGS.batch_size / duration
sec_per_batch = float(duration / FLAGS.log_frequency)
format_str = '%s: step %d, loss = %.2f (%.1f examples/sec; %.3f ' 'sec/batch)'
print(format_str % (datetime.now(), self._step, loss_value,
examples_per_sec, sec_per_batch))
with tf.train.MonitoredTrainingSession(
checkpoint_dir=FLAGS.train_dir,
hooks=[tf.train.StopAtStepHook(last_step=FLAGS.max_steps), # 在运行指定步长后停止
tf.train.NanTensorHook(loss), # 监视loss,如果loss==NaN,停止训练
_LoggerHook()],
# log_device_placement是否打印设备分配日志
config=tf.ConfigProto(log_device_placement=FLAGS.log_device_placement)) as mon_sess:
while not mon_sess.should_stop():
mon_sess.run(train_op)
def main(argv=None): # pylint: disable=unused-argument cifar10.maybe_download_and_extract() # 调用cifar10.py中的方法, 准备数据 if tf.gfile.Exists(FLAGS.train_dir): tf.gfile.DeleteRecursively(FLAGS.train_dir) tf.gfile.MakeDirs(FLAGS.train_dir) train() # 开始训练
if name == 'main': del_all_flags(tf.flags.FLAGS) tf.app.run()
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/tensorflow/models/issues/5360#issuecomment-707372003 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSF2RO4GPY4DKQXQG6NM5TSKN5VNANCNFSM4FWVKHCA . https://github.com/notifications/beacon/ABSF2RO6JCPYWZRJWZJ4OQTSKN5VNA5CNFSM4FWVKHCKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOFIU2HYY.gif
Can you point me to this file in repo. I cannot seem to find it
From: jiabinwang [email protected] Sent: Monday, October 12, 2020 3:15 PM To: tensorflow/models [email protected] Cc: robisen1 [email protected]; Comment [email protected] Subject: Re: [tensorflow/models] DuplicateFlagError: The flag 'master' is defined twice. First from E:/project/models/research/object_detection/train.py, Second from E:/project/models/research/object_detection/train.py. Description from first occurrence: Name of
here is the code, and the issue is train_dir defined twice. from future import absolute_import from future import division from future import print_function
from datetime import datetime import time
#import tensorflow as tf import tensorflow.compat.v1 as tf tf.disable_v2_behavior() from tensorflow.models.tutorials.image.cifar10 import cifar10,cifar10_input #import cifar10
def del_all_flags(FLAGS): flags_dict = FLAGS._flags() keys_list = [keys for keys in flags_dict] for keys in keys_list: FLAGS.delattr(keys)
FLAGS = tf.app.flags.FLAGS
tf.app.flags.DEFINE_string('train_dir', 'cifar10_train_xzy', """Directory where to write event logs and checkpoint.""") tf.app.flags.DEFINE_integer('max_steps', 200, """Number of batches to run.""") tf.app.flags.DEFINE_boolean('log_device_placement', False, """Whether to log device placement.""") tf.app.flags.DEFINE_integer('log_frequency', 100, """How often to log results to the console.""")
def train(): """ 多步训练CIFAR-10数据集 """ with tf.Graph().as_default(): global_step = tf.contrib.framework.get_or_create_global_step()
# 指定 CPU:0 进行数据的变形处理
with tf.device('/cpu:0'):
images, labels = cifar10.distorted_inputs()
# inference 前向预测,定义在cifar10.py文件
logits = cifar10.inference(images)
# loss.
loss = cifar10.loss(logits, labels)
# train
train_op = cifar10.train(loss, global_step)
class _LoggerHook(tf.train.SessionRunHook):
"""记录 loss 和 runtime."""
def __init__(self):
self._start_time = time.time()
self._step = -1
def begin(self):
pass
def before_run(self, run_context):
self._step += 1
return tf.train.SessionRunArgs(loss) # 将loss 操作加到Session.run()调用
def after_run(self, run_context, run_values):
if self._step % FLAGS.log_frequency == 0:
current_time = time.time()
duration = current_time - self._start_time
self._start_time = current_time
loss_value = run_values.results
examples_per_sec = FLAGS.log_frequency * FLAGS.batch_size / duration
sec_per_batch = float(duration / FLAGS.log_frequency)
format_str = '%s: step %d, loss = %.2f (%.1f examples/sec; %.3f ' 'sec/batch)'
print(format_str % (datetime.now(), self._step, loss_value,
examples_per_sec, sec_per_batch))
with tf.train.MonitoredTrainingSession(
checkpoint_dir=FLAGS.train_dir,
hooks=[tf.train.StopAtStepHook(last_step=FLAGS.max_steps), # 在运行指定步长后停止
tf.train.NanTensorHook(loss), # 监视loss,如果loss==NaN,停止训练
_LoggerHook()],
# log_device_placement是否打印设备分配日志
config=tf.ConfigProto(log_device_placement=FLAGS.log_device_placement)) as mon_sess:
while not mon_sess.should_stop():
mon_sess.run(train_op)
def main(argv=None): # pylint: disable=unused-argument cifar10.maybe_download_and_extract() # 调用cifar10.py中的方法, 准备数据 if tf.gfile.Exists(FLAGS.train_dir): tf.gfile.DeleteRecursively(FLAGS.train_dir) tf.gfile.MakeDirs(FLAGS.train_dir) train() # 开始训练
if name == 'main': del_all_flags(tf.flags.FLAGS) tf.app.run()
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/tensorflow/models/issues/5360#issuecomment-707372003 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ABSF2RO4GPY4DKQXQG6NM5TSKN5VNANCNFSM4FWVKHCA . https://github.com/notifications/beacon/ABSF2RO6JCPYWZRJWZJ4OQTSKN5VNA5CNFSM4FWVKHCKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOFIU2HYY.gif