其他分享
首页 > 其他分享> > deepfake使用

deepfake使用

作者:互联网

Github下载开源项目:https://github.com/deepfakes/faceswap

anaconda 创建环境:

conda create -n tf python=3.7

cd命令进入项目所在文件夹,进行安装

python setup.py
INFO    Running without root/admin privileges
INFO    The tool provides tips for installation
        and installs required python packages
INFO    Setup in Linux 5.13.0-30-generic
INFO    Installed Python: 3.7.13 64bit
INFO    Running in Conda
INFO    Running in a Virtual Environment
INFO    Encoding: UTF-8
INFO    Installed pip: 21.2.2
INFO    AMD Support: AMD GPU support is currently limited.
        Nvidia Users MUST answer 'no' to this option.
Enable AMD Support? [y/N] no
INFO    AMD Support Disabled
Enable  Docker? [y/N] no
INFO    Docker Disabled
Enable  CUDA? [Y/n] y
INFO    CUDA Enabled
INFO    Skipping Cuda/cuDNN checks for Conda install
INFO    Faceswap config written to: /home/bim/project-csc/faceswap-master/config/.faceswap
Please ensure your System Dependencies are met. Continue? [y/N] y
INFO    Installing Required Python Packages. This may take some time...
INFO    Installing tqdm>=4.64
INFO    Installing psutil>=5.8.0
INFO    Installing numpy>=1.18.0
INFO    Installing opencv-python>=4.5.5.0
INFO    "opencv-python>=4.5.5.0" not available in Conda. Installing with pip
INFO    Installing opencv-python>=4.5.5.0
INFO    Installing pillow>=8.3.1
INFO    Installing scikit-learn>=1.0.2
INFO    Installing fastcluster>=1.2.4
INFO    Installing matplotlib>=3.5.1
INFO    "matplotlib>=3.5.1" not available in Conda. Installing with pip
INFO    Installing matplotlib>=3.5.1
INFO    Installing imageio>=2.9.0
INFO    Installing imageio-ffmpeg>=0.4.7
INFO    Installing ffmpy==0.2.3
INFO    ffmpy==0.2.3 not available in Conda. Installing with pip
INFO    Installing ffmpy==0.2.3
INFO    Installing nvidia-ml-py<11.515
INFO    "nvidia-ml-py<11.515" not available in Conda. Installing with pip
INFO    Installing nvidia-ml-py<11.515
INFO    Installing typing-extensions
INFO    Installing Cuda Toolkit
Solving environment: failed

PackagesNotFoundError: The following packages are not available from current channels:

  - cudatoolkit=11.2
  - __glibc[version='>=2.17,<3.0.a0']
  - cudnn=8.1
  - __glibc[version='>=2.17,<3.0.a0']

Current channels:

  - https://conda.anaconda.org/conda-forge/linux-64
  - https://conda.anaconda.org/conda-forge/noarch
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/linux-64
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/noarch
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/noarch

To search for alternate channels that may provide the conda package you're
looking for, navigate to

    https://anaconda.org

and use the search bar at the top of the page.


WARNING Couldn't install Cuda Toolkit with Conda. Please install this package manually
INFO    Installing tensorflow-gpu>=2.5.0,<2.9.0
Collecting tensorflow-gpu<2.9.0,>=2.5.0
  Downloading tensorflow_gpu-2.8.1-cp37-cp37m-manylinux2010_x86_64.whl (497.9 MB)
     |████████████████████████████████| 497.9 MB 11.9 MB/s 
Requirement already satisfied: typing-extensions>=3.6.6 in /home/bim/anaconda3/envs/tf/lib/python3.7/site-packages (from tensorflow-gpu<2.9.0,>=2.5.0) (4.2.0)
Collecting google-pasta>=0.1.1
  Downloading google_pasta-0.2.0-py3-none-any.whl (57 kB)
     |████████████████████████████████| 57 kB 13.7 MB/s 
