summaryrefslogtreecommitdiff
path: root/megapixels/commands/demo/face_beauty.py
diff options
context:
space:
mode:
authorAdam Harvey <adam@ahprojects.com>2019-01-07 18:49:09 +0100
committerAdam Harvey <adam@ahprojects.com>2019-01-07 18:49:09 +0100
commitc67a3c23190287f747989e5dc7725e1657edf8f1 (patch)
tree5ff47ab72e6fb146f66730db06fc3b91265dd769 /megapixels/commands/demo/face_beauty.py
parent55b9734d131a197166156566d1b999a8bb59169b (diff)
add age, gender, emotion stubs
Diffstat (limited to 'megapixels/commands/demo/face_beauty.py')
-rw-r--r--megapixels/commands/demo/face_beauty.py28
1 files changed, 11 insertions, 17 deletions
diff --git a/megapixels/commands/demo/face_beauty.py b/megapixels/commands/demo/face_beauty.py
index b1612f7c..d31c5cee 100644
--- a/megapixels/commands/demo/face_beauty.py
+++ b/megapixels/commands/demo/face_beauty.py
@@ -1,6 +1,3 @@
-"""
-"""
-
import click
from app.settings import types
@@ -51,25 +48,23 @@ def cli(ctx, opt_fp_in, opt_fp_out, opt_gpu, opt_size, opt_force, opt_display):
# load image
im = cv.imread(opt_fp_in)
- # im = cv.cvtColor(im, cv.COLOR_BGR2RGB)
- if im.shape[0] > 1280:
- new_shape = (1280, im.shape[1] * 1280 / im.shape[0])
- elif im.shape[1] > 1280:
- new_shape = (im.shape[0] * 1280 / im.shape[1], 1280)
- elif im.shape[0] < 640 or im.shape[1] < 640:
- new_shape = (im.shape[0] * 2, im.shape[1] * 2)
- else:
- new_shape = im.shape[0:2]
+ im_resized = im_utils.resize(im, width=opt_size[0], height=opt_size[1])
- im_resized = cv.resize(im, (int(new_shape[1]), int(new_shape[0])))
- #im_resized = im_utils.resize(im, width=opt_size[0], height=opt_size[1])
+ # TODO fix Keras CPU/GPU device selection issue
+ # NB: GPU visibility issues with dlib/keras
+ # Wrap this with cuda toggle and run before init dlib GPU
+
+ device_cur = os.getenv('CUDA_VISIBLE_DEVICES', '')
+ os.environ['CUDA_VISIBLE_DEVICES'] = ''
+ beauty_predictor = face_beauty.FaceBeauty()
+ os.environ['CUDA_VISIBLE_DEVICES'] = device_cur
# ----------------------------------------------------------------------------
# detect face
- face_detector = face_detector.DetectorDLIBCNN() # -1 for CPU
+ face_detector = face_detector.DetectorDLIBCNN(gpu=opt_gpu) # -1 for CPU
bboxes = face_detector.detect(im_resized, largest=True)
bbox = bboxes[0]
dim = im_resized.shape[:2][::-1]
@@ -82,8 +77,7 @@ def cli(ctx, opt_fp_in, opt_fp_out, opt_gpu, opt_size, opt_force, opt_display):
# ----------------------------------------------------------------------------
# beauty
-
- beauty_predictor = face_beauty.FaceBeauty()
+
beauty_score = beauty_predictor.beauty(im_resized, bbox_dim)