-
Notifications
You must be signed in to change notification settings - Fork 1
/
predictKeyPoints.py
60 lines (50 loc) · 1.46 KB
/
predictKeyPoints.py
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
import os,sys
#print(sys.path)
sys.path.append('..')
#print(sys.path)
import tensorflow.keras as ks
import datetime
import argparse
from commonModule.ImageBase import *
from genLabel import writeAnotationFile
def argCmdParse():
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--source', help = 'source image')
parser.add_argument('-d', '--dst', help = 'save iamge')
return parser.parse_args()
def preditImg(img, modelName = r'./weights/trainFacialRecognition.h5'): # #r'./weightLoc/trainFacialRecognition.h5'
model = ks.models.load_model(modelName)
print(img.shape)
if getImagChannel(img) == 3:
x = img[:,:,0]
else:
x = img
print(x.shape)
x = x.reshape((1,x.shape[0],x.shape[1],1))
print(x.shape)
pts = model.predict(x)
pts = pts.reshape((68,2))
print('preditImg pts.shape=',type(pts),pts.shape)
return pts
def main():
arg = argCmdParse()
file=arg.source #r'./res/myface_gray.png'
dstFile = arg.dst
print(file,dstFile)
img = loadImg(file)
pts = preditImg(img)
'''
print(img.shape)
x = img[:,:,0]
print(x.shape)
x = x.reshape((1,x.shape[0],x.shape[1],1))
print(x.shape)
#return
pts = model.predict(x)
'''
print('pts=',len(pts),pts.shape,pts)
pts = pts.reshape((68,2))
print('pts=',len(pts),pts.shape,pts)
writeAnotationFile(dstFile,pts) #'./res/myface_gray.pts'
if __name__=='__main__':
main()