Requirement already satisfied: numpy>=1.20 in /home/bim/anaconda3/envs/tf/lib/python3.7/site-packages (from tensorflow-gpu<2.9.0,>=2.5.0) (1.20.3)
Collecting gast>=0.2.1
  Downloading gast-0.5.3-py3-none-any.whl (19 kB)
Collecting astunparse>=1.6.0
  Downloading astunparse-1.6.3-py2.py3-none-any.whl (12 kB)
Collecting flatbuffers>=1.12
  Downloading flatbuffers-2.0-py2.py3-none-any.whl (26 kB)
Collecting libclang>=9.0.1
  Downloading libclang-14.0.1-py2.py3-none-manylinux1_x86_64.whl (14.5 MB)
     |████████████████████████████████| 14.5 MB 8.2 MB/s 
Collecting grpcio<2.0,>=1.24.3
  Downloading grpcio-1.46.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.4 MB)
     |████████████████████████████████| 4.4 MB 11.4 MB/s 
Collecting tensorboard<2.9,>=2.8
  Downloading tensorboard-2.8.0-py3-none-any.whl (5.8 MB)
     |████████████████████████████████| 5.8 MB 9.0 MB/s 
Collecting tensorflow-estimator<2.9,>=2.8
  Downloading tensorflow_estimator-2.8.0-py2.py3-none-any.whl (462 kB)
     |████████████████████████████████| 462 kB 11.4 MB/s 
Collecting h5py>=2.9.0
  Downloading h5py-3.6.0-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (4.1 MB)
     |████████████████████████████████| 4.1 MB 11.1 MB/s 
Requirement already satisfied: setuptools in /home/bim/anaconda3/envs/tf/lib/python3.7/site-packages (from tensorflow-gpu<2.9.0,>=2.5.0) (61.2.0)
Collecting termcolor>=1.1.0
  Downloading termcolor-1.1.0.tar.gz (3.9 kB)
Collecting keras<2.9,>=2.8.0rc0
  Downloading keras-2.8.0-py2.py3-none-any.whl (1.4 MB)
     |████████████████████████████████| 1.4 MB 11.4 MB/s 
Collecting keras-preprocessing>=1.1.1
  Downloading Keras_Preprocessing-1.1.2-py2.py3-none-any.whl (42 kB)
     |████████████████████████████████| 42 kB 14.1 MB/s 
Collecting protobuf>=3.9.2
  Downloading protobuf-3.20.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (1.0 MB)
     |████████████████████████████████| 1.0 MB 11.3 MB/s 
Collecting opt-einsum>=2.3.2
  Downloading opt_einsum-3.3.0-py3-none-any.whl (65 kB)
     |████████████████████████████████| 65 kB 13.4 MB/s 
Collecting tensorflow-io-gcs-filesystem>=0.23.1
  Downloading tensorflow_io_gcs_filesystem-0.26.0-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (2.4 MB)
     |████████████████████████████████| 2.4 MB 11.1 MB/s 
Collecting absl-py>=0.4.0
  Downloading absl_py-1.0.0-py3-none-any.whl (126 kB)
     |████████████████████████████████| 126 kB 12.0 MB/s 
Requirement already satisfied: six>=1.12.0 in /home/bim/anaconda3/envs/tf/lib/python3.7/site-packages (from tensorflow-gpu<2.9.0,>=2.5.0) (1.16.0)
Collecting wrapt>=1.11.0
  Downloading wrapt-1.14.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (75 kB)
     |████████████████████████████████| 75 kB 13.0 MB/s 
Requirement already satisfied: wheel<1.0,>=0.23.0 in /home/bim/anaconda3/envs/tf/lib/python3.7/site-packages (from astunparse>=1.6.0->tensorflow-gpu<2.9.0,>=2.5.0) (0.37.1)
Collecting cached-property
  Downloading cached_property-1.5.2-py2.py3-none-any.whl (7.6 kB)
