Exemplo n.º 1
0
    def test_01_lwg_trainer(self):
        opt = EasyDict()

        opt.cfg_path = self.cfg_path
        opt.gpu_ids = "2"
        opt.model_id = "debug"
        opt.output_dir = "../tests/data"
        opt.verbose = True
        opt.temporal = False
        opt.load_iter = -1

        cfg = setup(opt)

        device = torch.device("cuda:{}".format(cfg.local_rank))

        lwg_trainer = LWGTrainer(cfg, device)
        lwg_trainer.gpu_wrapper()
def process_data():
    global args, iPER_train_txt, iPER_val_txt

    # 1. dumps videos to frames

    # 1. prepreocess
    vid_names = get_video_dirs(iPER_train_txt) + get_video_dirs(iPER_val_txt)
    src_paths = prepare_src_path(vid_names)

    args.src_path = "|".join(src_paths)

    # print(args.src_path)

    # set this as empty when preprocessing the training dataset.
    args.ref_path = ""

    cfg = setup(args)

    # 1. human estimation, including 2D pose, tracking, 3D pose, parsing, and front estimation.
    human_estimate(opt=cfg)

    # 2. digital deformation.
    digital_deform(opt=cfg)

    # 3. check
    meta_src_proc = cfg.meta_data["meta_src"]
    invalid_meta_process = []
    print(f"Check all videos have been processed...")
    for meta_proc in tqdm(meta_src_proc):
        process_info = ProcessInfo(meta_proc)
        process_info.deserialize()

        # check it has been processed successfully
        if not process_info.check_has_been_processed(process_info.vid_infos,
                                                     verbose=False):
            invalid_meta_process.append(meta_proc)

    num_invalid = len(invalid_meta_process)
    if num_invalid > 0:
        for meta_proc in invalid_meta_process:
            print(f"invalid meta proc {meta_proc}")

    else:
        print(f"process successfully.")
def process_data():
    # 1. preprocess
    src_paths = prepare_src_path()

    args.src_path = "|".join(src_paths)

    print(args.src_path)

    # set this as empty when preprocessing the training dataset.
    args.ref_path = ""

    cfg = setup(args)

    # 1. human estimation, including 2D pose, tracking, 3D pose, parsing, and front estimation.
    human_estimate(opt=cfg)

    # 2. digital deformation.
    digital_deform(opt=cfg)

    # 3. check
    meta_src_proc = cfg.meta_data["meta_src"]
    invalid_meta_process = []
    for meta_proc in meta_src_proc:
        process_info = ProcessInfo(meta_proc)
        process_info.deserialize()

        # check it has been processed successfully
        if not process_info.check_has_been_processed(process_info.vid_infos,
                                                     verbose=False):
            invalid_meta_process.append(meta_proc)

    num_invalid = len(invalid_meta_process)
    if num_invalid > 0:
        for meta_proc in invalid_meta_process:
            print(f"invalid meta proc {meta_proc}")

    else:
        print(f"process successfully.")
Exemplo n.º 4
0
parser.add_argument("--ref_path", type=str, default="", help=ref_path_format)

args = parser.parse_args()

# symlink from the actual assets directory to this current directory
work_asserts_dir = os.path.join("./assets")
if not os.path.exists(work_asserts_dir):
    os.symlink(osp.abspath(args.assets_dir),
               osp.abspath(work_asserts_dir),
               target_is_directory=(platform.system() == "Windows"))

args.cfg_path = osp.join(work_asserts_dir, "configs", "deploy.toml")

if __name__ == "__main__":
    # run imitator
    cfg = setup(args)
    run_imitator(cfg)

