From 04b5b113264f91399a1775533fd49d80167395b1 Mon Sep 17 00:00:00 2001 From: Aleksey Morozov <36787333+amrzv@users.noreply.github.com> Date: Sun, 11 Jul 2021 12:46:55 +0300 Subject: [PATCH 1/3] showing original and processed video inline --- SimSwap colab.ipynb | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/SimSwap colab.ipynb b/SimSwap colab.ipynb index 850989b3..bf74b2e3 100644 --- a/SimSwap colab.ipynb +++ b/SimSwap colab.ipynb @@ -351,6 +351,25 @@ } ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from IPython.display import HTML\n", + "from base64 import b64encode\n", + "\n", + "def show_mp4(filename, width=720):\n", + " mp4 = open(filename, 'rb').read()\n", + " data_url = \"data:video/mp4;base64,\" + b64encode(mp4).decode()\n", + " display(HTML(\"\"\"\n", + " <video width=\"%d\" controls autoplay loop>\n", + " <source src=\"%s\" type=\"video/mp4\">\n", + " </video>\n", + " \"\"\" % (width, data_url))) " + ] + }, { "cell_type": "code", "metadata": { @@ -564,12 +583,32 @@ } ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "show_mp4(opt.video_path) # original video" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "img_a_align_crop_pil # swappable face" + ] + }, { "cell_type": "code", "metadata": { "id": "Rty2GsyZZrI6" }, - "source": [], + "source": [ + "show_mp4(opt.output_path) # processed video" + ], "execution_count": null, "outputs": [] } From 03f2d8dc7abd226f306025c5de810352e1dec5f7 Mon Sep 17 00:00:00 2001 From: Aleksey Morozov <36787333+amrzv@users.noreply.github.com> Date: Sun, 11 Jul 2021 12:48:18 +0300 Subject: [PATCH 2/3] remove unused imports --- SimSwap colab.ipynb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/SimSwap colab.ipynb b/SimSwap colab.ipynb index bf74b2e3..279bb998 100644 --- a/SimSwap colab.ipynb +++ b/SimSwap colab.ipynb @@ -325,7 +325,6 @@ "source": [ "import cv2\n", "import torch\n", - "import fractions\n", "import numpy as np\n", "from PIL import Image\n", "import torch.nn.functional as F\n", @@ -333,8 +332,7 @@ "from models.models import create_model\n", "from options.test_options import TestOptions\n", "from insightface_func.face_detect_crop_multi import Face_detect_crop\n", - "from util.videoswap import video_swap\n", - "from util.add_watermark import watermark_image" + "from util.videoswap import video_swap" ], "execution_count": 7, "outputs": [ From 10c261808215fd9663e94725a25b15478f5c7df0 Mon Sep 17 00:00:00 2001 From: Aleksey Morozov <36787333+amrzv@users.noreply.github.com> Date: Sun, 11 Jul 2021 13:07:34 +0300 Subject: [PATCH 3/3] change googledrivedownloader to gdown --- SimSwap colab.ipynb | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/SimSwap colab.ipynb b/SimSwap colab.ipynb index 279bb998..04934ac2 100644 --- a/SimSwap colab.ipynb +++ b/SimSwap colab.ipynb @@ -127,9 +127,7 @@ "outputId": "9691a7a4-192e-4ec2-c3c1-1f2c933d7b6a" }, "source": [ - "!pip install insightface==0.2.1 onnxruntime moviepy\n", - "!pip install googledrivedownloader\n", - "!pip install imageio==2.4.1" + "!pip install insightface==0.2.1 onnxruntime imageio==2.4.1" ], "execution_count": 3, "outputs": [ @@ -224,13 +222,9 @@ "outputId": "e93c3f98-01df-458e-b791-c32f7343e705" }, "source": [ - "from google_drive_downloader import GoogleDriveDownloader\n", - "\n", "### it seems that google drive link may not be permenant, you can find this ID from our open url.\n", - "# GoogleDriveDownloader.download_file_from_google_drive(file_id='1TLNdIufzwesDbyr_nVTR7Zrx9oRHLM_N',\n", - "# dest_path='./arcface_model/arcface_checkpoint.tar')\n", - "# GoogleDriveDownloader.download_file_from_google_drive(file_id='1PXkRiBUYbu1xWpQyDEJvGKeqqUFthJcI',\n", - "# dest_path='./checkpoints.zip')\n", + "# !mkdir arcface_model && gdown --id 1TLNdIufzwesDbyr_nVTR7Zrx9oRHLM_N -O ./arcface_model/arcface_checkpoint.tar\n", + "# !gdown --id 1PXkRiBUYbu1xWpQyDEJvGKeqqUFthJcI -O checkpoints.zip\n", "\n", "!wget -P ./arcface_model https://github.com/neuralchen/SimSwap/releases/download/1.0/arcface_checkpoint.tar\n", "!wget https://github.com/neuralchen/SimSwap/releases/download/1.0/checkpoints.zip\n", @@ -277,7 +271,7 @@ "### open url(can be found at [our repo]/doc/guidance/preparation.md) and copy the assigned download link here.\n", "### many thanks to woctezuma for this very useful help\n", "!wget --no-check-certificate \"https://sh23tw.dm.files.1drv.com/y4mmGiIkNVigkSwOKDcV3nwMJulRGhbtHdkheehR5TArc52UjudUYNXAEvKCii2O5LAmzGCGK6IfleocxuDeoKxDZkNzDRSt4ZUlEt8GlSOpCXAFEkBwaZimtWGDRbpIGpb_pz9Nq5jATBQpezBS6G_UtspWTkgrXHHxhviV2nWy8APPx134zOZrUIbkSF6xnsqzs3uZ_SEX_m9Rey0ykpx9w\" -O antelope.zip\n", - "!unzip ./antelope.zip -d ./insightface_func/models/\n" + "!unzip ./antelope.zip -d ./insightface_func/models/" ], "execution_count": 6, "outputs": [ @@ -358,6 +352,7 @@ "from IPython.display import HTML\n", "from base64 import b64encode\n", "\n", + "\n", "def show_mp4(filename, width=720):\n", " mp4 = open(filename, 'rb').read()\n", " data_url = \"data:video/mp4;base64,\" + b64encode(mp4).decode()\n", @@ -365,7 +360,7 @@ " <video width=\"%d\" controls autoplay loop>\n", " <source src=\"%s\" type=\"video/mp4\">\n", " </video>\n", - " \"\"\" % (width, data_url))) " + " \"\"\" % (width, data_url)))" ] }, { @@ -376,7 +371,7 @@ "source": [ "transformer = transforms.Compose([\n", " transforms.ToTensor(),\n", - " #transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])\n", + " # transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])\n", " ])\n", "\n", "transformer_Arcface = transforms.Compose([\n", @@ -404,10 +399,10 @@ "source": [ "opt = TestOptions()\n", "opt.initialize()\n", - "opt.parser.add_argument('-f') ## dummy arg to avoid bug\n", + "opt.parser.add_argument('-f') # dummy arg to avoid bug\n", "opt = opt.parse()\n", - "opt.pic_a_path = './demo_file/Iron_man.jpg' ## or replace it with image from your own google drive\n", - "opt.video_path = './demo_file/multi_people_1080p.mp4' ## or replace it with video from your own google drive\n", + "opt.pic_a_path = './demo_file/Iron_man.jpg' # or replace it with image from your own google drive\n", + "opt.video_path = './demo_file/multi_people_1080p.mp4' # or replace it with video from your own google drive\n", "opt.output_path = './output/demo.mp4'\n", "opt.temp_path = './tmp'\n", "opt.Arc_path = './arcface_model/arcface_checkpoint.tar'\n", @@ -421,27 +416,27 @@ "\n", "\n", "app = Face_detect_crop(name='antelope', root='./insightface_func/models')\n", - "app.prepare(ctx_id= 0, det_thresh=0.6, det_size=(640,640))\n", + "app.prepare(ctx_id=0, det_thresh=0.6, det_size=(640, 640))\n", "\n", "pic_a = opt.pic_a_path\n", "# img_a = Image.open(pic_a).convert('RGB')\n", "img_a_whole = cv2.imread(pic_a)\n", - "img_a_align_crop, _ = app.get(img_a_whole,crop_size)\n", - "img_a_align_crop_pil = Image.fromarray(cv2.cvtColor(img_a_align_crop[0],cv2.COLOR_BGR2RGB)) \n", + "img_a_align_crop, _ = app.get(img_a_whole, crop_size)\n", + "img_a_align_crop_pil = Image.fromarray(cv2.cvtColor(img_a_align_crop[0], cv2.COLOR_BGR2RGB))\n", "img_a = transformer_Arcface(img_a_align_crop_pil)\n", "img_id = img_a.view(-1, img_a.shape[0], img_a.shape[1], img_a.shape[2])\n", "\n", "# convert numpy to tensor\n", "img_id = img_id.cuda()\n", "\n", - "#create latent id\n", + "# create latent id\n", "img_id_downsample = F.interpolate(img_id, scale_factor=0.5)\n", "latend_id = model.netArc(img_id_downsample)\n", "latend_id = latend_id.detach().to('cpu')\n", - "latend_id = latend_id/np.linalg.norm(latend_id,axis=1,keepdims=True)\n", + "latend_id = latend_id/np.linalg.norm(latend_id, axis=1, keepdims=True)\n", "latend_id = latend_id.to('cuda')\n", "\n", - "video_swap(opt.video_path, latend_id, model, app, opt.output_path,temp_results_dir=opt.temp_path)" + "video_swap(opt.video_path, latend_id, model, app, opt.output_path, temp_results_dir=opt.temp_path)" ], "execution_count": 9, "outputs": [