Collecting tensorboard-data-server<0.7.0,>=0.6.0
  Downloading tensorboard_data_server-0.6.1-py3-none-manylinux2010_x86_64.whl (4.9 MB)
     |████████████████████████████████| 4.9 MB 11.3 MB/s 
Collecting google-auth-oauthlib<0.5,>=0.4.1
  Downloading google_auth_oauthlib-0.4.6-py2.py3-none-any.whl (18 kB)
Collecting tensorboard-plugin-wit>=1.6.0
  Downloading tensorboard_plugin_wit-1.8.1-py3-none-any.whl (781 kB)
     |████████████████████████████████| 781 kB 12.0 MB/s 
Collecting requests<3,>=2.21.0
  Downloading requests-2.27.1-py2.py3-none-any.whl (63 kB)
     |████████████████████████████████| 63 kB 13.2 MB/s 
Collecting markdown>=2.6.8
  Downloading Markdown-3.3.7-py3-none-any.whl (97 kB)
     |████████████████████████████████| 97 kB 13.2 MB/s 
Collecting werkzeug>=0.11.15
  Downloading Werkzeug-2.1.2-py3-none-any.whl (224 kB)
     |████████████████████████████████| 224 kB 11.1 MB/s 
Collecting google-auth<3,>=1.6.3
  Downloading google_auth-2.6.6-py2.py3-none-any.whl (156 kB)
     |████████████████████████████████| 156 kB 11.1 MB/s 
Collecting cachetools<6.0,>=2.0.0
  Downloading cachetools-5.1.0-py3-none-any.whl (9.2 kB)
Collecting pyasn1-modules>=0.2.1
  Downloading pyasn1_modules-0.2.8-py2.py3-none-any.whl (155 kB)
     |████████████████████████████████| 155 kB 11.1 MB/s 
Collecting rsa<5,>=3.1.4
  Downloading rsa-4.8-py3-none-any.whl (39 kB)
Collecting requests-oauthlib>=0.7.0
  Downloading requests_oauthlib-1.3.1-py2.py3-none-any.whl (23 kB)
Collecting importlib-metadata>=4.4
  Downloading importlib_metadata-4.11.3-py3-none-any.whl (18 kB)
Collecting zipp>=0.5
  Downloading zipp-3.8.0-py3-none-any.whl (5.4 kB)
Collecting pyasn1<0.5.0,>=0.4.6
  Downloading pyasn1-0.4.8-py2.py3-none-any.whl (77 kB)
     |████████████████████████████████| 77 kB 12.5 MB/s 
Collecting charset-normalizer~=2.0.0
  Downloading charset_normalizer-2.0.12-py3-none-any.whl (39 kB)
Collecting urllib3<1.27,>=1.21.1
  Downloading urllib3-1.26.9-py2.py3-none-any.whl (138 kB)
     |████████████████████████████████| 138 kB 11.2 MB/s 
Requirement already satisfied: certifi>=2017.4.17 in /home/bim/anaconda3/envs/tf/lib/python3.7/site-packages (from requests<3,>=2.21.0->tensorboard<2.9,>=2.8->tensorflow-gpu<2.9.0,>=2.5.0) (2022.5.18.1)
Collecting idna<4,>=2.5
  Downloading idna-3.3-py3-none-any.whl (61 kB)
     |████████████████████████████████| 61 kB 13.0 MB/s 
Collecting oauthlib>=3.0.0
  Downloading oauthlib-3.2.0-py3-none-any.whl (151 kB)
     |████████████████████████████████| 151 kB 11.3 MB/s 
Building wheels for collected packages: termcolor
  Building wheel for termcolor (setup.py) ... done
  Created wheel for termcolor: filename=termcolor-1.1.0-py3-none-any.whl size=4848 sha256=f0c42830bca3d8858668bb7252a993b9e4c39385d50c72f3340856926d4f5f9e
  Stored in directory: /tmp/pip-ephem-wheel-cache-h10wtvcm/wheels/3f/e3/ec/8a8336ff196023622fbcb36de0c5a5c218cbb24111d1d4c7f2
