code: def main(args=None):
      if args is None:
          args = sys.argv[1:]
  
      parameters = process_args(args, Config)
      logging.basicConfig(
          level=logging.DEBUG,
          format="%(asctime)-15s %(name)-5s %(levelname)-8s %(message)s",
          filename=parameters.log_path,
      )
      console = logging.StreamHandler()
      console.setLevel(logging.INFO)
      formatter = logging.Formatter(
          "%(asctime)-15s %(name)-5s %(levelname)-8s %(message)s"
      )
      console.setFormatter(formatter)
      logging.getLogger("").addHandler(console)
  
      with tf.compat.v1.Session(
          config=tf.compat.v1.ConfigProto(allow_soft_placement=True)
      ) as sess:
          if parameters.phase == "dataset":
              dataset.generate(
                  parameters.annotations_path,
                  parameters.output_path,
                  parameters.log_step,
                  parameters.force_uppercase,
                  parameters.save_filename,
              )
              return
  
          if parameters.full_ascii:
              DataGen.set_full_ascii_charmap()
  
          model = Model(
              phase=parameters.phase,
              visualize=parameters.visualize,
              output_dir=parameters.output_dir,
              batch_size=parameters.batch_size,
              initial_learning_rate=parameters.initial_learning_rate,
              steps_per_checkpoint=parameters.steps_per_checkpoint,
              model_dir=parameters.model_dir,
              target_embedding_size=parameters.target_embedding_size,
              attn_num_hidden=parameters.attn_num_hidden,
              attn_num_layers=parameters.attn_num_layers,
              clip_gradients=parameters.clip_gradients,
              max_gradient_norm=parameters.max_gradient_norm,
              session=sess,
              load_model=parameters.load_model,
              gpu_id=parameters.gpu_id,
              use_gru=parameters.use_gru,
              use_distance=parameters.use_distance,
              max_image_width=parameters.max_width,
              max_image_height=parameters.max_height,
              max_prediction_length=parameters.max_prediction,
              channels=parameters.channels,
          )
  
          if parameters.phase == "train":
              model.train(
                  data_path=parameters.dataset_path,
                  num_epoch=parameters.num_epoch,
              )
          elif parameters.phase == "test":
              model.test(data_path=parameters.dataset_path)
          elif parameters.phase == "predict":
              for line in sys.stdin:
                  filename = line.rstrip()
                  try:
                      with open(filename, "rb") as img_file:
                          img_file_data = img_file.read()
                  except IOError:
                      logging.error(
                          "Result: error while opening file %s.",
                          filename,
                      )
                      continue
                  text, probability = model.predict(img_file_data)
                  logging.info(
                      "Result: OK. %s %s",
                      "{:.2f}".format(probability),
                      text,
                  )
          elif parameters.phase == "export":
              exporter = Exporter(model)
              exporter.save(parameters.export_path, parameters.format)
              return
          else:
              raise NotImplementedError
  
file_path: attention-ocr/aocr/__main__.py
imports: from __future__ import absolute_import
  import sys
  import argparse
  import logging
  import tensorflow
  from .model.model import Model
  from .defaults import Config
  from .util import dataset
  from .util.data_gen import DataGen
  from .util.export import Exporter
label_desc: Use image node_id 2 for calling a global function with example usage: main(args) without return types