After using many python scripts with the same Tensorflow FLAGS, I got tired of updating multiple flags for each change and so decided to refactor tf.app.flags
into a separate class which I could reuse across scripts.
However, for some strange reason, whenever I use self.flags
in a different method it fails to recognise a previously set flag. The following class for example will work fine for flag project_dir2
but will fail for flag project_dir3
`class MyClass():
def __init__(self):
self.flags = tf.app.flags
self.FLAGS = self.flags.FLAGS
#test code that works here
self.flags.DEFINE_string("project_dir2", "aValue", "project directory")
print("This will print correctly: "+self.FLAGS.project_dir2)
self.my_function()
def my_function(self):
#test code that fails
self.flags.DEFINE_string("project_dir3", "aValue", "project directory")
print("This will fail: "+self.FLAGS.project_dir3)`
I get the following exception:
AttributeError: project_dir2
Exception TypeError: TypeError("'NoneType' object is not callable",) in <function _remove at 0x7fd4c3090668> ignored
Is there something obvious I'm doing wrong? Or is this something you simply cannot do with Tensorflow flags? Does that mean there's no way of refactoring commonly used flag settings across scripts?