Beispiel #1
0
def parse_args(args=None):
    parser = TFAIPArgumentParser()
    parser.add_argument("--export_dir",
                        required=True,
                        nargs="+",
                        action=ScenarioSelectionAction)
    parser.add_argument("--dump_prediction",
                        type=str,
                        help="Dumps the prediction results as tar.gz")

    args = parser.parse_args(args=args)
    return args, args.scenario, args.scenario_params
def main(args=None):
    parser = TFAIPArgumentParser()
    parser.add_argument("params_file",
                        type=str,
                        help="path to the trainer_params.json",
                        action=ScenarioSelectionAction)
    args = parser.parse_args(args=args)

    with WriteToLogFile(args.trainer.output_dir, append=False):
        # create the trainer
        trainer = args.scenario_cls.create_trainer(args.trainer, restore=False)
        trainer.train()
Beispiel #3
0
def parse_args(args=None):
    parser = TFAIPArgumentParser()
    parser.add_argument("--prediction",
                        type=str,
                        required=True,
                        help="Path to the prediction dump")
    parser.add_argument("--scenario",
                        type=str,
                        required=True,
                        action=ScenarioSelectionAction)

    args = parser.parse_args(args=args)
    return args.prediction, args.scenario, args.scenario_params
def parse_args(args=None):
    parser = TFAIPArgumentParser()
    parser.add_argument("--export_dir", required=True, type=str)
    parser.add_argument("--input_json", required=True, type=str)
    parser.add_argument("--out",
                        default=None,
                        type=str,
                        help="output folder or .json-file")
    parser.add_argument("--print",
                        default=False,
                        action="store_true",
                        help="print results to console too")
    args = parser.parse_args(args=args)
    return args
Beispiel #5
0
def parse_args(args=None):
    parser = TFAIPArgumentParser()

    parser.add_argument(
        "scenario_selection",
        help=
        "Select the scenario by providing the module path which must be in the PYTHONPATH. "
        "Since a module is expected, separate with dots '.' not slashes. "
        "The module must either comprise a 'scenario.py' file with one "
        "scenario, else provide the full path to the Scenario class by separating the class name "
        "with a ':'. E.g. 'tfaip.scenario.tutorial.min', or "
        "'tfaip.scenario.tutorial.min.scenario:TutorialScenario'",
        action=ScenarioSelectionAction,
    )

    args = parser.parse_args(args=args)
    return args.scenario_selection, args.trainer
Beispiel #6
0
def parse_args(args=None):
    parser = TFAIPArgumentParser(add_help=True)
    parser.add_argument("--export_dir", required=True, action=ScenarioSelectionAction)
    parser.add_argument(
        "--run_eagerly",
        action="store_true",
        help="Run the graph in eager mode. This is helpful for debugging. "
        "Note that all custom layers must be added to ModelBase!",
    )
    parser.add_argument(
        "--instantiate_graph",
        action="store_true",
        help="Recreate the original graph. This might be required in some edge cases.",
    )
    parser.add_argument("--dump", type=str, help="Dump the predictions and results to the given filepath")

    args = parser.parse_args(args=args)
    return args, args.scenario, args.scenario_params
Beispiel #7
0
def parse_args(args=None):

    parser = TFAIPArgumentParser()
    parser.add_argument("--export_dirs",
                        required=True,
                        nargs="+",
                        action=ScenarioSelectionAction)
    parser.add_argument(
        "--run_eagerly",
        action="store_true",
        help=
        "Run the graph in eager mode. This is helpful for debugging. Note that all custom layers must be added to ModelBase!",
    )
    parser.add_argument(
        "--dump",
        type=str,
        help="Dump the predictions and results to the given filepath")

    args = parser.parse_args(args=args)
    return args, args.scenario, args.scenario_params, args.predictor
def main(args=None):
    parser = TFAIPArgumentParser()
    parser.add_argument("output_dir",
                        type=str,
                        help="path to the checkpoint dir to resume from",
                        action=ScenarioSelectionAction)
    args = parser.parse_args(args=args)

    with WriteToLogFile(args.trainer.output_dir, append=True):
        logger.info(
            "================================================================="
        )
        logger.info(f"RESUMING TRAINING from {args.trainer.output_dir}")
        logger.info(
            "================================================================="
        )

        # create the trainer
        trainer = args.scenario_cls.create_trainer(args.trainer, restore=True)
        trainer.train()
Beispiel #9
0
def run():
    parser = TFAIPArgumentParser(
        description="Program to update older graphs to newer version."
        "Recreate the Graph of a model based on the current code and optional"
        "changed parameters, then loads the weights, and reexports the model "
        "with the adapted settings and code."
        "Note: the weights must be unchanged!"
        "This is for example useful to adapt a parameter in the stored model, e.g. "
        "the beam with or a weighting factor: --model.inference_decoder.beam_width=5"
    )

    parser.add_argument("export_dir",
                        action=ScenarioSelectionAction,
                        help="path to the checkpoint dir to resume from")
    parser.add_argument("--output_dir",
                        help="path where to write the model to")
    parser.add_argument("--overwrite",
                        help="overwrite the existing model",
                        action="store_true")
    parser.add_argument(
        "--no_check_loaded",
        help="do not check if the loaded weights match with the existing ones."
        "This is particularly useful if you change the size of the model, "
        "e.g. by adding a pretrained language model",
        action="store_true",
    )

    args = parser.parse_args()

    assert args.output_dir or args.overwrite, "either or required"
    if args.overwrite:
        args.output_dir = args.export_dir

    scenario_cls = args.scenario_cls

    trainer_params = scenario_cls.default_trainer_params()
    trainer_params.scenario = args.scenario
    trainer_params.scenario.print_eval_limit = 0

    scenario = trainer_params.scenario.create()
    # setup training and prediction graph with dummy settings
    scenario.setup_training("adam", skip_model_load_test=True)

    def store(path, to_path):
        assert path is not None
        assert to_path is not None
        print(f"Converting from {path} to {to_path}")
        r = scenario.keras_predict_model.load_weights(
            os.path.join(path, "serve", "variables", "variables"))
        if not args.no_check_loaded:
            r.assert_existing_objects_matched()
            print(
                "Variables successfully loaded. All existing objects matched.")
        else:
            print(
                "Skipping verification to check if all variables are present in the provided checkpoint."
            )
        print(f"Attempting to store new model to {to_path}")
        scenario.export(to_path, export_resources=path != to_path)
        print(f"{to_path} successfully written.")

    store(args.export_dir, args.output_dir)