-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvggSKILClientMultiFacesApp.py
More file actions
764 lines (479 loc) · 24 KB
/
vggSKILClientMultiFacesApp.py
File metadata and controls
764 lines (479 loc) · 24 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
from keras.models import model_from_json, Sequential, Model
from keras.layers import Input, Convolution2D, ZeroPadding2D, MaxPooling2D, Flatten, Dense, Dropout, Activation
from keras.preprocessing.image import load_img, img_to_array, save_img
from keras.applications.imagenet_utils import preprocess_input
from numpy.testing import assert_allclose
import shutil
import pandas as pd
import numpy as np
import os
from os import listdir
from os.path import isfile, join
import dlib
import cv2
import requests
import json
from numpy import ndarray
import urllib.request
import time
import sys
import uuid
#documentation
#where to put the face image
#how to capture input image
#flip the image for front camera
#system configuration
#histEqualize
#use this as template for documentation
#get images of daily life. more emotions
#faces looking down is better
#install dlib
#
class VGGClientApp:
similarityMinValue = 0.85
imgRows = 224
imgCols = 224
channels = 3
nameList = [] #name list
nameEmbedding = dict() #name and the list of embeddings
SKILServerPassword = "admin123"
padHeight = 50
padwidth = 20
camera = 0 #default camera use 0
inputImageHeight = -1
inputImageWidth = -1
embeddingURL = 'http://localhost:9008/endpoints/vgg/model/vggmodel/v1/predict'#"http://localhost:9008//endpoints//vgg//model//vggFace//default//multipredict"
kerasModelPath = "resources\\vgg_face_weights.h5"
imageDbPath = "resources\\facesDataset\\"
embeddingDbPath = "resources\\facesEmbedding\\"
predictor_path = "resources\\shape_predictor_68_face_landmarks.dat"
faceFontType = cv2.FONT_HERSHEY_SIMPLEX
faceFontScale = 0.8
faceFontColor = (255,0,0)
faceRectColor = (0, 255, 0)
faceRectThickness = 2
def __init__(self, createDataBase = False):
#get Face Detector
self.detector = dlib.get_frontal_face_detector()
#get FaceRecognizer local, to generate embeddings for database faces
#when createDataBase set to True
self.initDescriptor()
#to get upright face for better embedding generation
self.landmark_predictor = dlib.shape_predictor(self.predictor_path)
#get Minimum Face Width for Face Verification
self.minimumFaceWidth = 50 #int(self.imgCols / 4)
self.initCamera()
if createDataBase == True:
#align each face from database, and save it
self.createDatabase()
else:
self.loadDatabase()
#get endpoint token
self.getToken()
def saveFaceForDatabase(self, mainPath):
name = ""
while True:
name = input("What name is this new person>")
name = name.lower() #lower case a string
if(len(name) > 0):
break
pathToSave = mainPath + name
files = os.listdir(self.imageDbPath)
if name in files:
pass
else:
os.mkdir(pathToSave)
if(self.cap.isOpened() == False):
self.cap = VideoCapture(self.camera)
count = 0
maxFacesCapture = 30
while(True):
# Capture frame-by-fram
ret, frame = self.cap.read()
frame = cv2.flip(frame, 1)
# 4. Pass de loaded image to the `detector`
dets = self.detector(frame, 0)
# Display the resulting frame
faces = dlib.full_object_detections()
for detection in dets:
# Find the 5 face landmarks we need to do the alignment.
faces.append(self.landmark_predictor(frame, detection))
if (len(dets) > 0):
faces_aligned = dlib.get_face_chips(frame, faces, size = self.imgCols)
rectList = self.getFacesRectangleList(dets)
faceRecogIndex = self.getBiggestFaceIndex(dets)
if faceRecogIndex != -1:
savePath = pathToSave + "\\" + str(uuid.uuid4()) + ".jpg"
det = rectList[faceRecogIndex]
#[top, bottom, topleft, right] to [topleft, top, right, bottom]
cv2.rectangle(frame, (det[2], det[0]), (det[3], det[1]), self.faceRectColor, self.faceRectThickness)
cv2.putText(frame, "Collect Face: %d left" % (maxFacesCapture - count), (10, 85), self.faceFontType, 0.95, (255, 0, 0))
cv2.imshow("Saving Image For Database", frame)
cv2.imwrite(savePath, faces_aligned[faceRecogIndex])
count += 1
if(count > maxFacesCapture):
break
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()
#load all the embeddings of different faces in the rootPath
#the directory can only contain subdirs. each of a particular person
def createDatabase(self):
print("Create embedding database ...")
while True:
choice = input("Do you want to captures faces for database [Y/N]>")
if (choice == 'y') |(choice == 'Y') :
databasePath = self.imageDbPath
self.saveFaceForDatabase(self.imageDbPath)
break
else:
break
try:
shutil.rmtree(self.embeddingDbPath)
except:
print('Error while deleting directory {}'.format(self.embeddingDbPath))
#create embedding path if not there
if(os.path.exists(self.embeddingDbPath) == False):
endIndex = int(len(self.embeddingDbPath) - 1)
embeddingFolder = self.embeddingDbPath[0:endIndex]
os.mkdir(embeddingFolder)
print("Directory " + embeddingFolder + " created")
subDirs = [x[0] for x in os.walk(self.imageDbPath)]
subDirs.remove(self.imageDbPath) #remove own path
#create embedding path if not there
if(os.path.exists(self.embeddingDbPath) == False):
os.mkdir(self.embeddingDbPath)
print("Directory " + self.embeddingDbPath + " created")
for person in subDirs:
imagePath = [x[0] for x in os.walk(person)][0]
#get name which the the title of the folder
name = imagePath.split("\\")[-1]
self.nameList.append(name)
self.nameEmbedding[name] = []
print("Name: " + name)
onlyfiles = [f for f in listdir(imagePath) if isfile(join(imagePath, f))]
for image in onlyfiles:
imageFullPath = imagePath + "\\" + image
arr = self.createEmbeddingForDatabase(imageFullPath)
if len(arr) != 0:
self.nameEmbedding[name].append(arr)
df = pd.DataFrame(self.nameEmbedding[name])
savePath = self.embeddingDbPath + name + ".txt"
np.savetxt(savePath, self.nameEmbedding[name])
def loadDatabase(self):
print("Load embedding database")
self.nameList = []
for file in os.listdir(self.embeddingDbPath):
if file.endswith(".txt"):
df_restored = np.loadtxt(os.path.join(self.embeddingDbPath, file))
name = file[0:len(file) - 4]
self.nameList.append(name)
self.nameEmbedding[name] = df_restored
def createEmbeddingForDatabase(self, imagePath):
img = cv2.imread(imagePath, 1)
#img = self.colorEqualizeHist(img)
#grayImg = load_img(imagePath, grayscale = True, target_size = (self.imgRows, self.imgCols))
dets = self.detector(img, 0) #img_to_array(img) second argument is for upscaling to detect smaller faces 0 for no upscaling
# Display the resulting frame
faces = dlib.full_object_detections()
for detection in dets:
# Find the 5 face landmarks we need to do the alignment.
faces.append(self.landmark_predictor(img, detection))
if(len(faces) == 1):
face_aligned = dlib.get_face_chips(img, faces, size = self.imgRows)
#cv2.imwrite('temp\\facecrop' + str(self.count) + ".jpg", face_aligned[0])
#self.count = self.count + 1
return self.getLocalMachineEmbedding(face_aligned[0])
else:
print("Skipped. No face found in this image.")
return []
def setInputImageSize(self, height, width):
self.inputImageHeight = height
self.inputImageWidth = width
def initCamera(self):
self.cap = cv2.VideoCapture(self.camera)
# get vcap property
width = self.cap.get(3) # float
height = self.cap.get(4) # float
self.setInputImageSize(height, width)
print("Image width: " + str(width))
print("Image height: " + str(height))
def getToken(self):
loginURL = "http://localhost:9008/login"#"http://localhost:9008/ui/#/login?returnUrl=%2Fworkspaces"
headers = {"Content-Type":"application/json","Accept":"application/json"}
payload = {
'sysparm_action': 'insert',
'short_description': 'test_jsonv2',
'priority': '1'
}
payload = {'userId': 'admin', 'password': self.SKILServerPassword}
response = requests.request("POST", loginURL, data=json.dumps(payload), headers = headers)
if response.status_code != 200:
raise Exception("Login to SKIL Server failed. Could not get token")
else:
loginJSON = response.json()
for key, value in loginJSON.items():
self.token = value
print("Token: " + self.token)
self.embeddingHeaders = {"Content-Type" : "application/json; charset=utf-8", "authorization" : "Bearer " + str(self.token)}
def colorEqualizeHist(self, colorImage):
img_yuv = cv2.cvtColor(colorImage, cv2.COLOR_BGR2YUV)
# equalize the histogram of the Y channel
img_yuv[:,:,0] = cv2.equalizeHist(img_yuv[:,:,0])
# convert the YUV image back to RGB format
return cv2.cvtColor(img_yuv, cv2.COLOR_YUV2BGR)
def getMax(self, dictList):
cosineMaxOutput = dict()
for name in self.nameList:
cosineMaxOutput[name] = max(dictList[name])
return cosineMaxOutput
def getTopAverage(self, dictList):
top = 3
cosineTopAverageOutput = dict()
for name in self.nameList:
if len(dictList[name]) > top:
dictList[name].sort(reverse = True)
sum = 0
for i in range(0, top):
sum = sum + dictList[name][i]
cosineTopAverageOutput[name] = sum / top
else:
print("database for particular person fewer than %d image" % top)
cosineTopAverageOutput[name] = self.getMax(dictList)
return cosineTopAverageOutput
def getLocalMachineEmbedding(self, faceImage):
modelInput = self.preprocess_image(faceImage)
embedding = self.vgg_face_descriptor.predict(modelInput)[0,:]
return embedding
def preprocess_image(self, image):
#img = load_img(imagePath, target_size = (self.imgRows, self.imgCols))
img = img_to_array(image)
img = np.expand_dims(img, axis = 0) # add one more []
#model accept batch size, this make single image ready to input into model
img = preprocess_input(img)
return img
def getSingleFaceForEndpoint(self, currentFaceImage):
# Expected input shape is height,width,channels,batch size
# DL4j: input shape is batch size, channels, height, width
# permute/transpose order is: 3,2,1,0 for inputs
# permute/transpose order output: 3,2,1,0
#currentFaceImage = load_img(currentFaceImage, target_size = (self.imgRows, self.imgCols))
currentFaceImage_ = img_to_array(currentFaceImage)
currentFaceImage_ = np.expand_dims(currentFaceImage_, axis = 0) # add one more []
currentFaceImage_ = preprocess_input(currentFaceImage_)
currentFaceImage_ = np.array(currentFaceImage_)
currentFaceImage_ = currentFaceImage_.ravel().tolist()
imgEndpointInput = np.array(currentFaceImage_)
imgEndpointInput = imgEndpointInput.reshape(1, self.imgRows, self.imgCols, self.channels)
imgEndpointInput = np.transpose(imgEndpointInput, (0, 3, 1, 2))
imgEndpointInput = list(imgEndpointInput.flatten())
return imgEndpointInput
def getEndpointEmbedding(self, faceInputVector):
prediction_json = {"ordering":"c","shape":(1, self.channels, self.imgRows, self.imgCols), "data": faceInputVector}
payload = {"needsPreProcessing":"false","id":"25baeee4-2736-4135-8dfd-0ec168bd1976","prediction": prediction_json}
response = requests.request("POST", self.embeddingURL, data = json.dumps(payload), headers = self.embeddingHeaders)
if response.status_code != 200:
print('Status:', response.status_code, 'Headers:', response.headers, 'Error Response:',response.json())
print(response.content)
print(response.text)
return []
else:
#print('response success')
#print(response.status_code)
json_result = response.json()
response_data = json_result['prediction']
embeddings = response_data['data']
return embeddings
def getMatchFace(self, singleFaceEmbedding):
cosineNameDict = dict()
for name in self.nameList:
cosineNameDict[name] = []
embeddingList = self.nameEmbedding[name]
for dbEmbedding in embeddingList:
cosineValue = self.getCosineSimilarity(dbEmbedding, singleFaceEmbedding)
cosineNameDict[name].append(cosineValue)
if(cosineValue > 0) & (cosineValue < 1):
cosineNameDict[name].append(cosineValue)
else:
cosineNameDict[name].append(0)
currentOutput = self.getTopAverage(cosineNameDict) #self.getTopAverage(cosineNameDict)
return currentOutput
def getBiggestFaceIndex(self, detection):
biggestFaceIndex = -1 #FACE TOO SMALL FOR FACE RECOGNITION
biggestFaceArea = self.minimumFaceWidth
currentIndex = 0
for det in detection:
#row and column similar. Chose column as the standard of comparison
currentFaceWidth = det.bottom() - det.top()
if(currentFaceWidth > biggestFaceArea):
biggestFaceArea = currentFaceWidth
biggestFaceIndex = currentIndex
currentIndex = currentIndex + 1
return biggestFaceIndex
def getFacesRectangleList(self, facesDect):
facesRectangle = []
for faceDect in facesDect:
#print("Detection {}: Left: {} Top: {} Right: {} Bottom: {}".format(i, d.left(), d.top(), d.right(), d.bottom()))
topleft = 0
top = 0
bottom = faceDect.bottom()
right = 0#int(width)
if(faceDect.left() - self.padwidth) > 0:
topleft = faceDect.left() - self.padwidth
if(faceDect.right() + self.padwidth) < self.inputImageWidth:
right = faceDect.right() + self.padwidth
if(faceDect.top() - self.padHeight) > 0:
top = faceDect.top() - self.padHeight
faceRectangle = [top, bottom, topleft, right]
facesRectangle.append(faceRectangle)
return facesRectangle
def runLocalFaceRecognition(self):
if(self.cap.isOpened() == False):
self.cap = VideoCapture(self.camera)
while(True):
# Capture frame-by-fram
ret, frame = self.cap.read()
frame = cv2.flip(frame, 1)
# 4. Pass de loaded image to the `detector`
dets = self.detector(frame, 0)
# Display the resulting frame
faces = dlib.full_object_detections()
for detection in dets:
# Find the 5 face landmarks we need to do the alignment.
faces.append(self.landmark_predictor(frame, detection))
if (len(dets) > 0):
faces_aligned = dlib.get_face_chips(frame, faces, size = self.imgCols)
rectList = self.getFacesRectangleList(dets)
for i, face in enumerate(faces_aligned):
#endpoint
singleFaceEmbedding = self.getLocalMachineEmbedding(face)
dictOutput = self.getMatchFace(singleFaceEmbedding)
outputNameList = list(dictOutput.keys())
outputNameSimilarity = list(dictOutput.values())
maxValue = max(outputNameSimilarity)
maxIndex = outputNameSimilarity.index(max(outputNameSimilarity))
if self.checkFaceConfident({outputNameList[maxIndex]: maxValue}):
cv2.putText(frame, "%s %.2f" % (outputNameList[maxIndex], dictOutput[outputNameList[maxIndex]] * 100), (rectList[i][3], rectList[i][0] ), self.faceFontType, self.faceFontScale, self.faceFontColor)#(right, top + padY), font, fontScale, fontColor)
#print all probabilities
'''
dictOutput = self.getMatchFace(singleFaceEmbedding)
padY = 0
for name in dictOutput.keys():
cv2.putText(frame, "%s %.2f" % (name, dictOutput[name]), (rectList[i][3], rectList[i][0] + padY), self.faceFontType, self.faceFontScale, self.faceFontColor)#(right, top + padY), font, fontScale, fontColor)
padY += 20
'''
for det in rectList:
#[top, bottom, topleft, right] to [topleft, top, right, bottom]
cv2.rectangle(frame, (det[2], det[0]), (det[3], det[1]), self.faceRectColor, self.faceRectThickness)
cv2.imshow('Endpoint Face Verification', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
self.cap.release()
cv2.destroyAllWindows()
def runEndpointFaceRecognition(self):
if(self.cap.isOpened() == False):
self.cap = VideoCapture(self.camera)
while(True):
# Capture frame-by-fram
ret, frame = self.cap.read()
frame = cv2.flip(frame, 1)
# 4. Pass de loaded image to the `detector`
dets = self.detector(frame, 0)
# Display the resulting frame
faces = dlib.full_object_detections()
for detection in dets:
# Find the 5 face landmarks we need to do the alignment.
faces.append(self.landmark_predictor(frame, detection))
if (len(dets) > 0):
faces_aligned = dlib.get_face_chips(frame, faces, size = self.imgCols)
rectList = self.getFacesRectangleList(dets)
for i, face in enumerate(faces_aligned):
#endpoint
singleFaceEmbedding = self.getEndpointEmbedding(self.getSingleFaceForEndpoint(face))
dictOutput = self.getMatchFace(singleFaceEmbedding)
outputNameList = list(dictOutput.keys())
outputNameSimilarity = list(dictOutput.values())
maxValue = max(outputNameSimilarity)
maxIndex = int(outputNameSimilarity.index(maxValue))
if self.checkFaceConfident({outputNameList[maxIndex]: maxValue}):
cv2.putText(frame, "%s %.2f" % (outputNameList[maxIndex], outputNameSimilarity[maxIndex] * 100), (rectList[i][3], rectList[i][0]), self.faceFontType, self.faceFontScale, self.faceFontColor)#(right, top + padY), font, fontScale, fontColor)
#print all probabilities
'''
dictOutput = self.getMatchFace(singleFaceEmbedding)
padY = 0
for name in dictOutput.keys():
cv2.putText(frame, "%s %.2f" % (name, dictOutput[name]), (rectList[i][3], rectList[i][0] + padY), self.faceFontType, self.faceFontScale, self.faceFontColor)#(right, top + padY), font, fontScale, fontColor)
padY += 20
'''
for det in rectList:
#[top, bottom, topleft, right] to [topleft, top, right, bottom]
cv2.rectangle(frame, (det[2], det[0]), (det[3], det[1]), self.faceRectColor, self.faceRectThickness)
cv2.imshow('Endpoint Face Verification', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
self.cap.release()
cv2.destroyAllWindows()
def checkFaceConfident(self, dictNameSimilarity):
for name, similarityValue in dictNameSimilarity.items(): # assume length = 1
if(similarityValue > self.similarityMinValue):
return True
else:
return False
def initDescriptor(self):
self.model = Sequential()
self.model.add(ZeroPadding2D((1,1), input_shape=(self.imgRows, self.imgCols, self.channels)))
self.model.add(Convolution2D(64, (3, 3), activation='relu'))
self.model.add(ZeroPadding2D((1,1)))
self.model.add(Convolution2D(64, (3, 3), activation='relu'))
self.model.add(MaxPooling2D((2,2), strides=(2,2)))
self.model.add(ZeroPadding2D((1,1)))
self.model.add(Convolution2D(128, (3, 3), activation='relu'))
self.model.add(ZeroPadding2D((1,1)))
self.model.add(Convolution2D(128, (3, 3), activation='relu'))
self.model.add(MaxPooling2D((2,2), strides=(2,2)))
self.model.add(ZeroPadding2D((1,1)))
self.model.add(Convolution2D(256, (3, 3), activation='relu'))
self.model.add(ZeroPadding2D((1,1)))
self.model.add(Convolution2D(256, (3, 3), activation='relu'))
self.model.add(ZeroPadding2D((1,1)))
self.model.add(Convolution2D(256, (3, 3), activation='relu'))
self.model.add(MaxPooling2D((2,2), strides=(2,2)))
self.model.add(ZeroPadding2D((1,1)))
self.model.add(Convolution2D(512, (3, 3), activation='relu'))
self.model.add(ZeroPadding2D((1,1)))
self.model.add(Convolution2D(512, (3, 3), activation='relu'))
self.model.add(ZeroPadding2D((1,1)))
self.model.add(Convolution2D(512, (3, 3), activation='relu'))
self.model.add(MaxPooling2D((2,2), strides=(2,2)))
self.model.add(ZeroPadding2D((1,1)))
self.model.add(Convolution2D(512, (3, 3), activation='relu'))
self.model.add(ZeroPadding2D((1,1)))
self.model.add(Convolution2D(512, (3, 3), activation='relu'))
self.model.add(ZeroPadding2D((1,1)))
self.model.add(Convolution2D(512, (3, 3), activation='relu'))
self.model.add(MaxPooling2D((2,2), strides=(2,2)))
self.model.add(Convolution2D(4096, (7, 7), activation='relu'))
self.model.add(Dropout(0.5))
self.model.add(Convolution2D(4096, (1, 1), activation='relu'))
self.model.add(Dropout(0.5))
self.model.add(Convolution2D(2622, (1, 1)))
self.model.add(Flatten())
self.model.add(Activation('softmax'))
self.model.load_weights(self.kerasModelPath)
self.vgg_face_descriptor = Model(inputs = self.model.layers[0].input, outputs = self.model.layers[-2].output)
#self.vgg_face_descriptor.save('model.h5')
#value ranging from -1 to 1 . -1 as totally ot similar to 1 as totally similar
def getCosineSimilarity(self, source, target):
a = np.matmul(np.transpose(source), target)
b = np.sum(np.multiply(source, source))
c = np.sum(np.multiply(target, target))
return (a / (np.sqrt(b) * np.sqrt(c)))
if __name__ == '__main__':
faceClientApp = VGGClientApp(createDataBase = False)
print("run Face Recognition Endpoint")
#faceClientApp.runEndpointFaceRecognition()
faceClientApp.runLocalFaceRecognition()
print('End of program...')
#