InferencetrainingAI commited on
Commit
b222cbf
1 Parent(s): eaa5438

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +67 -58
README.md CHANGED
@@ -15,34 +15,39 @@ import torch
15
  # prompt: compare face embediggs
16
 
17
  ```
 
 
 
 
 
 
 
 
 
 
 
18
 
19
 
20
  class FaceRec:
21
  def __init__(self):
22
- self.foldername = '/home/emmanuel/Pictures/Webcam'
23
  self.files = []
 
24
  self.embeds = []
25
  self.diff = []
26
  self.ground_mathches = []
27
- self.sampling = None
28
-
29
-
30
-
31
- def folder(self, attempt=True, folder='/home/emmanuel/Pictures/Webcam'):
32
- if attempt:
33
- for file in os.listdir(folder):
34
- self.files.append(file)
35
-
36
- self.image_pair = list(zip(self.files[0:len(self.files)//2], self.files[len(self.files)//2:]))
37
- print(self.image_pair)
38
 
39
 
40
- else:
41
- self.foldername = '/home/emmanuel/Pictures/webcam'
42
- self.files = []
43
- self.folder(attempt=True, folder=self.foldername)
44
-
45
-
46
 
47
 
48
  def embeddings(self, image):
@@ -64,67 +69,71 @@ class FaceRec:
64
 
65
 
66
 
67
- def closeness(self):
68
- self.embeds = []
69
- for faces in self.image_pair:
70
- self.embeds.append(self.face_embed(self.foldername+'/'+faces[0], self.foldername+'/'+faces[1]))
71
-
72
- return(0)
73
 
74
 
75
- def compare(self, attempt=True):
76
- self.diff = []
77
- for diffs in list(zip(self.embeds[0:len(self.embeds)//2], self.embeds[len(self.embeds)//2:])):
78
- self.diff.append(torch.nn.functional.pairwise_distance(diffs[0], diffs[1]))
79
 
80
 
81
 
82
-
83
- def expectation(self):
84
- mean, std = torch.mean(torch.Tensor(self.diff[0:])), torch.std(torch.Tensor(self.diff[0:]))
85
- distribute = torch.distributions.Normal(mean, std)
86
- self.sampling = distribute.sample(sample_shape=(10,))
87
 
 
 
 
 
 
88
 
 
 
89
 
90
- def model(self):
91
- self.closeness()
92
- return(self.compare())
93
 
94
 
 
 
 
 
 
 
 
 
95
 
96
- def verify(self):
97
- self.folder()
98
- self.model()
99
- self.expectation()
100
- self.folder(attempt=False)
101
- self.model()
102
 
103
- fails = 0
104
- success = 0
105
- max_itter = 10
106
- while max_itter >= 0:
107
- for samples in self.sampling:
108
- if self.diff[0] <= samples:
109
- success = success+1
110
-
111
- else:
112
- fails = fails+1
113
 
114
- max_itter = max_itter-1
 
115
 
116
 
117
- if fails > success:
118
- return(False)
 
 
 
 
 
 
 
 
 
 
 
 
 
119
 
120
  else:
121
- return(True)
122
 
123
 
124
-
125
 
126
 
127
 
128
  Recognition = FaceRec()
129
- print(Recognition.verify())
 
 
130
  ```
 
15
  # prompt: compare face embediggs
16
 
17
  ```
18
+ import os
19
+ import cv2
20
+ from insightface.app import FaceAnalysis
21
+ import torch
22
+
23
+ import torch.nn.functional as F
24
+
25
+
26
+ # prompt: compare face embediggs
27
+
28
+
29
 
30
 
31
  class FaceRec:
32
  def __init__(self):
33
+ self.foldername = '/home/emmanuel-nsanga/Pictures/Webcam'
34
  self.files = []
35
+ self.files_attempt = []
36
  self.embeds = []
37
  self.diff = []
38
  self.ground_mathches = []
39
+ self.sample_true = []
40
+ self.sample_attemt = []
41
+ self.folder_attempt='/home/emmanuel-nsanga/Pictures/Webcam/'
42
+ self.folder_ground = '/home/emmanuel-nsanga/Pictures/webcam/'
43
+ self.folder_camera = '/home/emmanuel-nsanga/Pictures/camera/'
44
+ self.files_ground = [self.folder_ground+files for files in os.listdir(self.folder_ground)]
45
+ self.files_attempt = [self.folder_attempt+files for files in os.listdir(self.folder_attempt)]
46
+ self.files_camera = [self.folder_camera+files for files in os.listdir(self.folder_camera)]
47
+ self.zip_ground = list(zip(self.files_ground, self.files_attempt))
48
+ self.zip_attempt = list(zip(self.files_attempt, self.files_camera))
 
49
 
50
 
 
 
 
 
 
 
51
 
52
 
53
  def embeddings(self, image):
 
69
 
70
 
71
 
72
+
 
 
 
 
 
73
 
74
 
75
+ def expectation(self, sample_data):
76
+ mean, std = torch.mean(sample_data), torch.std(sample_data)
77
+ distribute = torch.distributions.Normal(mean, std)
78
+ return(distribute.sample(sample_shape=(10,)))
79
 
80
 
81
 
 
 
 
 
 
82
 
83
+ def sim_distribution(self):
84
+ attempt_embeddings = self.zip_ground[0::]
85
+ ground_embeddings = self.zip_attempt[len(self.zip_ground)::]
86
+
87
+
88
 
89
+ w_r_t_g = self.zip_ground[0::]
90
+ w_r_t_c = self.zip_attempt
91
 
92
+ w_r_t_g = self.zip_ground[0::len(self.zip_ground)//2]
93
+ w_r_t_tr = self.zip_ground[len(self.zip_ground)//2::]
 
94
 
95
 
96
+
97
+
98
+ ground_embeddings = [self.face_embed(attempting, attempt) for attempting, attempt in w_r_t_g]
99
+ attempt_ground = [self.face_embed(attempting, attempt) for attempting, attempt in w_r_t_tr]
100
+
101
+
102
+ ground_embeddings_g = [self.face_embed(attempting, attempt) for attempting, attempt in w_r_t_g]
103
+ attempt_ground_c = [self.face_embed(attempting, attempt) for attempting, attempt in w_r_t_c]
104
 
 
 
 
 
 
 
105
 
 
 
 
 
 
 
 
 
 
 
106
 
107
+ self.sampling_ground = self.expectation(torch.Tensor(ground_embeddings))
108
+ self.sampling_attempt_g = self.expectation(torch.Tensor(attempt_ground))
109
 
110
 
111
+ self.sampling_ground = self.expectation(torch.Tensor(ground_embeddings_g))
112
+ self.sampling_attempt_c = self.expectation(torch.Tensor(attempt_ground_c))
113
+
114
+ return(self.sampling_ground, self.sampling_attempt_g, self.sampling_ground, self.sampling_attempt_c)
115
+
116
+
117
+
118
+ def model(self):
119
+ sim_distribution = self.sim_distribution()
120
+ xy = torch.mean(torch.Tensor([x-y for x, y in zip(sim_distribution[2], sim_distribution[3])]))
121
+ print(xy.item())
122
+
123
+ if xy.item() < 0.5:
124
+ print(True)
125
+
126
 
127
  else:
128
+ print(False)
129
 
130
 
131
+
132
 
133
 
134
 
135
  Recognition = FaceRec()
136
+ print(Recognition.model())
137
+
138
+
139
  ```