summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/faceAnalysis/faceAnalysis.actions.js2
-rw-r--r--client/faceAnalysis/faceAnalysis.result.js29
-rw-r--r--megapixels/app/server/tasks/demo.py72
3 files changed, 68 insertions, 35 deletions
diff --git a/client/faceAnalysis/faceAnalysis.actions.js b/client/faceAnalysis/faceAnalysis.actions.js
index 2d372c1e..4a6fe6ed 100644
--- a/client/faceAnalysis/faceAnalysis.actions.js
+++ b/client/faceAnalysis/faceAnalysis.actions.js
@@ -81,7 +81,7 @@ export const upload = (payload, file) => dispatch => {
post(url.upload(), fd)
.then(data => {
// console.log('loaded!', tag, data)
- dispatch(polled(tag, data))
+ dispatch(loaded(tag, data))
const { result, taskURL } = data
if (result && taskURL) {
poll(payload, taskURL)(dispatch)
diff --git a/client/faceAnalysis/faceAnalysis.result.js b/client/faceAnalysis/faceAnalysis.result.js
index 1c8a2ffb..e7a4c6de 100644
--- a/client/faceAnalysis/faceAnalysis.result.js
+++ b/client/faceAnalysis/faceAnalysis.result.js
@@ -66,7 +66,6 @@ class FaceAnalysisResult extends Component {
console.log(data.data)
const results = [
'blur_fn', 'points_3d_68', 'landmarks_3d_68', 'landmarks_2d_68', 'pose',
- 'age_real', 'age_apparent', 'gender'
].map(tag => {
if (tag in data.data) {
const { title, url } = data.data[tag]
@@ -80,14 +79,38 @@ class FaceAnalysisResult extends Component {
return null
}).filter(a => a)
+ const statisticsLabels = ['Age (Real)', 'Age (Apparent)', 'Gender', 'Beauty score', 'Emotion']
+ const statistics = [
+ 'age_real', 'age_apparent', 'gender', 'beauty', 'emotion'
+ ].map((tag, i) => {
+ if (tag in data.data.statistics) {
+ return (
+ <tr key={tag}>
+ <td>
+ {statisticsLabels[i]}
+ </td>
+ <td>
+ {data.data.statistics[tag]}
+ </td>
+ </tr>
+ )
+ }
+ return null
+ }).filter(a => a)
+
return (
<div>
- {!(step && total && message) ? '' : (<span>Step {step} / {total}: {message}</span>)}
<div className='results'>
{results}
</div>
+ {!!statistics.length && (
+ <table>
+ {statistics}
+ </table>
+ )}
<div className="about">
- <small>Query took {(timing / 1000).toFixed(2)} s.</small>
+ <small>Step {step} / {total} {message}</small>
+ <small>Query {step === total ? 'took' : 'timer:'} {(timing / 1000).toFixed(2)} s.</small>
</div>
</div>
)
diff --git a/megapixels/app/server/tasks/demo.py b/megapixels/app/server/tasks/demo.py
index 5143dd56..c27b08b5 100644
--- a/megapixels/app/server/tasks/demo.py
+++ b/megapixels/app/server/tasks/demo.py
@@ -24,7 +24,8 @@ def demo_task(self, uuid_name, fn):
from app.utils import logger_utils, file_utils, im_utils, display_utils, draw_utils
from app.utils import plot_utils
- from app.processors import face_detector, face_landmarks, face_age_gender
+ from app.processors import face_detector, face_landmarks, face_age_gender, face_beauty
+ # , face_emotion
from app.models.data_store import DataStore
# TODO add selective testing
@@ -39,16 +40,16 @@ def demo_task(self, uuid_name, fn):
meta = {
'step': 0,
- 'total': 3,
+ 'total': 10,
'message': 'Starting',
'uuid': uuid_name,
- 'data': {},
+ 'data': { 'statistics': {} },
}
paths = []
- def step(msg, step=0):
- meta['step'] += step
+ def step(msg, step=1):
meta['message'] = msg
+ meta['step'] += step
log.debug('> {}'.format(msg))
self.update_state(state='PROCESSING', meta=meta)
@@ -178,56 +179,65 @@ def demo_task(self, uuid_name, fn):
# age
# real
+ step('Running age predictor')
age_real_predictor = face_age_gender.FaceAgeReal()
st = time.time()
age_real = age_real_predictor.predict(im_resized, bbox_dim)
log.info(f'age real took: {(time.time()-st)/1000:.5f}s')
+ meta['data']['statistics']['age_real'] = f'{(age_real):.2f}'
# apparent
age_apparent_predictor = face_age_gender.FaceAgeApparent()
st = time.time()
age_apparent = age_apparent_predictor.predict(im_resized, bbox_dim)
log.info(f'age apparent took: {(time.time()-st)/1000:.5f}s')
+ meta['data']['statistics']['age_apparent'] = f'{(age_apparent):.2f}'
# gender
+ step('Running gender predictor')
gender_predictor = face_age_gender.FaceGender()
st = time.time()
gender = gender_predictor.predict(im_resized, bbox_dim)
log.info(f'gender took: {(time.time()-st)/1000:.5f}s')
+ meta['data']['statistics']['gender'] = f"M: {gender['m']:.2f}, F: {gender['f']:.2f}"
- # ----------------------------------------------------------------------------
- # output
-
- log.info(f'Face coords: {bbox_dim} face')
- log.info(f'Age (real): {(age_real):.2f}')
- log.info(f'Age (apparent): {(age_apparent):.2f}')
- log.info(f'gender: {gender}')
+ # # ----------------------------------------------------------------------------
+ # # emotion
+
+ # emotion_predictor = face_emotion.FaceEmotion(gpu=opt_gpu)
+ # emotion_score = emotion_predictor.emotion(im_resized, bbox_dim)
+ # log.info(f'emotion score: {(100*emotion_score):.2f}')
+
+ # im_emotion = im_resized.copy()
+ # draw_utils.draw_bbox(im_emotion, bbox_dim)
+ # txt = f'emotion score: {(100*emotion_score):.2f}'
+ # draw_utils.draw_text(im_emotion, bbox_dim.pt_tl, txt)
+ # save_image('emotion', 'Emotion', im_emotion)
# ----------------------------------------------------------------------------
- # draw
+ # beauty
- # draw real age
- im_age_real = im_resized.copy()
- draw_utils.draw_bbox(im_age_real, bbox_dim)
- txt = f'{(age_real):.2f}'
- draw_utils.draw_text(im_age_real, bbox_dim.pt_tl, txt)
+ # 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
- # apparent age
- im_age_apparent = im_resized.copy()
- draw_utils.draw_bbox(im_age_apparent, bbox_dim)
- txt = f'{(age_apparent):.2f}'
- draw_utils.draw_text(im_age_apparent, bbox_dim.pt_tl, txt)
+ step('Running beauty predictor')
+ device_cur = os.getenv('CUDA_VISIBLE_DEVICES', '')
+ os.environ['CUDA_VISIBLE_DEVICES'] = ''
+ beauty_predictor = face_beauty.FaceBeauty()
+ os.environ['CUDA_VISIBLE_DEVICES'] = device_cur
- # gender
- im_gender = im_resized.copy()
- draw_utils.draw_bbox(im_age_apparent, bbox_dim)
- txt = f"M: {gender['m']:.2f}, F: {gender['f']:.2f}"
- draw_utils.draw_text(im_gender, (10, dim[1]-20), txt)
+ beauty_score = beauty_predictor.beauty(im_resized, bbox_dim)
+ log.info(f'beauty score: {(100*beauty_score):.2f}')
- save_image('age_real', 'Age (Real)', im_age_real)
- save_image('age_apparent', 'Age (Apparent)', im_age_apparent)
- save_image('gender', 'Gender', im_gender)
+ # # draw 2d landmarks
+ # im_beauty = im_resized.copy()
+ # draw_utils.draw_bbox(im_beauty, bbox_dim)
+ # txt = f'Beauty score: {(100*beauty_score):.2f}'
+ # draw_utils.draw_text(im_beauty, bbox_dim.pt_tl, txt)
+ # save_image('beauty', 'Beauty', im_beauty)
+ meta['data']['statistics']['beauty'] = f'{(100*beauty_score):.2f}'
step('Done')