# # or use the system call wrapper
# cmd = [
#     sys.executable, "-m", "iPERCore.services.run_imitator",
#     "--gpu_ids", args.gpu_ids,
#     "--image_size", str(args.image_size),
#     "--num_source", str(args.num_source),
#     "--output_dir", args.output_dir,
#     "--model_id", args.model_id,
#     "--src_path", args.src_path,
#     "--ref_path", args.ref_path
# ]
#
# subprocess.call(cmd)
def main():
    # set this as empty when preprocessing the training dataset.
    args.ref_path = ""

    cfg = setup(args)
    cfg.num_source = 4
    cfg.time_step = 2

    dataset = DatasetFactory.get_by_name(cfg.dataset_mode,
                                         cfg,
                                         is_for_train=True)

    dataloader = torch.utils.data.DataLoader(dataset,
                                             batch_size=2,
                                             num_workers=4,
                                             pin_memory=True)

    device = torch.device("cuda:0")

    flow_comp = FlowCompositionForTrainer(cfg)
    flow_comp = flow_comp.to(device)

    for inputs in tqdm(dataloader):
        images = inputs["images"].to(device, non_blocking=True)
        smpls = inputs["smpls"].to(device, non_blocking=True)
        masks = inputs["masks"].to(device, non_blocking=True)
        offsets = inputs["offsets"].to(
            device, non_blocking=True) if "offsets" in inputs else 0
        links_ids = inputs["links_ids"].to(
            device, non_blocking=True) if "links_ids" in inputs else None
        aug_bg = inputs["bg"].to(device,
                                 non_blocking=True) if "bg" in inputs else None

        ns = cfg.num_source
        src_img = images[:, 0:ns].contiguous()
        src_smpl = smpls[:, 0:ns].contiguous()
        tsf_img = images[:, ns:].contiguous()
        tsf_smpl = smpls[:, ns:].contiguous()
        src_mask = masks[:, 0:ns].contiguous()
        ref_mask = masks[:, ns:].contiguous()

        ##################################################################
        # input_G_bg  (bs, 1, 4, 512, 512): for background inpainting network,
        # input_G_src (bs, ns, 6, 512, 512): for source identity network,
        # input_G_tsf (bs, nt, 6, 512, 512): for transfer network,
        # Tst (bs, ns, nt, 512, 512, 2):  the transformation flows from source (s_i) to target (t_j);
        # Ttt ():  if temporal is True, transformation from last time target (t_{j-1)
        #          to current time target (t_j), otherwise, it is None.
        #
        # src_mask  (bs, ns, 1, 512, 512): the source masks;
        # tsf_mask  (bs, nt, 1, 512, 512): the target masks;
        # head_bbox (ns, 4): the head bounding boxes of all targets;
        # body_bbox (ns, 4): the body bounding boxes of all targets;
        # uv_img (bs, 3, 512, 512): the extracted uv images, for visualization.
        ################################################################

        input_G_bg, input_G_src, input_G_tsf, Tst, Ttt, src_mask, tsf_mask, head_bbox, body_bbox, uv_img = \
            flow_comp(src_img, tsf_img, src_smpl, tsf_smpl, src_mask=src_mask, ref_mask=ref_mask,
                      links_ids=links_ids, offsets=offsets, temporal=cfg.temporal)

        visualizer.vis_named_img("input_G_bg", input_G_bg[0:1, 0, 0:3])
        visualizer.vis_named_img("input_G_src", input_G_src[0, :, 0:3])
        visualizer.vis_named_img("input_G_tsf", input_G_tsf[0, :, 0:3])
        visualizer.vis_named_img("src_mask", src_mask[0])
        visualizer.vis_named_img("tsf_mask", tsf_mask[0])
        visualizer.vis_named_img("src_img", src_img[0])
        visualizer.vis_named_img("tsf_img", tsf_img[0])
        visualizer.vis_named_img("uv_img", uv_img[0:1])

        if aug_bg is not None:
            visualizer.vis_named_img("aug_bg", aug_bg)
            print(f"aug_bg = {aug_bg.shape}")

        print(f"input_G_bg = {input_G_bg.shape}")
        print(f"input_G_src = {input_G_src.shape}")
        print(f"input_G_tsf = {input_G_tsf.shape}")
        print(f"Tst = {Tst.shape}")
        print(f"src_mask = {src_mask.shape}")
        print(f"tsf_mask = {tsf_mask.shape}")
        print(f"head_bbox = {head_bbox.shape}")
        print(f"body_bbox = {body_bbox.shape}")
        print(f"uv_img = {uv_img.shape}")