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 _setup_dirs(self, meta_src, meta_ref): src_name = meta_src.meta_input["name"] ref_name = meta_ref.meta_input["name"] src_ref_name = f"{src_name}-{ref_name}" synthesized_dir = mkdir(os.path.join(meta_src.primitives_dir, "synthesis")) out_img_dir = mkdir(os.path.join(synthesized_dir, "imitations", f"{src_ref_name}")) self.src_name = src_name self.ref_name = ref_name self.src_ref_name = src_ref_name self.synthesized_dir = synthesized_dir self.out_img_dir = out_img_dir self.out_mp4 = out_img_dir + ".mp4"
def __init__(self, meta_input: MetaInputInfo, root_primitives_dir: str): """ Args: meta_input (MetaInputInfo): root_primitives_dir: """ primitives_dir = mkdir(os.path.join(root_primitives_dir, meta_input.name)) processed_dir = mkdir(os.path.join(primitives_dir, "processed")) meta_input = self.update_meta_input(meta_input, processed_dir) self.meta_input = meta_input.get_info() self.primitives_dir = primitives_dir self.processed_dir = processed_dir self.vid_info_path = os.path.join(processed_dir, "vid_info.pkl")
def __init__(self, meta_src): """ Args: meta_src (MetaProcess): """ src_name = meta_src.meta_input["name"] synthesized_dir = mkdir(os.path.join(meta_src.primitives_dir, "synthesis")) out_img_dir = mkdir(os.path.join(synthesized_dir, "viewers")) self.src_name = src_name self.out_img_dir = out_img_dir self.out_mp4 = out_img_dir + ".mp4"
def format_imgs_dir(src_path, imgs_dir): if not osp.exists(src_path): raise FileNotFoundError(f"{src_path} does not exist. Please provide a existing path.") if is_image_file(src_path): # if `src_path` is a image path, the the image will be copied to `output_dir/frames`. imgs_dir = mkdir(imgs_dir) dst_path = osp.join(imgs_dir, osp.split(src_path)[-1]) # create a symbolic link if src_path != dst_path and not osp.exists(dst_path): # TODO, handle the Privilege Error (WinError 1314) of os.symlink in Windows? Need help. if platform.system().lower() == "windows": shutil.copy(src_path, dst_path) else: os.symlink(osp.abspath(src_path), osp.abspath(dst_path)) elif is_video_file(src_path): imgs_dir = mkdir(imgs_dir) # * if `src_path` is a video path, then use `ffmpeg` to extract the frames into `output_dir/frames`. video2frames(src_path, imgs_dir) elif osp.isdir(src_path): # * if `src_path` is a directory that contains multiple images, then these images will # be copied to `output_dir/frames`. if src_path != imgs_dir and not osp.exists(imgs_dir): # TODO, handle the Privilege Error (WinError 1314) of os.symlink in Windows? Need help. if platform.system().lower() == "windows": if osp.exists(imgs_dir): shutil.rmtree(imgs_dir) shutil.copytree(src_path, imgs_dir) else: os.symlink(osp.abspath(src_path), osp.abspath(imgs_dir)) else: raise ValueError("imgs_dir {} is not image path, video path and image directory.".format(imgs_dir)) return imgs_dir
def __init__(self, meta_src, meta_ref): """ Args: meta_src (MetaProcess): meta_ref (MetaProcess): """ src_name = meta_src.meta_input["name"] ref_name = meta_ref.meta_input["name"] synthesized_dir = mkdir( os.path.join(meta_src.primitives_dir, "synthesis")) src_ref_name = f"{src_name}-{ref_name}" imitation_dir = mkdir( os.path.join(synthesized_dir, "imitations", f"{src_ref_name}")) swapper_dir = mkdir( os.path.join(synthesized_dir, "swappers", f"{src_ref_name}")) viewer_dir = mkdir(os.path.join(synthesized_dir, "viewers")) self.src_name = src_name self.ref_name = ref_name self.audio = meta_ref.meta_input["audio"] self.fps = meta_ref.meta_input["fps"] self.pose_fc = meta_ref.meta_input["pose_fc"] self.cam_fc = meta_ref.meta_input["cam_fc"] self.src_ref_name = src_ref_name self.synthesized_dir = synthesized_dir self.imitation_dir = imitation_dir self.imitation_mp4 = imitation_dir + ".mp4" self.swapper_dir = swapper_dir self.swapper_mp4 = swapper_dir + ".mp4" self.viewer_dir = viewer_dir self.viewer_mp4 = viewer_dir + ".mp4"
def _setup_dirs(self, meta_src_or_list, meta_ref): all_src_name = [] for meta_src in meta_src_or_list: all_src_name.append(meta_src.meta_input["name"]) src_name = "+".join(all_src_name) # get the primary meta_src meta_src = meta_src_or_list[0] ref_name = meta_ref.meta_input["name"] src_ref_name = f"{src_name}-{ref_name}" synthesized_dir = mkdir(os.path.join(meta_src.primitives_dir, "synthesis")) out_img_dir = mkdir(os.path.join(synthesized_dir, "swappers", f"{src_ref_name}")) self.src_name = src_name self.ref_name = ref_name self.src_ref_name = src_ref_name self.synthesized_dir = synthesized_dir self.out_img_dir = out_img_dir self.out_mp4 = out_img_dir + ".mp4"
help="the root directory of iPER dataset.") parser.add_argument("--gpu_ids", type=str, default="9", help="the gpu ids.") args = parser.parse_args() # the render image size IMAGE_SIZE = 1080 MotionSynthetic_root_dir = args.output_dir MotionSynthetic_video_dir = os.path.join(MotionSynthetic_root_dir, "videos") MotionSynthetic_poses_dir = os.path.join(MotionSynthetic_root_dir, "poses") MotionSynthetic_train_txt = os.path.join(MotionSynthetic_root_dir, "train.txt") MotionSynthetic_val_txt = os.path.join(MotionSynthetic_root_dir, "val.txt") MotionSynthetic_video_zip = os.path.join(MotionSynthetic_root_dir, "videos.zip") MotionSynthetic_poses_zip = os.path.join(MotionSynthetic_root_dir, "poses.zip") MotionSynthetic_processed_dir = mkdir( os.path.join(MotionSynthetic_root_dir, "primitives")) # MotionSynthetic URLs MotionSynthetic_url = "http://download.impersonator.org:20086/datasets/motionSynthetic" MotionSynthetic_poses_url = os.path.join(MotionSynthetic_url, "poses.zip") MotionSynthetic_videos_url = os.path.join(MotionSynthetic_url, "videos.zip") MotionSynthetic_train_txt_url = os.path.join(MotionSynthetic_url, "train.txt") MotionSynthetic_val_txt_url = os.path.join(MotionSynthetic_url, "val.txt") def get_video_dirs(txt_file): vid_names = [] with open(txt_file, "r") as reader: for line in reader: line = line.rstrip() vid_names.append(line)
def __init__(self, meta_process): """ Args: meta_process (MetaProcess): """ processed_dir = meta_process.processed_dir self.vid_infos = { "input_info": meta_process.get_info(), "src_img_dir": os.path.join(processed_dir, "orig_images"), "src_num_imgs": 0, "out_img_dir": mkdir(os.path.join(processed_dir, "images")), "out_bg_dir": mkdir(os.path.join(processed_dir, "background")), "out_actual_bg_dir": mkdir(os.path.join(processed_dir, "actual_background")), "out_parse_dir": mkdir(os.path.join(processed_dir, "parse")), "out_visual_path": os.path.join(processed_dir, "visual.mp4"), "has_run_detector": False, "has_run_cropper": False, "has_run_3dpose": False, "has_find_front": False, "has_run_parser": False, "has_run_inpaintor": False, "has_run_deform": False, "has_finished": False, "orig_shape": (), "valid_img_info": { "names": [], "ids": [], "stage": "" }, "processed_pose2d": { "boxes_XYXY": [], "keypoints": [] }, "processed_cropper": { "crop_shape": (), "active_boxes_XYXY": [], "crop_boxes_XYXY": [], "crop_keypoints": [] }, "processed_pose3d": { "cams": [], "pose": [], "shape": [], "init_pose": [], "init_shape": [] }, "processed_front_info": { "ft": { "body_num": [], "face_num": [], "ids": [] }, "bk": { "body_num": [], "face_num": [], "ids": [] } }, "processed_parse": { "mask_suffix": "mask.png", "alpha_suffix": "alpha.png" }, "processed_background": { "inpainted_suffix": "_inpainted.png", "replaced_suffix": "_replaced.png", "replace": False, }, "processed_deform": { "links": None, "offsets": None } }
type=str, default="FashionVideo_Preprocess", help="the renamed model.") parser.add_argument("--Preprocess.Cropper.src_crop_factor", type=float, default=0, help="directly resize on iPER.") parser.add_argument("--ref_path", type=str, default="", help="set this empty when preprocessing training dataset.") args = parser.parse_args() args.cfg_path = os.path.join("./assets", "configs", "deploy.toml") FashionVideo_root_dir = mkdir(args.output_dir) FashionVideo_video_dir = mkdir(os.path.join(FashionVideo_root_dir, "videos")) FashionVideo_train_url_txt = os.path.join(FashionVideo_root_dir, "fashion_train.txt") FashionVideo_test_url_txt = os.path.join(FashionVideo_root_dir, "fashion_test.txt") TRAIN_list_txt = os.path.join(FashionVideo_root_dir, "train.txt") TEST_list_txt = os.path.join(FashionVideo_root_dir, "val.txt") TRAIN_URL = "https://vision.cs.ubc.ca/datasets/fashion/resources/fashion_dataset/fashion_train.txt" TEST_URL = "https://vision.cs.ubc.ca/datasets/fashion/resources/fashion_dataset/fashion_test.txt" def raise_error(msg): instruction_url = "https://vision.cs.ubc.ca/datasets/fashion/resources/fashion_dataset" print(
type=str, default="iPER_Preprocess", help="the renamed model.") parser.add_argument("--Preprocess.Cropper.src_crop_factor", type=float, default=0, help="directly resize on iPER.") parser.add_argument("--ref_path", type=str, default="", help="set this empty when preprocessing training dataset.") args = parser.parse_args() args.cfg_path = os.path.join("./assets", "configs", "deploy.toml") iPER_root_dir = mkdir(args.output_dir) iPER_images_dir = mkdir(os.path.join(iPER_root_dir, "images_HD")) iPER_images_splits_dir = mkdir(os.path.join(iPER_root_dir, "splits")) iPER_images_merged_tar_gz = os.path.join(iPER_root_dir, "images_HD.tar.gz") iPER_smpls_dir = os.path.join(iPER_root_dir, "smpls") iPER_train_txt = os.path.join(iPER_root_dir, "train.txt") iPER_val_txt = os.path.join(iPER_root_dir, "val.txt") iPER_images_HD_split_txt = os.path.join(iPER_root_dir, "images_HD_splits.txt") DOWNLOAD_URL = "http://download.impersonator.org:20086/" iPER_url = "http://download.impersonator.org:20086/datasets/iPER" iPER_images_HD_url = os.path.join(iPER_url, "images_HD") iPER_images_HD_split_txt_url = os.path.join(iPER_url, "images_HD_splits.txt") iPER_train_txt_url = os.path.join(iPER_url, "train.txt") iPER_val_txt_url = os.path.join(iPER_url, "val.txt")