From 6079269314ca66e969c648e5de09c87e2d2fbbee Mon Sep 17 00:00:00 2001 From: mohamed mosad Date: Fri, 24 Jul 2020 14:23:24 +0200 Subject: [PATCH 1/2] added face swap demo --- faceswap-demo.ipynb | 1 + 1 file changed, 1 insertion(+) create mode 100644 faceswap-demo.ipynb diff --git a/faceswap-demo.ipynb b/faceswap-demo.ipynb new file mode 100644 index 000000000..7166ff7a8 --- /dev/null +++ b/faceswap-demo.ipynb @@ -0,0 +1 @@ +{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n for filename in filenames:\n print(os.path.join(dirname, filename))\n\n# You can write up to 5GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","execution_count":1,"outputs":[{"output_type":"stream","text":"/kaggle/input/srcimgs/876.jpg\n/kaggle/input/targetvidz/target.mp4\n","name":"stdout"}]},{"metadata":{"trusted":true},"cell_type":"code","source":"!nvidia-smi","execution_count":2,"outputs":[{"output_type":"stream","text":"Fri Jul 24 11:41:46 2020 \n+-----------------------------------------------------------------------------+\n| NVIDIA-SMI 418.67 Driver Version: 418.67 CUDA Version: 10.1 |\n|-------------------------------+----------------------+----------------------+\n| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |\n| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |\n|===============================+======================+======================|\n| 0 Tesla P100-PCIE... Off | 00000000:00:04.0 Off | 0 |\n| N/A 37C P0 28W / 250W | 0MiB / 16280MiB | 6% Default |\n+-------------------------------+----------------------+----------------------+\n \n+-----------------------------------------------------------------------------+\n| Processes: GPU Memory |\n| GPU PID Type Process name Usage |\n|=============================================================================|\n| No running processes found |\n+-----------------------------------------------------------------------------+\n","name":"stdout"}]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"!git clone https://github.com/AliaksandrSiarohin/motion-cosegmentation.git","execution_count":3,"outputs":[{"output_type":"stream","text":"Cloning into 'motion-cosegmentation'...\nremote: Enumerating objects: 83, done.\u001b[K\nremote: Counting objects: 100% (83/83), done.\u001b[K\nremote: Compressing objects: 100% (76/76), done.\u001b[K\nremote: Total 83 (delta 25), reused 53 (delta 7), pack-reused 0\u001b[K\nUnpacking objects: 100% (83/83), done.\n","name":"stdout"}]},{"metadata":{"trusted":true},"cell_type":"code","source":"%cd motion-cosegmentation/\n!git clone https://github.com/AliaksandrSiarohin/face-makeup.PyTorch face_parsing","execution_count":4,"outputs":[{"output_type":"stream","text":"/kaggle/working/motion-cosegmentation\n","name":"stdout"}]},{"metadata":{"trusted":true},"cell_type":"code","source":"!conda install -y gdown\n!pip install imageio_ffmpeg\n!mkdir weights/\n# download first order weights\nimport gdown\nid='1n2CqYEjM82X7sE40xrZpmnOxF6NekYW0'\nurl = 'https://drive.google.com/uc?id='\noutdir='weights/'\ngdown.download(url+id, outdir, quiet=False)","execution_count":6,"outputs":[{"output_type":"stream","text":"Collecting package metadata (current_repodata.json): done\nSolving environment: done\n\n## Package Plan ##\n\n environment location: /opt/conda\n\n added / updated specs:\n - gdown\n\n\nThe following packages will be downloaded:\n\n package | build\n ---------------------------|-----------------\n gdown-3.12.0 | pyh9f0ad1d_0 12 KB conda-forge\n ------------------------------------------------------------\n Total: 12 KB\n\nThe following NEW packages will be INSTALLED:\n\n gdown conda-forge/noarch::gdown-3.12.0-pyh9f0ad1d_0\n\n\n\nDownloading and Extracting Packages\ngdown-3.12.0 | 12 KB | ##################################### | 100% \nPreparing transaction: done\nVerifying transaction: done\nExecuting transaction: done\nmkdir: cannot create directory ‘weights/’: File exists\n","name":"stdout"},{"output_type":"stream","text":"Downloading...\nFrom: https://drive.google.com/uc?id=1n2CqYEjM82X7sE40xrZpmnOxF6NekYW0\nTo: /kaggle/working/motion-cosegmentation/weights/vox-first-order.pth.tar\n729MB [00:08, 85.1MB/s] \n","name":"stderr"},{"output_type":"execute_result","execution_count":6,"data":{"text/plain":"'weights/vox-first-order.pth.tar'"},"metadata":{}}]},{"metadata":{"trusted":true},"cell_type":"code","source":"!python part_swap.py --source_image /kaggle/input/srcimgs/unnamed.jpg --target_video /kaggle/input/targetvidz/target.mp4 --checkpoint weights/vox-first-order.pth.tar --config config/vox-256-sem-10segments.yaml --supervised --first_order_motion_model","execution_count":17,"outputs":[{"output_type":"stream","text":"part_swap.py:105: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.\n config = yaml.load(f)\nSegmentation part initialized at random.\nDownloading: \"https://download.pytorch.org/models/resnet18-5c106cde.pth\" to /root/.cache/torch/checkpoints/resnet18-5c106cde.pth\n100%|███████████████████████████████████████| 44.7M/44.7M [00:00<00:00, 185MB/s]\n/opt/conda/lib/python3.7/site-packages/torch/nn/functional.py:2854: UserWarning: The default behavior for interpolate/upsample with float scale_factor will change in 1.6.0 to align with other frameworks/libraries, and use scale_factor directly, instead of relying on the computed output size. If you wish to keep the old behavior, please set recompute_scale_factor=True. See the documentation of nn.Upsample for details. \n warnings.warn(\"The default behavior for interpolate/upsample with float scale_factor will change \"\n 0%| | 0/225 [00:00 Date: Fri, 24 Jul 2020 21:19:20 +0200 Subject: [PATCH 2/2] added proper face segments --- faceswap-demo.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/faceswap-demo.ipynb b/faceswap-demo.ipynb index 7166ff7a8..febefbb32 100644 --- a/faceswap-demo.ipynb +++ b/faceswap-demo.ipynb @@ -1 +1 @@ -{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n for filename in filenames:\n print(os.path.join(dirname, filename))\n\n# You can write up to 5GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","execution_count":1,"outputs":[{"output_type":"stream","text":"/kaggle/input/srcimgs/876.jpg\n/kaggle/input/targetvidz/target.mp4\n","name":"stdout"}]},{"metadata":{"trusted":true},"cell_type":"code","source":"!nvidia-smi","execution_count":2,"outputs":[{"output_type":"stream","text":"Fri Jul 24 11:41:46 2020 \n+-----------------------------------------------------------------------------+\n| NVIDIA-SMI 418.67 Driver Version: 418.67 CUDA Version: 10.1 |\n|-------------------------------+----------------------+----------------------+\n| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |\n| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |\n|===============================+======================+======================|\n| 0 Tesla P100-PCIE... Off | 00000000:00:04.0 Off | 0 |\n| N/A 37C P0 28W / 250W | 0MiB / 16280MiB | 6% Default |\n+-------------------------------+----------------------+----------------------+\n \n+-----------------------------------------------------------------------------+\n| Processes: GPU Memory |\n| GPU PID Type Process name Usage |\n|=============================================================================|\n| No running processes found |\n+-----------------------------------------------------------------------------+\n","name":"stdout"}]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"!git clone https://github.com/AliaksandrSiarohin/motion-cosegmentation.git","execution_count":3,"outputs":[{"output_type":"stream","text":"Cloning into 'motion-cosegmentation'...\nremote: Enumerating objects: 83, done.\u001b[K\nremote: Counting objects: 100% (83/83), done.\u001b[K\nremote: Compressing objects: 100% (76/76), done.\u001b[K\nremote: Total 83 (delta 25), reused 53 (delta 7), pack-reused 0\u001b[K\nUnpacking objects: 100% (83/83), done.\n","name":"stdout"}]},{"metadata":{"trusted":true},"cell_type":"code","source":"%cd motion-cosegmentation/\n!git clone https://github.com/AliaksandrSiarohin/face-makeup.PyTorch face_parsing","execution_count":4,"outputs":[{"output_type":"stream","text":"/kaggle/working/motion-cosegmentation\n","name":"stdout"}]},{"metadata":{"trusted":true},"cell_type":"code","source":"!conda install -y gdown\n!pip install imageio_ffmpeg\n!mkdir weights/\n# download first order weights\nimport gdown\nid='1n2CqYEjM82X7sE40xrZpmnOxF6NekYW0'\nurl = 'https://drive.google.com/uc?id='\noutdir='weights/'\ngdown.download(url+id, outdir, quiet=False)","execution_count":6,"outputs":[{"output_type":"stream","text":"Collecting package metadata (current_repodata.json): done\nSolving environment: done\n\n## Package Plan ##\n\n environment location: /opt/conda\n\n added / updated specs:\n - gdown\n\n\nThe following packages will be downloaded:\n\n package | build\n ---------------------------|-----------------\n gdown-3.12.0 | pyh9f0ad1d_0 12 KB conda-forge\n ------------------------------------------------------------\n Total: 12 KB\n\nThe following NEW packages will be INSTALLED:\n\n gdown conda-forge/noarch::gdown-3.12.0-pyh9f0ad1d_0\n\n\n\nDownloading and Extracting Packages\ngdown-3.12.0 | 12 KB | ##################################### | 100% \nPreparing transaction: done\nVerifying transaction: done\nExecuting transaction: done\nmkdir: cannot create directory ‘weights/’: File exists\n","name":"stdout"},{"output_type":"stream","text":"Downloading...\nFrom: https://drive.google.com/uc?id=1n2CqYEjM82X7sE40xrZpmnOxF6NekYW0\nTo: /kaggle/working/motion-cosegmentation/weights/vox-first-order.pth.tar\n729MB [00:08, 85.1MB/s] \n","name":"stderr"},{"output_type":"execute_result","execution_count":6,"data":{"text/plain":"'weights/vox-first-order.pth.tar'"},"metadata":{}}]},{"metadata":{"trusted":true},"cell_type":"code","source":"!python part_swap.py --source_image /kaggle/input/srcimgs/unnamed.jpg --target_video /kaggle/input/targetvidz/target.mp4 --checkpoint weights/vox-first-order.pth.tar --config config/vox-256-sem-10segments.yaml --supervised --first_order_motion_model","execution_count":17,"outputs":[{"output_type":"stream","text":"part_swap.py:105: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.\n config = yaml.load(f)\nSegmentation part initialized at random.\nDownloading: \"https://download.pytorch.org/models/resnet18-5c106cde.pth\" to /root/.cache/torch/checkpoints/resnet18-5c106cde.pth\n100%|███████████████████████████████████████| 44.7M/44.7M [00:00<00:00, 185MB/s]\n/opt/conda/lib/python3.7/site-packages/torch/nn/functional.py:2854: UserWarning: The default behavior for interpolate/upsample with float scale_factor will change in 1.6.0 to align with other frameworks/libraries, and use scale_factor directly, instead of relying on the computed output size. If you wish to keep the old behavior, please set recompute_scale_factor=True. See the documentation of nn.Upsample for details. \n warnings.warn(\"The default behavior for interpolate/upsample with float scale_factor will change \"\n 0%| | 0/225 [00:00