科技匠|怎样用 Python 控制图片人物动起来?一文就能 Get( 三 )
parser.add_argument("--find_best_frame", dest="find_best_frame", action="store_true",
help="Generate from the frame that is the most alligned with source. (Only for faces, requires face_aligment lib)")
parser.add_argument("--best_frame", dest="best_frame", type=int, default=None,
help="Set frame to start from.")
parser.add_argument("--cpu", dest="cpu", action="store_true", help="cpu mode.")
parser.set_defaults(relative=False)
parser.set_defaults(adapt_scale=False)
opt = parser.parse_args
source_image = imageio.imread(opt.source_image)
reader = imageio.get_reader(opt.driving_video)
fps = reader.get_meta_data['fps']
driving_video =
try:
for im in reader:
driving_video.append(im)
except RuntimeError:
pass
reader.close
source_image = resize(source_image, (256, 256))[..., :3]
driving_video = [resize(frame, (256, 256))[..., :3] for frame in driving_video]
generator, kp_detector = load_checkpoints(config_path=opt.config, checkpoint_path=opt.checkpoint, cpu=opt.cpu)
if opt.find_best_frame or opt.best_frame is not None:
i = opt.best_frame if opt.best_frame is not None else find_best_frame(source_image, driving_video, cpu=opt.cpu)
print ("Best frame: " + str(i))
driving_forward = driving_video[i:]
driving_backward = driving_video[:(i+1)][::-1]
predictions_forward = make_animation(source_image, driving_forward, generator, kp_detector, relative=opt.relative, adapt_movement_scale=opt.adapt_scale, cpu=opt.cpu)
predictions_backward = make_animation(source_image, driving_backward, generator, kp_detector, relative=opt.relative, adapt_movement_scale=opt.adapt_scale, cpu=opt.cpu)
predictions = predictions_backward[::-1] + predictions_forward[1:]
else:
predictions = make_animation(source_image, driving_video, generator, kp_detector, relative=opt.relative, adapt_movement_scale=opt.adapt_scale, cpu=opt.cpu)
imageio.mimsave(opt.result_video, [img_as_ubyte(frame) for frame in predictions], fps=fps)
模型的搭建整个模型训练过程是图像重建的过程 , 输入是源图像和驱动图像 , 输出是保留源图像物体信息的含有驱动图像姿态的新图像 , 其中输入的两张图像来源于同一个视频 , 即同一个物体信息 , 那么整个训练过程就是驱动图像的重建过程 。 大体上来说分成两个模块 , 一个是motion estimation module , 另一个是imagegeneration module 。
(1)其中通过定义VGG19模型建立网络层作为perceptual损失 。
其中手动输入数据进行预测需要设置更多的GUI按钮 , 其中代码如下:
class Vgg19(torch.nn.Module):
"""
Vgg19 network for perceptual loss. See Sec 3.3.
"""
def __init__(self, requires_grad=False):
super(Vgg19, self).__init__
vgg_pretrained_features = models.vgg19(pretrained=True).features
推荐阅读
- 下个10年,Go能取代Python成为开发者的首选语言吗?
- 怎样不秃顶|期中温习: 二年级上册数学加法、减法和乘法应用题, 附谜底
- 科技日报|塑料微粒影响几何?人类认知仍不足
- 七号人称说科技|华为始料未及?台积电又成了“炮灰”?新风暴说来就来
- 大众新闻|众安科技荣获“今日·保险中介榜”年度Insurtech独角兽
- 雷科技|朋友圈都在秀的“互联网勋章”到底是什么?
- 快科技|小米10至尊纪念版妙享功能升级:手机与Windows电脑合体
- 七号人称说科技|再给华为一颗糖?美国到底在打什么“算盘”?,先给华为一巴掌
- 量子科技,爆发!有项关键技术中国已领先世界
- 暖日科技盈如|这到底是为什么?,俄罗斯华人给出劝告:最好别跟俄罗斯女孩结婚
