33from __future__ import division
44from __future__ import print_function
55
6- import os , json , time , sys , thread
6+ import os , json , time , sys , thread , base64
77import argparse
88import unicodedata
99import shutil
130130# run as worker only
131131CLUSTER_WORKERONLY = os .getenv ('CLUSTER_WORKERONLY' , False )
132132
133+ HAS_OPENCL = os .getenv ('HAS_OPENCL' , 'true' )
133134SAVE_ORIGINAL_FACE = False
134135original_face_img_path = os .path .join (BASEDIR , 'data' , 'original_face_img' )
135136if not os .path .exists (original_face_img_path ):
142143
143144counter = 0
144145
146+ if HAS_OPENCL == 'false' :
147+ from embedding_client import get_remote_embedding
148+
149+
145150def featureCalculation (imgpath ):
146151 img = misc .imread (os .path .expanduser (imgpath ))
147152 prewhitened = facenet .prewhiten (img )
@@ -1623,7 +1628,12 @@ def getQueueName():
16231628
16241629def featureCalculation2 (imgpath ):
16251630 embedding = None
1626- embedding = FaceProcessing .FaceProcessingImageData2 (imgpath )
1631+ if HAS_OPENCL == 'false' :
1632+ with open (imgpath , "rb" ) as image_file :
1633+ encoded_string = base64 .b64encode (image_file .read ())
1634+ embedding = get_remote_embedding (encoded_string )
1635+ else :
1636+ embedding = FaceProcessing .FaceProcessingImageData2 (imgpath )
16271637 return embedding
16281638
16291639@worker_process_init .connect ()
@@ -1638,11 +1648,11 @@ def setup(sender=None, **kwargs):
16381648 check_groupid_changed ()
16391649 init_fs ()
16401650
1641-
1642- mod = FaceProcessing .init_embedding_processor ()
1643- print ("start to warm up" )
1644- embedding = featureCalculation2 (os .path .join (BASEDIR ,"image" ,"Mike_Alden_0001_tmp.png" ))
1645- print ("warmed up" )
1651+ if HAS_OPENCL == 'true' :
1652+ mod = FaceProcessing .init_embedding_processor ()
1653+ print ("start to warm up" )
1654+ embedding = featureCalculation2 (os .path .join (BASEDIR ,"image" ,"Mike_Alden_0001_tmp.png" ))
1655+ print ("warmed up" )
16461656 #if embedding is not None:
16471657 # print("worker embedding ready")
16481658
@@ -1672,7 +1682,10 @@ def extract_v2(image):
16721682
16731683 if current_groupid is None :
16741684 return json .dumps ({"embedding_path" :"" ,"error" :"please join group" })
1675- embedding = FaceProcessing .FaceProcessingBase64ImageData2 (imgstring )
1685+ if HAS_OPENCL == 'false' :
1686+ embedding = get_remote_embedding (imgstring )
1687+ else :
1688+ embedding = FaceProcessing .FaceProcessingBase64ImageData2 (imgstring )
16761689 embedding_path = ''
16771690 embedding_str = ''
16781691 if embedding is not None :
0 commit comments