AshanGimhana commited on
Commit
a27171b
·
verified ·
1 Parent(s): 7310187

Update notebook.txt

Browse files
Files changed (1) hide show
  1. notebook.txt +65 -1
notebook.txt CHANGED
@@ -13,4 +13,68 @@ from huggingface_hub import hf_hub_download
13
  repo_id = "AshanGimhana/NewFWModelV1"
14
  model_filename = "inswapperFTV1Model.onnx"
15
 
16
- --------------------------------------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  repo_id = "AshanGimhana/NewFWModelV1"
14
  model_filename = "inswapperFTV1Model.onnx"
15
 
16
+ --------------------------------------------------
17
+
18
+
19
+ model_path = hf_hub_download(repo_id=repo_id, filename=model_filename)
20
+
21
+ ----------------------------------------------------------------------------
22
+
23
+
24
+ model = "copy path and paste"
25
+
26
+ ----------------------------------------------------------------------------
27
+
28
+ from matplotlib import pyplot as plt
29
+ import cv2
30
+ import insightface
31
+ import numpy as np
32
+ -----------------------------------------------------------------------------
33
+
34
+ providers = ["CPUExecutionProvider"]
35
+ -----------------------------------------------------------------------------
36
+
37
+ target_frame = cv2.imread('Enter reference image path')
38
+ src_frame = cv2.imread("Enter user image path")
39
+ fig = plt.figure()
40
+ ax1 = fig.add_subplot(1,2,1)
41
+ ax1.imshow(cv2.cvtColor(src_frame, cv2.COLOR_BGR2RGB))
42
+ ax2 = fig.add_subplot(1,2,2)
43
+ ax2.imshow(cv2.cvtColor(target_frame, cv2.COLOR_BGR2RGB))
44
+ plt.show()
45
+ ------------------------------------------------------------------------------
46
+
47
+ FACE_ANALYSER = insightface.app.FaceAnalysis(
48
+ name="buffalo_l",
49
+ root=".", providers=providers,allowed_modules=["landmark_3d_68", "landmark_2d_106","detection","recognition"]
50
+ )
51
+ FACE_ANALYSER.prepare(
52
+ ctx_id=0,
53
+ det_size=(640, 640),
54
+ )
55
+ ----------------------------------------------------------------------------------------------------------------------------------------
56
+
57
+ src_faces = FACE_ANALYSER.get(src_frame)
58
+ target_faces = FACE_ANALYSER.get(target_frame)
59
+ fig = plt.figure()
60
+ ax1 = fig.add_subplot(1,2,1)
61
+ rimg = FACE_ANALYSER.draw_on(src_frame,src_faces)
62
+ ax1.imshow(cv2.cvtColor(rimg, cv2.COLOR_BGR2RGB))
63
+ ax1 = fig.add_subplot(1,2,2)
64
+ rimg = FACE_ANALYSER.draw_on(target_frame,target_faces)
65
+ ax1.imshow(cv2.cvtColor(rimg, cv2.COLOR_BGR2RGB))
66
+ plt.show()
67
+
68
+ ----------------------------------------------------------------------------------------------------------------------------------------
69
+
70
+ model_swap_insightface = insightface.model_zoo.get_model(model, providers=providers)
71
+
72
+ ----------------------------------------------------------------------------------------------------
73
+
74
+ 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)
75
+
76
+ -------------------------------------------------------------------------------------------------------------------------------------------------------
77
+
78
+ plt.imshow(cv2.cvtColor(img_fake, cv2.COLOR_BGR2RGB))
79
+
80
+ ------------------------------------------------------------------------