Successfully built termcolor
Installing collected packages: urllib3, pyasn1, idna, charset-normalizer, zipp, rsa, requests, pyasn1-modules, oauthlib, cachetools, requests-oauthlib, importlib-metadata, google-auth, werkzeug, tensorboard-plugin-wit, tensorboard-data-server, protobuf, markdown, grpcio, google-auth-oauthlib, cached-property, absl-py, wrapt, termcolor, tensorflow-io-gcs-filesystem, tensorflow-estimator, tensorboard, opt-einsum, libclang, keras-preprocessing, keras, h5py, google-pasta, gast, flatbuffers, astunparse, tensorflow-gpu
Successfully installed absl-py-1.0.0 astunparse-1.6.3 cached-property-1.5.2 cachetools-5.1.0 charset-normalizer-2.0.12 flatbuffers-2.0 gast-0.5.3 google-auth-2.6.6 google-auth-oauthlib-0.4.6 google-pasta-0.2.0 grpcio-1.46.1 h5py-3.6.0 idna-3.3 importlib-metadata-4.11.3 keras-2.8.0 keras-preprocessing-1.1.2 libclang-14.0.1 markdown-3.3.7 oauthlib-3.2.0 opt-einsum-3.3.0 protobuf-3.20.1 pyasn1-0.4.8 pyasn1-modules-0.2.8 requests-2.27.1 requests-oauthlib-1.3.1 rsa-4.8 tensorboard-2.8.0 tensorboard-data-server-0.6.1 tensorboard-plugin-wit-1.8.1 tensorflow-estimator-2.8.0 tensorflow-gpu-2.8.1 tensorflow-io-gcs-filesystem-0.26.0 termcolor-1.1.0 urllib3-1.26.9 werkzeug-2.1.2 wrapt-1.14.1 zipp-3.8.0
INFO    All python3 dependencies are met.
        You are good to go.
        
        Enter:  'python faceswap.py -h' to see the options
                'python faceswap.py gui' to launch the GUI

建立原始图像文件夹source,下设两个文件夹分别储存被替换人物图像和替换人物图像,可以用视频

人像抓取(从视频):

python faceswap.py extract -i /home/bim/project-csc/faceswap-master/source/chaoyue -o /home/bim/project-csc/faceswap-master/source/xiaopang/

开始训练:

python faceswap.py train -A ./face/chaoyue -B ./face/xiaopang -m ./model/

训练过程:

