From c81c919868e44972de9459858835603946776b47 Mon Sep 17 00:00:00 2001 From: "jordi.hasianta" Date: Thu, 15 Sep 2022 19:44:59 +0700 Subject: [PATCH] add private module to create model object for library api --- opendbm/api_lib/facial_activity/__init__.py | 1 + .../api_lib/facial_activity/_action_unit.py | 49 ++++++++++ opendbm/api_lib/facial_activity/_asymmetry.py | 20 +++++ .../api_lib/facial_activity/_expressivity.py | 89 +++++++++++++++++++ opendbm/api_lib/facial_activity/_landmark.py | 24 +++++ 5 files changed, 183 insertions(+) create mode 100644 opendbm/api_lib/facial_activity/__init__.py create mode 100644 opendbm/api_lib/facial_activity/_action_unit.py create mode 100644 opendbm/api_lib/facial_activity/_asymmetry.py create mode 100644 opendbm/api_lib/facial_activity/_expressivity.py create mode 100644 opendbm/api_lib/facial_activity/_landmark.py diff --git a/opendbm/api_lib/facial_activity/__init__.py b/opendbm/api_lib/facial_activity/__init__.py new file mode 100644 index 00000000..a20716c8 --- /dev/null +++ b/opendbm/api_lib/facial_activity/__init__.py @@ -0,0 +1 @@ +from opendbm.api_lib.facial_activity.api import FacialActivity diff --git a/opendbm/api_lib/facial_activity/_action_unit.py b/opendbm/api_lib/facial_activity/_action_unit.py new file mode 100644 index 00000000..35b75b09 --- /dev/null +++ b/opendbm/api_lib/facial_activity/_action_unit.py @@ -0,0 +1,49 @@ +import tempfile + +from opendbm.api_lib.model import VideoModel +from opendbm.dbm_lib.dbm_features.raw_features.video.face_au import run_face_au + + +class ActionUnit(VideoModel): + def __init__(self): + super().__init__() + self._params = [ + "fac_AU01int", + "fac_AU02int", + "fac_AU04int", + "fac_AU05int", + "fac_AU06int", + "fac_AU07int", + "fac_AU09int", + "fac_AU10int", + "fac_AU12int", + "fac_AU14int", + "fac_AU15int", + "fac_AU17int", + "fac_AU20int", + "fac_AU23int", + "fac_AU25int", + "fac_AU26int", + "fac_AU45int", + "fac_AU01pres", + "fac_AU02pres", + "fac_AU04pres", + "fac_AU05pres", + "fac_AU06pres", + "fac_AU07pres", + "fac_AU09pres", + "fac_AU10pres", + "fac_AU12pres", + "fac_AU14pres", + "fac_AU15pres", + "fac_AU17pres", + "fac_AU20pres", + "fac_AU23pres", + "fac_AU25pres", + "fac_AU26pres", + "fac_AU28pres", + "fac_AU45pres", + ] + + def _fit_transform(self, path): + return run_face_au(path, f"{tempfile.gettempdir()}/", self.r_config, save=False) diff --git a/opendbm/api_lib/facial_activity/_asymmetry.py b/opendbm/api_lib/facial_activity/_asymmetry.py new file mode 100644 index 00000000..04ae78e8 --- /dev/null +++ b/opendbm/api_lib/facial_activity/_asymmetry.py @@ -0,0 +1,20 @@ +import tempfile + +from opendbm.api_lib.model import VideoModel +from opendbm.dbm_lib import run_face_asymmetry + + +class Asymmetry(VideoModel): + def __init__(self): + super().__init__() + self._params = [ + "fac_asymmaskmouth", + "fac_asymmaskeye", + "fac_asymmaskeyebrow", + "fac_asymmaskcom", + ] + + def _fit_transform(self, path): + return run_face_asymmetry( + path, f"{tempfile.gettempdir()}/", self.r_config, save=False + ) diff --git a/opendbm/api_lib/facial_activity/_expressivity.py b/opendbm/api_lib/facial_activity/_expressivity.py new file mode 100644 index 00000000..f69da6e2 --- /dev/null +++ b/opendbm/api_lib/facial_activity/_expressivity.py @@ -0,0 +1,89 @@ +import tempfile + +from opendbm.api_lib.model import VideoModel +from opendbm.dbm_lib.dbm_features.raw_features.video import face_emotion_expressivity + + +class Expressivity(VideoModel): + def __init__(self): + super().__init__() + self._params = [ + " AU01_r", + " AU02_r", + " AU04_r", + " AU05_r", + " AU06_r", + " AU07_r", + " AU09_r", + " AU10_r", + " AU12_r", + " AU14_r", + " AU15_r", + " AU17_r", + " AU20_r", + " AU25_r", + " AU26_r", + " AU45_r", + " AU01_c", + " AU02_c", + " AU04_c", + " AU05_c", + " AU06_c", + " AU07_c", + " AU10_c", + " AU12_c", + " AU14_c", + " AU15_c", + " AU17_c", + " AU20_c", + " AU23_c", + " AU25_c", + " AU26_c", + " AU28_c", + " AU45_c", + " AU09_c", + " AU23_r", + "s_confidence", + "fac_hapintsoft", + "fac_sadintsoft", + "fac_surintsoft", + "fac_feaintsoft", + "fac_angintsoft", + "fac_disintsoft", + "fac_conintsoft", + "fac_paiintsoft", + "fac_negintsoft", + "fac_posintsoft", + "neu_exp", + "fac_comlowintsoft", + "fac_comuppintsoft", + "cai_exp", + "fac_comintsoft", + "fac_happres", + "fac_sadpres", + "fac_surpres", + "fac_feapres", + "fac_angpres", + "fac_dispres", + "fac_conpres", + "fac_hapinthard", + "fac_sadinthard", + "fac_surinthard", + "fac_feainthard", + "fac_anginthard", + "fac_disinthard", + "fac_coninthard", + "fac_paiinthard", + "fac_neginthard", + "fac_posinthard", + "neu_exp_full", + "cai_exp_full", + "fac_comlowinthard", + "fac_comuppinthard", + "fac_cominthard", + ] + + def _fit_transform(self, path): + return face_emotion_expressivity.run_face_expressivity( + path, f"{tempfile.gettempdir()}/", self.r_config, save=False + ) diff --git a/opendbm/api_lib/facial_activity/_landmark.py b/opendbm/api_lib/facial_activity/_landmark.py new file mode 100644 index 00000000..9ed9f538 --- /dev/null +++ b/opendbm/api_lib/facial_activity/_landmark.py @@ -0,0 +1,24 @@ +import tempfile + +from opendbm.api_lib.model import VideoModel +from opendbm.dbm_lib import run_face_landmark + + +def r_num_fmt(fmt, rnum): + return list(map(lambda x: fmt.format(i="%02d" % x), rnum)) + + +lcols = [] +for vr in ["r", "c", "X", "Y", "Z"]: + lcols += r_num_fmt(f"fac_LMK{{i}}{vr}", range(68)) + + +class Landmark(VideoModel): + def __init__(self): + super().__init__() + self._params = lcols + + def _fit_transform(self, path): + return run_face_landmark( + path, f"{tempfile.gettempdir()}/", self.r_config, save=False + )