File size: 2,879 Bytes
19de3b0 7310187 dfff1cc 7310187 a27171b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | !pip install insightface
-------------------------------
from huggingface_hub import loggin
loggin(token="")
-----------------------------------------------
from huggingface_hub import hf_hub_download
repo_id = "AshanGimhana/NewFWModelV1"
model_filename = "inswapperFTV1Model.onnx"
--------------------------------------------------
model_path = hf_hub_download(repo_id=repo_id, filename=model_filename)
----------------------------------------------------------------------------
model = "copy path and paste"
----------------------------------------------------------------------------
from matplotlib import pyplot as plt
import cv2
import insightface
import numpy as np
-----------------------------------------------------------------------------
providers = ["CPUExecutionProvider"]
-----------------------------------------------------------------------------
target_frame = cv2.imread('Enter reference image path')
src_frame = cv2.imread("Enter user image path")
fig = plt.figure()
ax1 = fig.add_subplot(1,2,1)
ax1.imshow(cv2.cvtColor(src_frame, cv2.COLOR_BGR2RGB))
ax2 = fig.add_subplot(1,2,2)
ax2.imshow(cv2.cvtColor(target_frame, cv2.COLOR_BGR2RGB))
plt.show()
------------------------------------------------------------------------------
FACE_ANALYSER = insightface.app.FaceAnalysis(
name="buffalo_l",
root=".", providers=providers,allowed_modules=["landmark_3d_68", "landmark_2d_106","detection","recognition"]
)
FACE_ANALYSER.prepare(
ctx_id=0,
det_size=(640, 640),
)
----------------------------------------------------------------------------------------------------------------------------------------
src_faces = FACE_ANALYSER.get(src_frame)
target_faces = FACE_ANALYSER.get(target_frame)
fig = plt.figure()
ax1 = fig.add_subplot(1,2,1)
rimg = FACE_ANALYSER.draw_on(src_frame,src_faces)
ax1.imshow(cv2.cvtColor(rimg, cv2.COLOR_BGR2RGB))
ax1 = fig.add_subplot(1,2,2)
rimg = FACE_ANALYSER.draw_on(target_frame,target_faces)
ax1.imshow(cv2.cvtColor(rimg, cv2.COLOR_BGR2RGB))
plt.show()
----------------------------------------------------------------------------------------------------------------------------------------
model_swap_insightface = insightface.model_zoo.get_model(model, providers=providers)
----------------------------------------------------------------------------------------------------
img_fake = model_swap_insightface.get(img = target_frame, target_face=FACE_ANALYSER.get(target_frame)[0], source_face=src_faces[0], paste_back=True)
-------------------------------------------------------------------------------------------------------------------------------------------------------
plt.imshow(cv2.cvtColor(img_fake, cv2.COLOR_BGR2RGB))
------------------------------------------------------------------------ |