def __getitem__(self, index): self.A, self.B, self.I, seq_idx = self.update_frame_idx(self.A_paths, index) tG = self.opt.n_frames_G A_img = Image.open(self.A_paths[seq_idx][0]).convert('RGB') params = get_img_params(self.opt, A_img.size) transform_scaleB = get_transform(self.opt, params) transform_scaleA = get_transform(self.opt, params, method=Image.NEAREST, normalize=False) if self.A_is_label else transform_scaleB frame_range = list(range(tG)) if self.A is None else [tG-1] for i in frame_range: A_path = self.A_paths[seq_idx][self.frame_idx + i] Ai = self.get_image(A_path, transform_scaleA, is_label=self.A_is_label) self.A = concat_frame(self.A, Ai, tG) if self.use_real: B_path = self.B_paths[seq_idx][self.frame_idx + i] Bi = self.get_image(B_path, transform_scaleB) self.B = concat_frame(self.B, Bi, tG) else: self.B = 0 if self.opt.use_instance: I_path = self.I_paths[seq_idx][self.frame_idx + i] Ii = self.get_image(I_path, transform_scaleA) * 255.0 self.I = concat_frame(self.I, Ii, tG) else: self.I = 0 self.frame_idx += 1 return_list = {'A': self.A, 'B': self.B, 'inst': self.I, 'A_path': A_path, 'change_seq': self.change_seq} return return_list
def __getitem__(self, index): TParsing, SPose, SParsing, SFG, seq_idx = self.update_frame_idx_parser( self.sparsing_paths, index) sparsing_paths = self.sparsing_paths[seq_idx] sfg_paths = self.sfg_paths[seq_idx] n_frames_total, start_idx, t_step = get_video_params( self.opt, self.n_frames_total, len(sparsing_paths), self.frame_idx) sparsing = Image.open(sparsing_paths[start_idx]) sfg = Image.open(sfg_paths[start_idx]).convert('RGB') size = sfg.size BigSizeFlag = True if size[0] / size[1] > 1: BigSizeFlag = True else: BigSizeFlag = False if BigSizeFlag: params = get_img_params(self.opt, (1920, 1080)) else: params = get_img_params(self.opt, size) tparsing_path = self.tparsing_paths[seq_idx][0] TParsing = self.get_TImage(tparsing_path, size, params, BigSizeFlag) TParsing = self.crop(TParsing) frame_range = list(range(n_frames_total)) if ( self.opt.isTrain or self.TPose is None) else [self.opt.n_frames_G - 1] for i in frame_range: sparsing_path = sparsing_paths[start_idx + i * t_step] spose_path = self.spose_paths[seq_idx][start_idx + i * t_step] sfg_path = sfg_paths[start_idx + i * t_step] SPose_i, SParsing_i, SFG_i = self.get_SImage( spose_path, sparsing_path, sfg_path, size, params, BigSizeFlag) SParsing_i = self.crop(SParsing_i) SPose_i = self.crop(SPose_i) SFG_i = self.crop(SFG_i) SPose = concat_frame(SPose, SPose_i, n_frames_total) SParsing = concat_frame(SParsing, SParsing_i, n_frames_total) SFG = concat_frame(SFG, SFG_i, n_frames_total) if not self.opt.isTrain: self.TParsing, self.SPose, self.SParsing, self.SFG = TParsing, SPose, SParsing, SFG self.frame_idx += 1 change_seq = False if self.opt.isTrain else self.change_seq return_list = { 'TParsing': TParsing, 'SPose': SPose, 'SParsing': SParsing, 'SFG': SFG, 'A_path': sparsing_path, 'change_seq': change_seq } return return_list
def __getitem__(self, index): A, B, _, seq_idx = self.update_frame_idx(self.img_paths, index) img_paths = self.img_paths[seq_idx] n_frames_total, start_idx, t_step = get_video_params( self.opt, self.n_frames_total, len(img_paths), self.frame_idx) img = Image.open(img_paths[start_idx]).convert('RGB') size = img.size params = get_img_params(self.opt, size) frame_range = list(range(n_frames_total)) if ( self.opt.isTrain or self.A is None) else [self.opt.n_frames_G - 1] for i in frame_range: img_path = img_paths[start_idx + i * t_step] if not self.opt.openpose_only: dp_path = self.dp_paths[seq_idx][start_idx + i * t_step] Di = self.get_image(dp_path, size, params, input_type='densepose') Di[2, :, :] = ( (Di[2, :, :] * 0.5 + 0.5) * 255 / 24 - 0.5) / 0.5 if not self.opt.densepose_only: op_path = self.op_paths[seq_idx][start_idx + i * t_step] Oi = self.get_image(op_path, size, params, input_type='openpose') if self.opt.openpose_only: Ai = Oi elif self.opt.densepose_only: Ai = Di else: Ai = torch.cat([Di, Oi]) Bi = self.get_image(img_path, size, params, input_type='img') Ai, Bi = self.crop(Ai), self.crop( Bi) # only crop the central half region to save time A = concat_frame(A, Ai, n_frames_total) B = concat_frame(B, Bi, n_frames_total) if not self.opt.isTrain: self.A, self.B = A, B self.frame_idx += 1 change_seq = False if self.opt.isTrain else self.change_seq return_list = { 'A': A, 'B': B, 'inst': 0, 'A_path': img_path, 'change_seq': change_seq } return return_list
def __getitem__(self, index): A, B, I, seq_idx = self.update_frame_idx(self.A_paths, index) A_paths = self.A_paths[seq_idx] B_paths = self.B_paths[seq_idx] n_frames_total, start_idx, t_step = get_video_params( self.opt, self.n_frames_total, len(A_paths), self.frame_idx) B_img = Image.open(B_paths[0]).convert('RGB') B_size = B_img.size points = np.loadtxt(A_paths[0], delimiter=',') is_first_frame = self.opt.isTrain or not hasattr(self, 'min_x') if is_first_frame: # crop only the face region self.get_crop_coords(points, B_size) params = get_img_params(self.opt, self.crop(B_img).size) transform_scaleA = get_transform(self.opt, params, method=Image.BILINEAR, normalize=False) transform_label = get_transform(self.opt, params, method=Image.NEAREST, normalize=False) transform_scaleB = get_transform(self.opt, params) # read in images frame_range = list(range(n_frames_total)) if self.A is None else [ self.opt.n_frames_G - 1 ] for i in frame_range: A_path = A_paths[start_idx + i * t_step] B_path = B_paths[start_idx + i * t_step] B_img = Image.open(B_path) Ai, Li = self.get_face_image(A_path, transform_scaleA, transform_label, B_size, B_img) Bi = transform_scaleB(self.crop(B_img)) A = concat_frame(A, Ai, n_frames_total) B = concat_frame(B, Bi, n_frames_total) I = concat_frame(I, Li, n_frames_total) if not self.opt.isTrain: self.A, self.B, self.I = A, B, I self.frame_idx += 1 change_seq = False if self.opt.isTrain else self.change_seq return_list = { 'A': A, 'B': B, 'inst': I, 'A_path': A_path, 'change_seq': change_seq } return return_list
def __getitem__(self, index): TParsing, TFG, SPose, SParsing, SFG, SFG_full, BG, BG_flag, SI, seq_idx = self.update_frame_idx_composer( self.simg_paths, index) simg_paths = self.simg_paths[seq_idx] n_frames_total, start_idx, t_step = get_video_params( self.opt, self.n_frames_total, len(simg_paths), self.frame_idx) simg = Image.open(simg_paths[start_idx]).convert('RGB') size = simg.size BigSizeFlag = True if size[0] / size[1] > 1: BigSizeFlag = True else: BigSizeFlag = False if BigSizeFlag: params = get_img_params(self.opt, (1920, 1080)) else: params = get_img_params(self.opt, size) tparsing_path = self.tparsing_paths[seq_idx][0] timg_path = self.timg_paths[seq_idx][0] video_name = timg_path[timg_path.rfind('video'):timg_path.rfind('/timg' )] bg_path = self.dir_bg + '/' + video_name + '.jpg' BG_i, BG_flag = self.get_bg_image(bg_path, size, params, BigSizeFlag) TParsing, TFG = self.get_TImage(tparsing_path, timg_path, size, params, BigSizeFlag) TParsing, TFG = self.crop(TParsing), self.crop(TFG) frame_range = list(range(n_frames_total)) if ( self.opt.isTrain or self.TPose is None) else [self.opt.n_frames_G - 1] for i in frame_range: simg_path = simg_paths[start_idx + i * t_step] sfg_path = self.sfg_paths[seq_idx][start_idx + i * t_step] spose_path = self.spose_paths[seq_idx][start_idx + i * t_step] sparsing_path = self.sparsing_paths[seq_idx][start_idx + i * t_step] SPose_i, SParsing_i, SFG_i, SFG_full_i, SI_i = self.get_SImage( spose_path, sparsing_path, sfg_path, simg_path, size, params, BigSizeFlag) SParsing_i = self.crop(SParsing_i) SFG_i = self.crop(SFG_i) SPose_i, SFG_full_i, SI_i = self.crop(SPose_i), self.crop( SFG_full_i), self.crop(SI_i) SPose = concat_frame(SPose, SPose_i, n_frames_total) SParsing = concat_frame(SParsing, SParsing_i, n_frames_total) SFG = concat_frame(SFG, SFG_i, n_frames_total) SFG_full = concat_frame(SFG_full, SFG_full_i, n_frames_total) SI = concat_frame(SI, SI_i, n_frames_total) BG = concat_frame(BG, BG_i, n_frames_total) if not self.opt.isTrain: self.TParsing, self.TFG, self.SPose, self.SParsing, self.SFG, self.SFG_full, self.BG, self.BG_flag, self.SI = TParsing, TFG, SPose, SParsing, SFG, SFG_full, BG, BG_flag, SI self.frame_idx += 1 change_seq = False if self.opt.isTrain else self.change_seq return_list = { 'TParsing': TParsing, 'TFG': TFG, 'SPose': SPose, 'SParsing': SParsing, 'SFG': SFG, 'SFG_full': SFG_full, 'BG': BG, 'BG_flag': BG_flag, 'SI': SI, 'A_path': simg_path, 'change_seq': change_seq } return return_list