Exemple #1
0
def load_meta_data(cfg):
    """

    Set the meta directories:
        |--self._opt.output_dir:
            |--models:
                |--self._opt.model_id:
                    |--opt_train.txt or opt_test.txt

    Returns:
        meta_data (EasyDict): the meta directories, it contains the followings:
            --checkpoints_dir:
    """

    output_dir = cfg.output_dir

    meta_data = EasyDict()
    meta_data["checkpoints_dir"] = mkdir(
        os.path.join(output_dir, "models", cfg.model_id))
    meta_data["personalized_ckpt_path"] = os.path.join(
        meta_data["checkpoints_dir"], "personalized.pth")
    meta_data["root_primitives_dir"] = mkdir(
        os.path.join(cfg.output_dir, "primitives"))
    meta_data["opt_path"] = os.path.join(meta_data["checkpoints_dir"],
                                         "opts.txt")

    if "src_path" in cfg:
        src_inputs = parse_src_input(cfg.src_path)
        root_primitives_dir = meta_data["root_primitives_dir"]

        meta_src = []

        for meta_inp in src_inputs:
            meta_proc = MetaProcess(meta_inp, root_primitives_dir)
            meta_src.append(meta_proc)
        meta_data["meta_src"] = meta_src

    if "ref_path" in cfg:
        ref_inputs = parse_ref_input(cfg.ref_path)

        root_primitives_dir = meta_data["root_primitives_dir"]

        meta_ref = []

        for meta_inp in ref_inputs:
            meta_proc = MetaProcess(meta_inp, root_primitives_dir)
            meta_ref.append(meta_proc)
        meta_data["meta_ref"] = meta_ref

    return meta_data
    def test_10_parse_src_missing_value(self):
        src_input = "/path1,bg_path?=|" \
                    "/path2,bg_path?=/bg_path2"

        src_meta_gt = [
            meta_info.SrcMetaInputInfo(path="/path1"),
            meta_info.SrcMetaInputInfo(path="/path2", bg_path="/bg_path2")
        ]

        src_meta_parse = meta_info.parse_src_input(src_input)

        for meta_gt, meta_parse in zip(src_meta_gt, src_meta_parse):
            print(meta_gt)
            print(meta_parse)

            self.assertEqual(meta_gt == meta_parse, True)
    def test_08_parse_src_only_path(self):
        src_input = "/path1|" \
                    "/path2"

        src_meta_gt = [
            meta_info.SrcMetaInputInfo(path="/path1"),
            meta_info.SrcMetaInputInfo(path="/path2")
        ]

        src_meta_parse = meta_info.parse_src_input(src_input)

        for meta_gt, meta_parse in zip(src_meta_gt, src_meta_parse):
            print(meta_gt)
            print(meta_parse)

            self.assertEqual(meta_gt == meta_parse, True)