Setting Faceswap backend to NVIDIA
05/20/2022 18:57:30 INFO     Log level set to: INFO
05/20/2022 18:57:31 INFO     Model A Directory: '/home/bim/project-csc/faceswap-master/face/chaoyue' (354 images)
05/20/2022 18:57:31 INFO     Model B Directory: '/home/bim/project-csc/faceswap-master/face/xiaopang' (302 images)
05/20/2022 18:57:31 INFO     Training data directory: /home/bim/project-csc/faceswap-master/model
05/20/2022 18:57:31 INFO     ===================================================
05/20/2022 18:57:31 INFO       Starting
05/20/2022 18:57:31 INFO       Press 'ENTER' to save and quit
05/20/2022 18:57:31 INFO       Press 'S' to save model weights immediately
05/20/2022 18:57:31 INFO     ===================================================
05/20/2022 18:57:32 INFO     Loading data, this may take a while...
05/20/2022 18:57:32 INFO     Loading Model from Original plugin...
05/20/2022 18:57:32 INFO     No existing state file found. Generating.
05/20/2022 18:57:35 INFO     Loading Trainer from Original plugin...
[18:57:48] [#00001] Loss A: 0.29092, Loss B: 0.25283
05/20/2022 18:57:48 INFO     [Saved models] - Average loss since last save: face_a: 0.29092, face_b: 0.25283
[18:58:31] [#00250] Loss A: 0.08387, Loss B: 0.12929
05/20/2022 18:58:31 INFO     [Saved models] - Average loss since last save: face_a: 0.12682, face_b: 0.16347
[18:59:11] [#00500] Loss A: 0.08441, Loss B: 0.11587
05/20/2022 18:59:12 INFO     [Saved models] - Average loss since last save: face_a: 0.08083, face_b: 0.11646
[18:59:52] [#00750] Loss A: 0.06658, Loss B: 0.09254
05/20/2022 18:59:53 INFO     [Saved models] - Average loss since last save: face_a: 0.06893, face_b: 0.10239
[19:00:33] [#01000] Loss A: 0.05453, Loss B: 0.07997
05/20/2022 19:00:34 INFO     [Saved models] - Average loss since last save: face_a: 0.06153, face_b: 0.09495
[19:01:15] [#01250] Loss A: 0.05931, Loss B: 0.10159
05/20/2022 19:01:16 INFO     [Saved models] - Average loss since last save: face_a: 0.05717, face_b: 0.08923
[19:01:58] [#01500] Loss A: 0.05073, Loss B: 0.08939
05/20/2022 19:01:58 INFO     [Saved models] - Average loss since last save: face_a: 0.05318, face_b: 0.08536
[19:02:40] [#01750] Loss A: 0.04741, Loss B: 0.07891
05/20/2022 19:02:41 INFO     [Saved models] - Average loss since last save: face_a: 0.05014, face_b: 0.08195
[19:03:23] [#02000] Loss A: 0.05117, Loss B: 0.07520
05/20/2022 19:03:24 INFO     [Saved models] - Average loss since last save: face_a: 0.04778, face_b: 0.08011
[19:04:05] [#02250] Loss A: 0.04463, Loss B: 0.08217
05/20/2022 19:04:06 INFO     [Saved models] - Average loss since last save: face_a: 0.04666, face_b: 0.07742
[19:04:47] [#02500] Loss A: 0.04054, Loss B: 0.08013
05/20/2022 19:04:48 INFO     [Saved models] - Average loss since last save: face_a: 0.04453, face_b: 0.07574
[19:05:29] [#02750] Loss A: 0.03798, Loss B: 0.07508
05/20/2022 19:05:30 INFO     [Saved models] - Average loss since last save: face_a: 0.04322, face_b: 0.07385
[19:06:11] [#03000] Loss A: 0.04088, Loss B: 0.06374
05/20/2022 19:06:12 INFO     [Saved models] - Average loss since last save: face_a: 0.04156, face_b: 0.07255
[19:06:54] [#03250] Loss A: 0.04008, Loss B: 0.06920
05/20/2022 19:06:54 INFO     [Saved models] - Average loss since last save: face_a: 0.04128, face_b: 0.07075
[19:07:36] [#03500] Loss A: 0.03971, Loss B: 0.07669
05/20/2022 19:07:36 INFO     [Saved models] - Average loss since last save: face_a: 0.03975, face_b: 0.06984
[19:08:18] [#03750] Loss A: 0.04245, Loss B: 0.06629
05/20/2022 19:08:19 INFO     [Saved models] - Average loss since last save: face_a: 0.03923, face_b: 0.06923
[19:09:00] [#04000] Loss A: 0.04397, Loss B: 0.06900
05/20/2022 19:09:01 INFO     [Saved models] - Average loss since last save: face_a: 0.03823, face_b: 0.06784
[19:09:42] [#04250] Loss A: 0.03289, Loss B: 0.06148
05/20/2022 19:09:42 INFO     [Saved models] - Average loss since last save: face_a: 0.03736, face_b: 0.06743
[19:10:25] [#04500] Loss A: 0.03530, Loss B: 0.07094
05/20/2022 19:10:25 INFO     [Saved models] - Average loss since last save: face_a: 0.03702, face_b: 0.06596
[19:11:07] [#04750] Loss A: 0.03651, Loss B: 0.06341
05/20/2022 19:11:08 INFO     [Saved models] - Average loss since last save: face_a: 0.03644, face_b: 0.06522
[19:11:49] [#05000] Loss A: 0.02978, Loss B: 0.05741
05/20/2022 19:11:50 INFO     [Saved models] - Average loss since last save: face_a: 0.03594, face_b: 0.06486
[19:12:31] [#05250] Loss A: 0.03091, Loss B: 0.06061
05/20/2022 19:12:32 INFO     [Saved models] - Average loss since last save: face_a: 0.03553, face_b: 0.06409
[19:13:13] [#05500] Loss A: 0.03453, Loss B: 0.06567
05/20/2022 19:13:14 INFO     [Saved models] - Average loss since last save: face_a: 0.03487, face_b: 0.06315
[19:13:55] [#05750] Loss A: 0.03094, Loss B: 0.06266
05/20/2022 19:13:56 INFO     [Saved models] - Average loss since last save: face_a: 0.03468, face_b: 0.06292
[19:14:38] [#06000] Loss A: 0.03007, Loss B: 0.05961
05/20/2022 19:14:38 INFO     [Saved models] - Average loss since last save: face_a: 0.03437, face_b: 0.06176
[19:15:19] [#06250] Loss A: 0.03887, Loss B: 0.06390
05/20/2022 19:15:20 INFO     [Saved models] - Average loss since last save: face_a: 0.03335, face_b: 0.06121
[19:16:02] [#06500] Loss A: 0.03204, Loss B: 0.06094
05/20/2022 19:16:04 INFO     [Saved models] - Average loss since last save: face_a: 0.03344, face_b: 0.06102
[19:16:45] [#06750] Loss A: 0.03290, Loss B: 0.05749
05/20/2022 19:16:45 INFO     [Saved models] - Average loss since last save: face_a: 0.03324, face_b: 0.06002
[19:17:27] [#07000] Loss A: 0.03356, Loss B: 0.05954
05/20/2022 19:17:29 INFO     [Saved models] - Average loss since last save: face_a: 0.03313, face_b: 0.06050
[19:18:10] [#07250] Loss A: 0.02756, Loss B: 0.05608
05/20/2022 19:18:10 INFO     [Saved models] - Average loss since last save: face_a: 0.03261, face_b: 0.05931
[19:18:51] [#07500] Loss A: 0.03412, Loss B: 0.05743
05/20/2022 19:18:52 INFO     [Saved models] - Average loss since last save: face_a: 0.03206, face_b: 0.05913
[19:19:34] [#07750] Loss A: 0.02854, Loss B: 0.05528
05/20/2022 19:19:35 INFO     [Saved models] - Average loss since last save: face_a: 0.03212, face_b: 0.05822
[19:20:16] [#08000] Loss A: 0.03306, Loss B: 0.06277
05/20/2022 19:20:17 INFO     [Saved models] - Average loss since last save: face_a: 0.03167, face_b: 0.05836
[19:20:58] [#08250] Loss A: 0.02742, Loss B: 0.05388
05/20/2022 19:20:59 INFO     [Saved models] - Average loss since last save: face_a: 0.03128, face_b: 0.05754
[19:21:41] [#08500] Loss A: 0.02840, Loss B: 0.05149
05/20/2022 19:21:42 INFO     [Saved models] - Average loss since last save: face_a: 0.03093, face_b: 0.05766

enter结束训练,模型存放在./model

视频转图像

 ffmpeg -i ./source/chaoyue/s1.mp4 ./convert/before/video-%d.png

对原始视频的图像逐帧替换

python faceswap.py convert -i ./convert/before/ -o ./convert/after/ -m ./model/

图像合成视频

ffmpeg -i video-%d.png -c:v libx264 -vf "fps=25,format=yuv420p" out.mp4

 

标签:INFO,Loss,20,05,19,face,使用,deepfake
来源: https://www.cnblogs.com/chensongchun/p/16293840.html