Skip to content

Commit f41491c

Browse files
committed
To use on devices w/o opencl support.
1 parent aebf5fa commit f41491c

3 files changed

Lines changed: 44 additions & 5 deletions

File tree

src/embedding/FaceProcessing.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from scipy.misc import imread, imresize
2323
import sklearn.preprocessing
2424

25+
global mx
2526
global globGraph
2627
globGraph = None
2728
global mod
@@ -32,6 +33,7 @@
3233
DEBUG = False
3334

3435
DATA_RUNTIME_FOLDER = os.getenv('DATA_RUNTIME_FOLDER', '/data/runtime')
36+
HAS_OPENCL = os.getenv('HAS_OPENCL', 'true')
3537

3638
def load_graph(frozen_graph_filename):
3739
return None
@@ -108,6 +110,25 @@ def get_model(ctx, image_size, model_str, layer):
108110
def init_embedding_processor():
109111
global mod2
110112
global mod3
113+
114+
if HAS_OPENCL == 'false':
115+
global mx
116+
import mxnet as mx
117+
print('need init mxnet')
118+
119+
mod2 = None
120+
if os.path.isfile(DATA_RUNTIME_FOLDER+'/model-0000.params'):
121+
ctx = mx.cpu(0)
122+
mod3 = get_model(ctx, [112,112], DATA_RUNTIME_FOLDER+'/model,0', 'fc1')
123+
print('backup model loaded')
124+
return mod3
125+
126+
mod = FaceProcessing.init_embedding_processor()
127+
print("start to warm up")
128+
embedding = featureCalculation2(os.path.join(BASEDIR,"image","Mike_Alden_0001_tmp.png"))
129+
print("warmed up")
130+
return mod3
131+
111132
if os.path.isfile(DATA_RUNTIME_FOLDER+'/net2'):
112133
global __t
113134
global graph_runtime

src/embedding/upload_api-v2.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
# run as worker only
131131
CLUSTER_WORKERONLY = os.getenv('CLUSTER_WORKERONLY', False)
132132

133+
HAS_OPENCL = os.getenv('HAS_OPENCL', 'true')
133134
SAVE_ORIGINAL_FACE = False
134135
original_face_img_path = os.path.join(BASEDIR, 'data', 'original_face_img')
135136
if not os.path.exists(original_face_img_path):
@@ -142,6 +143,14 @@
142143

143144
counter = 0
144145

146+
if HAS_OPENCL == 'false':
147+
print('need init mxnet')
148+
mod = FaceProcessing.init_embedding_processor()
149+
print("start to warm up")
150+
embedding = FaceProcessing.FaceProcessingImageData2(os.path.join(BASEDIR,"image","Mike_Alden_0001_tmp.png"))
151+
print("warmed up")
152+
153+
145154
def featureCalculation(imgpath):
146155
img = misc.imread(os.path.expanduser(imgpath))
147156
prewhitened = facenet.prewhiten(img)
@@ -1638,11 +1647,11 @@ def setup(sender=None, **kwargs):
16381647
check_groupid_changed()
16391648
init_fs()
16401649

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")
1650+
if HAS_OPENCL == 'true':
1651+
mod = FaceProcessing.init_embedding_processor()
1652+
print("start to warm up")
1653+
embedding = featureCalculation2(os.path.join(BASEDIR,"image","Mike_Alden_0001_tmp.png"))
1654+
print("warmed up")
16461655
#if embedding is not None:
16471656
# print("worker embedding ready")
16481657

start_service.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
#!/bin/bash
22
source ./env/common.sh
33

4+
if [ -f /system/vendor/lib64/libOpenCL.so ]
5+
then
6+
export HAS_OPENCL=1
7+
echo 'has opencl supporting'
8+
else
9+
export HAS_OPENCL=0
10+
echo 'no opencl supporting'
11+
fi
12+
413
redis-server --maxmemory 40mb --maxmemory-policy allkeys-lru --save "" --appendonly no --dbfilename "" &
514
mosquitto &
615

0 commit comments

Comments
 (0)