Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does tensorflow ignore undefined flags

I'm wrapping my tensorflow model in a simple flask server and I'm adding gunicorn wsgi for the flask server. When I ran the gunicorn and tried to send a request to call my train function that has been import to the flask server, I got an error from command line arguments parsing:

absl.flags._exceptions.UnrecognizedFlagError: Unknown command line flag 'b'

I know this flags is passed when gunicorn bind the address arguments, because I have no flags named as 'b' for tensorflow. So my question is how does tensorflow ignore these undefined flags that the tf.app.run() function will not complain?

FYI, Here is my server structure:

wsgi.py:

from simple_server import app

if __name__ == "__main__":
    app.run()

simple_server.py:

from my_tf_model import my_train

@app.route('/call_train', methods=['POST'])
def call_train():
    if request.method == 'POST':
        training_data = request.json
        my_train(training_data, param2)  
        return('Trained!')

my_tf_model.py:

tf.app.flags.DEFINE_integer('model_version',1, 'version number of the model.')
tf.app.flags.DEFINE_string('work_dir', '', 'Working directory.')
FLAGS = tf.app.flags.FLAGS

def my_train(param1, param2):
    # Train Algorithm
    export_path_base = FlAGS.work_dir
    # Exporting model code

def main(argv):

    my_train(param1, param2)

if __name__ == "__main__":
    tf.app.run()

Update:

I'm using tensorflow 1.5.x and python 3.6.0, the command that I used for gunicorn is:

gunicorn -b 0.0.0.0:5000 -t 30 wsgi:app

like image 364
RandomEli Avatar asked Feb 02 '18 23:02

RandomEli


1 Answers

I solved my problem by defining these flags in tensorflow model: my_tf_model.py.

tf.app.flags.DEFINE_string('bind', '', 'Server address')
tf.app.flags.DEFINE_integer('timeout', 30, 'Server timeout')

And then changed my gunicorn command line to use double dash style command line:

gunicorn --bind 0.0.0.0:5000 --timeout 30 wsgi:app

But I think there should be some other way rather than this hack to resolve the globally-used flags.

like image 132
RandomEli Avatar answered Sep 23 '22 02:09

RandomEli