Colab enhance #47
+51
-19
@@ -127,9 +127,7 @@
|
|||||||
"outputId": "9691a7a4-192e-4ec2-c3c1-1f2c933d7b6a"
|
"outputId": "9691a7a4-192e-4ec2-c3c1-1f2c933d7b6a"
|
||||||
},
|
},
|
||||||
"source": [
|
"source": [
|
||||||
"!pip install insightface==0.2.1 onnxruntime moviepy\n",
|
"!pip install insightface==0.2.1 onnxruntime imageio==2.4.1"
|
||||||
"!pip install googledrivedownloader\n",
|
|
||||||
"!pip install imageio==2.4.1"
|
|
||||||
],
|
],
|
||||||
"execution_count": 3,
|
"execution_count": 3,
|
||||||
"outputs": [
|
"outputs": [
|
||||||
@@ -224,13 +222,9 @@
|
|||||||
"outputId": "e93c3f98-01df-458e-b791-c32f7343e705"
|
"outputId": "e93c3f98-01df-458e-b791-c32f7343e705"
|
||||||
},
|
},
|
||||||
"source": [
|
"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",
|
"### 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",
|
"# !mkdir arcface_model && gdown --id 1TLNdIufzwesDbyr_nVTR7Zrx9oRHLM_N -O ./arcface_model/arcface_checkpoint.tar\n",
|
||||||
"# dest_path='./arcface_model/arcface_checkpoint.tar')\n",
|
"# !gdown --id 1PXkRiBUYbu1xWpQyDEJvGKeqqUFthJcI -O checkpoints.zip\n",
|
||||||
"# GoogleDriveDownloader.download_file_from_google_drive(file_id='1PXkRiBUYbu1xWpQyDEJvGKeqqUFthJcI',\n",
|
|
||||||
"# dest_path='./checkpoints.zip')\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
"!wget -P ./arcface_model https://github.com/neuralchen/SimSwap/releases/download/1.0/arcface_checkpoint.tar\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",
|
"!wget https://github.com/neuralchen/SimSwap/releases/download/1.0/checkpoints.zip\n",
|
||||||
@@ -278,7 +272,7 @@
|
|||||||
"### open url(can be found at [our repo]/doc/guidance/preparation.md) and copy the assigned download link here.\n",
|
"### 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",
|
"### 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",
|
"!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,
|
"execution_count": 6,
|
||||||
"outputs": [
|
"outputs": [
|
||||||
@@ -326,7 +320,6 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"import cv2\n",
|
"import cv2\n",
|
||||||
"import torch\n",
|
"import torch\n",
|
||||||
"import fractions\n",
|
|
||||||
"import numpy as np\n",
|
"import numpy as np\n",
|
||||||
"from PIL import Image\n",
|
"from PIL import Image\n",
|
||||||
"import torch.nn.functional as F\n",
|
"import torch.nn.functional as F\n",
|
||||||
@@ -334,8 +327,7 @@
|
|||||||
"from models.models import create_model\n",
|
"from models.models import create_model\n",
|
||||||
"from options.test_options import TestOptions\n",
|
"from options.test_options import TestOptions\n",
|
||||||
"from insightface_func.face_detect_crop_multi import Face_detect_crop\n",
|
"from insightface_func.face_detect_crop_multi import Face_detect_crop\n",
|
||||||
"from util.videoswap import video_swap\n",
|
"from util.videoswap import video_swap"
|
||||||
"from util.add_watermark import watermark_image"
|
|
||||||
],
|
],
|
||||||
"execution_count": 7,
|
"execution_count": 7,
|
||||||
"outputs": [
|
"outputs": [
|
||||||
@@ -352,6 +344,26 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"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",
|
||||||
|
" 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",
|
"cell_type": "code",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
@@ -360,7 +372,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"transformer = transforms.Compose([\n",
|
"transformer = transforms.Compose([\n",
|
||||||
" transforms.ToTensor(),\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",
|
||||||
"\n",
|
"\n",
|
||||||
"transformer_Arcface = transforms.Compose([\n",
|
"transformer_Arcface = transforms.Compose([\n",
|
||||||
@@ -388,10 +400,10 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"opt = TestOptions()\n",
|
"opt = TestOptions()\n",
|
||||||
"opt.initialize()\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 = opt.parse()\n",
|
||||||
"opt.pic_a_path = './demo_file/Iron_man.jpg' ## or replace it with image 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.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.output_path = './output/demo.mp4'\n",
|
||||||
"opt.temp_path = './tmp'\n",
|
"opt.temp_path = './tmp'\n",
|
||||||
"opt.Arc_path = './arcface_model/arcface_checkpoint.tar'\n",
|
"opt.Arc_path = './arcface_model/arcface_checkpoint.tar'\n",
|
||||||
@@ -405,7 +417,7 @@
|
|||||||
"model.eval()\n",
|
"model.eval()\n",
|
||||||
"\n",
|
"\n",
|
||||||
"app = Face_detect_crop(name='antelope', root='./insightface_func/models')\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",
|
"\n",
|
||||||
"with torch.no_grad():\n",
|
"with torch.no_grad():\n",
|
||||||
" pic_a = opt.pic_a_path\n",
|
" pic_a = opt.pic_a_path\n",
|
||||||
@@ -566,12 +578,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",
|
"cell_type": "code",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"id": "Rty2GsyZZrI6"
|
"id": "Rty2GsyZZrI6"
|
||||||
},
|
},
|
||||||
"source": [],
|
"source": [
|
||||||
|
"show_mp4(opt.output_path) # processed video"
|
||||||
|
],
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
"outputs": []
|
"outputs": []
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user