def main(argv=None):
    print("start of main")
    main_time = time.time()

    os.makedirs(RESULT_DIR)

    # loging
    LOG_FILE = os.path.join(RESULT_DIR, "log.txt")
    logger.set_logger(level=FLAGS.get('log_level'),
                      stream=True,
                      fileh=True,
                      filename=LOG_FILE)

    # file handling
    logger.info("create folder for results: {}".format(RESULT_DIR))
    if FLAGS.checkpoint_step > 0:
        os.mkdir(CHECKPOINT_DIR)
        logger.info("create checkpoints folder: {}".format(CHECKPOINT_DIR))

    # import the corresponding module
    # what about models.model ????????
    try:
        model_path = 'models.' + FLAGS.get('model').lower()
        model_module = __import__(model_path, fromlist=[''])
    except ImportError:
        raise ValueError("no such model exists: {}".format())

    # parse all FLAGS
    FLAGS.parse_and_log()

    # start training
    train(model_module.Model)

    # pring something before end
    logger.newline(2)
    logger.info("total time used: {}".format(time.time() - main_time))
    logger.info("summary dir: " + RESULT_DIR)
    logger.newline()
    logger.info("~end of main~")
Ejemplo n.º 2
0
logger.newline()
logger.error("newline beneath~")
logger.newline(2)
logger.info("haha")

# ================================
# test FLAGS
# ================================
FLAGS.add("--aa", type=float, default=11., help="doc for dd")
logger.info("aa: {}".format(FLAGS.get('aa')))
# for flag that should be overwrite later, don't set default
FLAGS.add("--bb", type=int, default=None, help="doc for dd")
if FLAGS.get('aa') == 11:
    FLAGS.overwrite_none(bb=15)

FLAGS.add("--cc", type=bool, default=False, help="doc for dd")
FLAGS.add("--dd", type=str, default="dddddd", help="doc for dd")
# for flag that should be overwrite later, don't set default
FLAGS.add("--ff", type=str, help="doc for dd")
FLAGS.add("--gg", type=str, help="doc for dd")
FLAGS.add("--hh", type=str, default="hhhhh", help="doc for dd")
# overwrite or set new default values
FLAGS.overwrite_defaults(dd="replaced dd", ee="an extra flag", ff="ff")
FLAGS.overwrite_none(hh="this won't show", gg="gggg", ii="illigal")
FLAGS.add("--jj", type=str, default="hhhhh", help="doc for dd")

# parse FLAGS at the start of main()
FLAGS.parse_and_log()
logger.info(FLAGS.gg)
logger.info(FLAGS.ii)