|
@@ -245,49 +245,49 @@ def videoSwap(opt):
|
|
|
task.status = 'processing'
|
|
|
task.start_time = datetime.now()
|
|
|
update(task)
|
|
|
- # try:
|
|
|
- start_epoch, epoch_iter = 1, 0
|
|
|
- crop_size = 224
|
|
|
- # opt_dict = vars(opt)
|
|
|
- # args = get_args_from_json(item,opt_dict)
|
|
|
- torch.nn.Module.dump_patches = True
|
|
|
- model = create_model(opt)
|
|
|
- model.eval()
|
|
|
- app = Face_detect_crop(name='antelope', root='./insightface_func/models')
|
|
|
- app.prepare(ctx_id= 0, det_thresh=0.6, det_size=(640,640))
|
|
|
-
|
|
|
- with torch.no_grad():
|
|
|
- pic_a = opt.pic_a_path
|
|
|
- # img_a = Image.open(pic_a).convert('RGB')
|
|
|
- img_a_whole = cv2.imread(pic_a)
|
|
|
- img_a_align_crop, _ = app.get(img_a_whole,crop_size)
|
|
|
- img_a_align_crop_pil = Image.fromarray(cv2.cvtColor(img_a_align_crop[0],cv2.COLOR_BGR2RGB))
|
|
|
- img_a = transformer_Arcface(img_a_align_crop_pil)
|
|
|
- img_id = img_a.view(-1, img_a.shape[0], img_a.shape[1], img_a.shape[2])
|
|
|
+ try:
|
|
|
+ start_epoch, epoch_iter = 1, 0
|
|
|
+ crop_size = 224
|
|
|
+ # opt_dict = vars(opt)
|
|
|
+ # args = get_args_from_json(item,opt_dict)
|
|
|
+ torch.nn.Module.dump_patches = True
|
|
|
+ model = create_model(opt)
|
|
|
+ model.eval()
|
|
|
+ app = Face_detect_crop(name='antelope', root='./insightface_func/models')
|
|
|
+ app.prepare(ctx_id= 0, det_thresh=0.6, det_size=(640,640))
|
|
|
+
|
|
|
+ with torch.no_grad():
|
|
|
+ pic_a = opt.pic_a_path
|
|
|
+ # img_a = Image.open(pic_a).convert('RGB')
|
|
|
+ img_a_whole = cv2.imread(pic_a)
|
|
|
+ img_a_align_crop, _ = app.get(img_a_whole,crop_size)
|
|
|
+ img_a_align_crop_pil = Image.fromarray(cv2.cvtColor(img_a_align_crop[0],cv2.COLOR_BGR2RGB))
|
|
|
+ img_a = transformer_Arcface(img_a_align_crop_pil)
|
|
|
+ img_id = img_a.view(-1, img_a.shape[0], img_a.shape[1], img_a.shape[2])
|
|
|
|
|
|
- # pic_b = opt.pic_b_path
|
|
|
- # img_b_whole = cv2.imread(pic_b)
|
|
|
- # img_b_align_crop, b_mat = app.get(img_b_whole,crop_size)
|
|
|
- # img_b_align_crop_pil = Image.fromarray(cv2.cvtColor(img_b_align_crop,cv2.COLOR_BGR2RGB))
|
|
|
- # img_b = transformer(img_b_align_crop_pil)
|
|
|
- # img_att = img_b.view(-1, img_b.shape[0], img_b.shape[1], img_b.shape[2])
|
|
|
+ # pic_b = opt.pic_b_path
|
|
|
+ # img_b_whole = cv2.imread(pic_b)
|
|
|
+ # img_b_align_crop, b_mat = app.get(img_b_whole,crop_size)
|
|
|
+ # img_b_align_crop_pil = Image.fromarray(cv2.cvtColor(img_b_align_crop,cv2.COLOR_BGR2RGB))
|
|
|
+ # img_b = transformer(img_b_align_crop_pil)
|
|
|
+ # img_att = img_b.view(-1, img_b.shape[0], img_b.shape[1], img_b.shape[2])
|
|
|
|
|
|
- # convert numpy to tensor
|
|
|
- img_id = img_id.cuda()
|
|
|
- # img_att = img_att.cuda()
|
|
|
+ # convert numpy to tensor
|
|
|
+ img_id = img_id.cuda()
|
|
|
+ # img_att = img_att.cuda()
|
|
|
|
|
|
- #create latent id
|
|
|
- img_id_downsample = F.interpolate(img_id, scale_factor=0.5)
|
|
|
- latend_id = model.netArc(img_id_downsample)
|
|
|
- latend_id = F.normalize(latend_id, p=2, dim=1)
|
|
|
+ #create latent id
|
|
|
+ img_id_downsample = F.interpolate(img_id, scale_factor=0.5)
|
|
|
+ latend_id = model.netArc(img_id_downsample)
|
|
|
+ latend_id = F.normalize(latend_id, p=2, dim=1)
|
|
|
|
|
|
- video_swap(opt.video_path, latend_id, model, app, opt.output_path,temp_results_dir=opt.temp_path,\
|
|
|
- no_simswaplogo=opt.no_simswaplogo,use_mask=opt.use_mask)
|
|
|
- # except:
|
|
|
- # task = query(opt.taskId,None,None,None)[0]
|
|
|
- # task.status = 'process_error'
|
|
|
- # update(task)
|
|
|
- # del_file(opt.base_path)
|
|
|
+ video_swap(opt.video_path, latend_id, model, app, opt.output_path,temp_results_dir=opt.temp_path,\
|
|
|
+ no_simswaplogo=opt.no_simswaplogo,use_mask=opt.use_mask)
|
|
|
+ except:
|
|
|
+ task = query(opt.taskId,None,None,None)[0]
|
|
|
+ task.status = 'process_error'
|
|
|
+ update(task)
|
|
|
+ del_file(opt.base_path)
|
|
|
output_video_md5 = getmd5(opt.output_path)
|
|
|
task = query(opt.taskId,None,None,None)[0]
|
|
|
task.status = 'uploading'
|