Пример #1
0
def main() -> None:
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("config",
                        metavar="INI-FILE",
                        help="a configuration file")
    parser.add_argument("--code",
                        "-c",
                        action="store_true",
                        help="instead of building the config, generate "
                        "equivalent Python code and write it to stdout")
    args = parser.parse_args()

    with open(args.config, "r", encoding="utf-8") as f:
        _, config_dict = parse_file(f)

    if args.code:
        imports, statements = _patch_config_builder()

    config, _ = build_config(config_dict, ignore_names=set())

    if args.code:
        print("import argparse\nimport tensorflow as tf")
        print(*sorted(imports), sep="\n", end="\n\n")
        print(*statements, sep="\n", end="\n\n")
        print("model = argparse.Namespace({})".format(",".join(
            "\n    {}={}".format(key, config[key]) for key in config)))
Пример #2
0
 def build_model(self, warn_unused=False) -> None:
     log("Building model based on the config.")
     self._check_loaded_conf()
     try:
         model = build_config(self.config_dict, self.ignored, warn_unused)
     # pylint: disable=broad-except
     except Exception as exc:
         log("Failed to build model: {}".format(exc), color="red")
         traceback.print_exc()
         exit(1)
     log("Model built.")
     self.model = self.make_namespace(model)
Пример #3
0
 def build_model(self, warn_unused=False) -> None:
     log("Building model based on the config.")
     self._check_loaded_conf()
     try:
         model, self.objects = build_config(self.config_dict, self.ignored,
                                            warn_unused)
     # pylint: disable=broad-except
     except Exception as exc:
         log("Failed to build model: {}".format(exc), color="red")
         traceback.print_exc()
         exit(1)
     log("Model built.")
     self.model = self.make_namespace(model)