def run(main=None, argv=None): """Runs the program with an optional 'main' function and 'argv' list.""" # Define help flags. _define_help_flags() # Parse known flags. argv = flags.FLAGS(_sys.argv if argv is None else argv, known_only=True) main = main # or _sys.modules['__main__'].main
def run(main=None, argv=None): """Runs the program with an optional 'main' function and 'argv' list.""" # Define help flags. _define_help_flags() # Parse known flags. argv = flags.FLAGS(_sys.argv if argv is None else argv, known_only=True) main = main or _sys.modules['__main__'].main # Call the main function, passing through any arguments # to the final program. _sys.exit(main(argv))
def run(main=None, argv=None): """Runs the program with an optional 'main' function and 'argv' list.""" # Define help flags. _define_help_flags() # Parse flags. try: argv = flags.FLAGS(_sys.argv if argv is None else argv) except flags.Error as error: _sys.stderr.write('FATAL Flags parsing error: %s\n' % error) _sys.stderr.write( 'Pass --helpshort or --helpfull to see help on flags.\n') _sys.exit(1) main = main or _sys.modules['__main__'].main # Call the main function, passing through any arguments # to the final program. _sys.exit(main(argv))
def _parse_flags_tolerate_undef(argv): """Parse args, returning any unknown flags (ABSL defaults to crashing).""" return flags.FLAGS(_sys.argv if argv is None else argv, known_only=True)
@app.route('/', methods=['POST']) def index(): ret = {'result': []} if not request.json or 'images' not in request.json: return json.dumps(ret) result = [] for idx, image in enumerate(request.json['images']): name = image['name'] content = base64.b64decode(image['content']) image = np.asarray(bytearray(content), dtype="uint8") channel = cv2.IMREAD_GRAYSCALE if FLAGS.image_channel == 1 else cv2.IMREAD_COLOR image_cv = cv2.imdecode(image, channel) image_cv = cv2.resize(image_cv, (FLAGS.image_width, FLAGS.image_height)) if FLAGS.image_channel == 1 : image_cv = np.expand_dims(image_cv, axis = 2) result.append(image_cv) while len(result) % FLAGS.batch_size : result.append(result[-1]) decode_text = [] for i in range(0, len(result), FLAGS.batch_size): decode_text += infer.infer(result[i:i+FLAGS.batch_size]) for idx, image in enumerate(request.json['images']): ret['result'].append({'name': image['name'], 'text' : decode_text[idx]}) return json.dumps(ret) if __name__ == '__main__': if tf_version <= '1.4.': flags.FLAGS._parse_flags() else : flags.FLAGS(sys.argv) app.run(host='0.0.0.0', debug=False, port=18888, threaded=True)