diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2019-01-13 23:23:17 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2019-01-13 23:23:17 +0100 |
| commit | 13655c42f9dd844a68f8c60a614641cdfa4c4277 (patch) | |
| tree | 8b729b04ac454e1e125c66ba38626c6c1c84bd0d /megapixels | |
| parent | e3cfc630f52bce03c3e0e213ca93be6f748a77cb (diff) | |
displayiing all statistics
Diffstat (limited to 'megapixels')
| -rw-r--r-- | megapixels/app/server/tasks/demo.py | 72 |
1 files changed, 41 insertions, 31 deletions
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') |
