导读:本论文来自NeurIPS2019,该算法中主要采用一阶运动模型的思想,用一组自学习的关键点和局部仿射变换,建立了复杂运动模型。模型由运动估计模块和图像生成模块两个主要部分组成。首先进行关键点检测,然后根据关键点,进行运动估计,最后使用图像生成模块,生成最终效果。
额,哈哈,不好意思了,又拿我的偶像胡歌下手啦,视频截取来源偶像胡歌在《猎场》中的一角色。
目录
利用人工智能算法让经典图片根据自定义动作嗨起来(将一张静态人像图片转为带表情动作视频)
利用人工智能算法让古代皇帝画像动起来(模仿偶像胡歌《猎场》剧中角色表情动作)
作品视频链接
利用人工智能算法,让古代皇帝画像动起来(模仿偶像胡歌《猎场》剧中角色表情动作)
利用人工智能算法让古代美女《西施、王昭君、貂蝉、杨玉环四大美女领衔》画像动起来
利用人工智能算法让经典图片根据自定义动作嗨起来(将一张静态人像图片转为带表情动作视频)
相关论文
Paper:《First Order Motion Model for Image Animation》翻译与解读
输出结果
利用人工智能算法让古代皇帝画像动起来(模仿偶像胡歌《猎场》剧中角色表情动作)
利用人工智能算法让古代四大美女画像动起来
实现代码
1. import imageio 2. import torch 3. from tqdm import tqdm 4. from animate import normalize_kp 5. from demo import load_checkpoints 6. import numpy as np 7. import matplotlib.pyplot as plt 8. import matplotlib.animation as animation 9. from skimage import img_as_ubyte 10. from skimage.transform import resize 11. import cv2 12. import os 13. import argparse 14. 15. ap = argparse.ArgumentParser() 16. ap.add_argument("-i", "--input_image", required=True,help="Path to image to animate") 17. ap.add_argument("-c", "--checkpoint", required=True,help="Path to checkpoint") 18. ap.add_argument("-v","--input_video", required=False, help="Path to video input") 19. 20. args = vars(ap.parse_args()) 21. 22. print("[INFO] loading source image and checkpoint...") 23. source_path = args['input_image'] 24. checkpoint_path = args['checkpoint'] 25. if args['input_video']: 26. video_path = args['input_video'] 27. else: 28. video_path = None 29. source_image = imageio.imread(source_path) 30. source_image = resize(source_image,(256,256))[..., :3] 31. 32. generator, kp_detector = load_checkpoints(config_path='config/vox-256.yaml', checkpoint_path=checkpoint_path) 33. 34. if not os.path.exists('output'): 35. os.mkdir('output') 36. 37. 38. relative=True 39. adapt_movement_scale=True 40. cpu=False 41. 42. if video_path: 43. cap = cv2.VideoCapture(video_path) 44. print("[INFO] Loading video from the given path") 45. else: 46. cap = cv2.VideoCapture(0) 47. print("[INFO] Initializing front camera...") 48. 49. fourcc = cv2.VideoWriter_fourcc(*'MJPG') 50. out1 = cv2.VideoWriter('output/Animation_HuGe_02.avi', fourcc, 12, (256*3 , 256), True) 51. 52. cv2_source = cv2.cvtColor(source_image.astype('float32'),cv2.COLOR_BGR2RGB) 53. with torch.no_grad() : 54. predictions = [] 55. source = torch.tensor(source_image[np.newaxis].astype(np.float32)).permute(0, 3, 1, 2) 56. if not cpu: 57. source = source.cuda() 58. kp_source = kp_detector(source) 59. count = 0 60. while(True): 61. ret, frame = cap.read() 62. frame = cv2.flip(frame,1) 63. if ret == True: 64. 65. if not video_path: 66. x = 143 67. y = 87 68. w = 322 69. h = 322 70. frame = frame[y:y+h,x:x+w] 71. frame1 = resize(frame,(256,256))[..., :3] 72. 73. if count == 0: 74. source_image1 = frame1 75. source1 = torch.tensor(source_image1[np.newaxis].astype(np.float32)).permute(0, 3, 1, 2) 76. kp_driving_initial = kp_detector(source1) 77. 78. frame_test = torch.tensor(frame1[np.newaxis].astype(np.float32)).permute(0, 3, 1, 2) 79. 80. driving_frame = frame_test 81. if not cpu: 82. driving_frame = driving_frame.cuda() 83. kp_driving = kp_detector(driving_frame) 84. kp_norm = normalize_kp(kp_source=kp_source, 85. kp_driving=kp_driving, 86. kp_driving_initial=kp_driving_initial, 87. use_relative_movement=relative, 88. use_relative_jacobian=relative, 89. adapt_movement_scale=adapt_movement_scale) 90. out = generator(source, kp_source=kp_source, kp_driving=kp_norm) 91. predictions.append(np.transpose(out['prediction'].data.cpu().numpy(), [0, 2, 3, 1])[0]) 92. im = np.transpose(out['prediction'].data.cpu().numpy(), [0, 2, 3, 1])[0] 93. im = cv2.cvtColor(im,cv2.COLOR_RGB2BGR) 94. joinedFrame = np.concatenate((cv2_source,im,frame1),axis=1) 95. 96. cv2.imshow('Test',joinedFrame) 97. out1.write(img_as_ubyte(joinedFrame)) 98. count += 1 99. if cv2.waitKey(20) & 0xFF == ord('q'): 100. break 101. else: 102. break 103. 104. cap.release() 105. out1.release() 106. cv2.destroyAllWindows()
依赖环境
1. C:\Users\Administrator>conda activate F:\File_Anaconda\project_py37\envs 2. 3. (F:\File_Anaconda\project_py37\envs) C:\Users\Administrator>conda list 4. # packages in environment at F:\File_Anaconda\project_py37\envs: 5. # 6. # Name Version Build Channel 7. attrs 19.3.0 pypi_0 pypi 8. backcall 0.1.0 pypi_0 pypi 9. blas 1.0 mkl https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 10. bleach 3.1.5 pypi_0 pypi 11. ca-certificates 2021.10.26 haa95532_2 http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 12. certifi 2021.10.8 py37haa95532_0 http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 13. cffi 1.11.5 pypi_0 pypi 14. cloudpickle 0.5.3 pypi_0 pypi 15. colorama 0.4.3 pypi_0 pypi 16. cpuonly 2.0 0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch 17. cudatoolkit 8.0 4 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 18. cycler 0.10.0 pypi_0 pypi 19. dask 0.18.2 pypi_0 pypi 20. decorator 4.3.0 pypi_0 pypi 21. defusedxml 0.6.0 pypi_0 pypi 22. entrypoints 0.3 pypi_0 pypi 23. freetype 2.10.4 hd328e21_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 24. imageio 2.3.0 pypi_0 pypi 25. importlib-metadata 1.6.0 pypi_0 pypi 26. intel-openmp 2021.4.0 haa95532_3556 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 27. ipykernel 5.2.1 pypi_0 pypi 28. ipython 7.14.0 pypi_0 pypi 29. ipython-genutils 0.2.0 pypi_0 pypi 30. jedi 0.17.0 pypi_0 pypi 31. jinja2 2.11.2 pypi_0 pypi 32. jpeg 9d h2bbff1b_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 33. jsonschema 3.2.0 pypi_0 pypi 34. jupyter-client 6.1.3 pypi_0 pypi 35. jupyter-core 4.6.3 pypi_0 pypi 36. kiwisolver 1.0.1 pypi_0 pypi 37. libpng 1.6.37 h2a8f88b_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 38. libtiff 4.2.0 hd0e1b90_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 39. libuv 1.40.0 he774522_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 40. libwebp 1.2.0 h2bbff1b_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 41. lz4-c 1.9.3 h2bbff1b_1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 42. markupsafe 1.1.1 pypi_0 pypi 43. matplotlib 2.2.2 pypi_0 pypi 44. mistune 0.8.4 pypi_0 pypi 45. mkl 2021.4.0 haa95532_640 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 46. mkl-service 2.4.0 py37h2bbff1b_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 47. mkl_fft 1.3.1 py37h277e83a_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 48. mkl_random 1.2.2 py37hf11a4ad_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 49. nbconvert 5.6.1 pypi_0 pypi 50. nbformat 5.0.6 pypi_0 pypi 51. networkx 2.1 pypi_0 pypi 52. ninja 1.10.2 py37h559b2a2_3 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 53. notebook 6.0.3 pypi_0 pypi 54. numpy 1.15.0 pypi_0 pypi 55. olefile 0.46 py37_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 56. opencv-python 4.2.0.34 pypi_0 pypi 57. openssl 1.1.1l h2bbff1b_0 http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 58. packaging 20.4 pypi_0 pypi 59. pandas 0.23.4 pypi_0 pypi 60. pandocfilters 1.4.2 pypi_0 pypi 61. parso 0.7.0 pypi_0 pypi 62. pickleshare 0.7.5 pypi_0 pypi 63. pillow 5.2.0 pypi_0 pypi 64. pip 21.2.4 py37haa95532_0 http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 65. prometheus-client 0.7.1 pypi_0 pypi 66. prompt-toolkit 3.0.5 pypi_0 pypi 67. pycparser 2.18 pypi_0 pypi 68. pygit 0.1 pypi_0 pypi 69. pygments 2.6.1 pypi_0 pypi 70. pyparsing 2.2.0 pypi_0 pypi 71. pyrsistent 0.16.0 pypi_0 pypi 72. python 3.7.11 h6244533_0 http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 73. python-dateutil 2.7.3 pypi_0 pypi 74. pytorch 1.0.1 py3.7_cuda80_cudnn7_1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch 75. pytorch-mutex 1.0 cpu https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch 76. pytz 2018.5 pypi_0 pypi 77. pywavelets 0.5.2 pypi_0 pypi 78. pywin32 227 pypi_0 pypi 79. pywinpty 0.5.7 pypi_0 pypi 80. pyyaml 5.1 pypi_0 pypi 81. pyzmq 19.0.1 pypi_0 pypi 82. scikit-image 0.14.0 pypi_0 pypi 83. scikit-learn 0.19.2 pypi_0 pypi 84. scipy 1.1.0 pypi_0 pypi 85. send2trash 1.5.0 pypi_0 pypi 86. setuptools 58.0.4 py37haa95532_0 http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 87. six 1.11.0 pypi_0 pypi 88. sqlite 3.36.0 h2bbff1b_0 http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 89. terminado 0.8.3 pypi_0 pypi 90. testpath 0.4.4 pypi_0 pypi 91. tk 8.6.11 h2bbff1b_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 92. toolz 0.9.0 pypi_0 pypi 93. torchvision 0.2.2 py_3 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch 94. tornado 6.0.4 pypi_0 pypi 95. tqdm 4.24.0 pypi_0 pypi 96. traitlets 4.3.3 pypi_0 pypi 97. typing_extensions 3.10.0.2 pyh06a4308_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 98. vc 14.2 h21ff451_1 http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 99. vs2015_runtime 14.27.29016 h5e58377_2 http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 100. wcwidth 0.1.9 pypi_0 pypi 101. webencodings 0.5.1 pypi_0 pypi 102. wheel 0.37.0 pyhd3eb1b0_1 http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 103. wincertstore 0.2 py37haa95532_2 http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 104. xz 5.2.5 h62dcd97_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 105. zipp 3.1.0 pypi_0 pypi 106. zlib 1.2.11 h62dcd97_4 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main 107. zstd 1.4.9 h19a0ad4_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
导出当前依赖环境txt文档
1. F:\File_Anaconda\project_py37\RealTimeImageAnimation>conda activate F:\File_Anaconda\project_py37\envs 2. 3. (F:\File_Anaconda\project_py37\envs) F:\File_Anaconda\project_py37\RealTimeImageAnimation>conda list -e > requirements2020.txt 4. 5. 6. # This file may be used to create an environment using: 7. # $ conda create --name <env> --file <this file> 8. # platform: win-64 9. attrs=19.3.0=pypi_0 10. backcall=0.1.0=pypi_0 11. blas=1.0=mkl 12. bleach=3.1.5=pypi_0 13. ca-certificates=2021.10.26=haa95532_2 14. certifi=2021.10.8=py37haa95532_0 15. cffi=1.11.5=pypi_0 16. cloudpickle=0.5.3=pypi_0 17. colorama=0.4.3=pypi_0 18. cpuonly=2.0=0 19. cudatoolkit=8.0=4 20. cycler=0.10.0=pypi_0 21. dask=0.18.2=pypi_0 22. decorator=4.3.0=pypi_0 23. defusedxml=0.6.0=pypi_0 24. entrypoints=0.3=pypi_0 25. freetype=2.10.4=hd328e21_0 26. imageio=2.3.0=pypi_0 27. importlib-metadata=1.6.0=pypi_0 28. intel-openmp=2021.4.0=haa95532_3556 29. ipykernel=5.2.1=pypi_0 30. ipython=7.14.0=pypi_0 31. ipython-genutils=0.2.0=pypi_0 32. jedi=0.17.0=pypi_0 33. jinja2=2.11.2=pypi_0 34. jpeg=9d=h2bbff1b_0 35. jsonschema=3.2.0=pypi_0 36. jupyter-client=6.1.3=pypi_0 37. jupyter-core=4.6.3=pypi_0 38. kiwisolver=1.0.1=pypi_0 39. libpng=1.6.37=h2a8f88b_0 40. libtiff=4.2.0=hd0e1b90_0 41. libuv=1.40.0=he774522_0 42. libwebp=1.2.0=h2bbff1b_0 43. lz4-c=1.9.3=h2bbff1b_1 44. markupsafe=1.1.1=pypi_0 45. matplotlib=2.2.2=pypi_0 46. mistune=0.8.4=pypi_0 47. mkl=2021.4.0=haa95532_640 48. mkl-service=2.4.0=py37h2bbff1b_0 49. mkl_fft=1.3.1=py37h277e83a_0 50. mkl_random=1.2.2=py37hf11a4ad_0 51. nbconvert=5.6.1=pypi_0 52. nbformat=5.0.6=pypi_0 53. networkx=2.1=pypi_0 54. ninja=1.10.2=py37h559b2a2_3 55. notebook=6.0.3=pypi_0 56. numpy=1.15.0=pypi_0 57. olefile=0.46=py37_0 58. opencv-python=4.2.0.34=pypi_0 59. openssl=1.1.1l=h2bbff1b_0 60. packaging=20.4=pypi_0 61. pandas=0.23.4=pypi_0 62. pandocfilters=1.4.2=pypi_0 63. parso=0.7.0=pypi_0 64. pickleshare=0.7.5=pypi_0 65. pillow=5.2.0=pypi_0 66. pip=21.2.4=py37haa95532_0 67. prometheus-client=0.7.1=pypi_0 68. prompt-toolkit=3.0.5=pypi_0 69. pycparser=2.18=pypi_0 70. pygit=0.1=pypi_0 71. pygments=2.6.1=pypi_0 72. pyparsing=2.2.0=pypi_0 73. pyrsistent=0.16.0=pypi_0 74. python=3.7.11=h6244533_0 75. python-dateutil=2.7.3=pypi_0 76. pytorch=1.0.1=py3.7_cuda80_cudnn7_1 77. pytorch-mutex=1.0=cpu 78. pytz=2018.5=pypi_0 79. pywavelets=0.5.2=pypi_0 80. pywin32=227=pypi_0 81. pywinpty=0.5.7=pypi_0 82. pyyaml=5.1=pypi_0 83. pyzmq=19.0.1=pypi_0 84. scikit-image=0.14.0=pypi_0 85. scikit-learn=0.19.2=pypi_0 86. scipy=1.1.0=pypi_0 87. send2trash=1.5.0=pypi_0 88. setuptools=58.0.4=py37haa95532_0 89. six=1.11.0=pypi_0 90. sqlite=3.36.0=h2bbff1b_0 91. terminado=0.8.3=pypi_0 92. testpath=0.4.4=pypi_0 93. tk=8.6.11=h2bbff1b_0 94. toolz=0.9.0=pypi_0 95. torchvision=0.2.2=py_3 96. tornado=6.0.4=pypi_0 97. tqdm=4.24.0=pypi_0 98. traitlets=4.3.3=pypi_0 99. typing_extensions=3.10.0.2=pyh06a4308_0 100. vc=14.2=h21ff451_1 101. vs2015_runtime=14.27.29016=h5e58377_2 102. wcwidth=0.1.9=pypi_0 103. webencodings=0.5.1=pypi_0 104. wheel=0.37.0=pyhd3eb1b0_1 105. wincertstore=0.2=py37haa95532_2 106. xz=5.2.5=h62dcd97_0 107. zipp=3.1.0=pypi_0 108. zlib=1.2.11=h62dcd97_4 109. zstd=1.4.9=h19a0ad4_0 110.