diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..cd24720c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,8 @@ +[submodule "external/emonet"] + path = external/emonet + url = https://github.com/coloss/emonet.git + branch = feature/exposeEemotionFeature +[submodule "external/SwinTransformer"] + path = external/SwinTransformer + url = https://github.com/coloss/Swin-Transformer.git + branch = feature/emoca diff --git a/external/SwinTransformer b/external/SwinTransformer new file mode 160000 index 00000000..ed92e9ae --- /dev/null +++ b/external/SwinTransformer @@ -0,0 +1 @@ +Subproject commit ed92e9aeb36387447a5193590033b3b0f17e057b diff --git a/external/emonet b/external/emonet new file mode 160000 index 00000000..48425dee --- /dev/null +++ b/external/emonet @@ -0,0 +1 @@ +Subproject commit 48425dee64919ea9a767de1c091ca19567a209d3 diff --git a/gdl/datasets/FaceVideoDataModule.py b/gdl/datasets/FaceVideoDataModule.py index 89033b8d..5eb0f2aa 100644 --- a/gdl/datasets/FaceVideoDataModule.py +++ b/gdl/datasets/FaceVideoDataModule.py @@ -398,8 +398,9 @@ def vis_parsing_maps(im, parsing_anno, stride, save_im=False, save_path='overlay def _get_emonet(self, device=None): + from gdl.utils.other import get_path_to_externals device = device or torch.device('cuda:0' if torch.cuda.is_available() else 'cpu') - path_to_emonet = Path(__file__).parent.parent.parent / "emonet" + path_to_emonet = get_path_to_externals() / "emonet" if not(str(path_to_emonet) in sys.path or str(path_to_emonet.absolute()) in sys.path): sys.path += [str(path_to_emonet)] diff --git a/gdl/layers/losses/EmonetLoader.py b/gdl/layers/losses/EmonetLoader.py index cd62aa8c..b2d6aa99 100644 --- a/gdl/layers/losses/EmonetLoader.py +++ b/gdl/layers/losses/EmonetLoader.py @@ -1,13 +1,13 @@ import inspect import sys from pathlib import Path - +from gdl.utils.other import get_path_to_externals import torch def get_emonet(device=None, load_pretrained=True): device = device or torch.device('cuda:0' if torch.cuda.is_available() else 'cpu') - path_to_emonet = Path(__file__).absolute().resolve().parent.parent.parent.parent.parent / "emonet" + path_to_emonet = get_path_to_externals() / "emonet" if not(str(path_to_emonet) in sys.path or str(path_to_emonet.absolute()) in sys.path): # print(f"Adding EmoNet path '{path_to_emonet}'") sys.path += [str(path_to_emonet)] diff --git a/gdl/models/Swin.py b/gdl/models/Swin.py index 61579801..0c43a520 100644 --- a/gdl/models/Swin.py +++ b/gdl/models/Swin.py @@ -1,7 +1,7 @@ import os, sys from pathlib import Path -# swin_path = (Path(__file__).parents[2] / "Swin-Transformer").absolute() -swin_path = (Path(__file__).parents[3] / "SwinTransformer").absolute() +from gdl.utils.other import get_path_to_externals +swin_path = (get_path_to_externals() / "SwinTransformer").absolute() if not swin_path.is_dir(): raise ImportError(f"Swin repository not found in : '{swin_path}'") if str(swin_path.parent) not in sys.path: diff --git a/gdl/utils/other.py b/gdl/utils/other.py index abe01cf0..49a0ed1f 100644 --- a/gdl/utils/other.py +++ b/gdl/utils/other.py @@ -16,3 +16,8 @@ def class_from_str(str, module=None, none_on_fail = False) -> type: def get_path_to_assets() -> Path: import gdl return Path(gdl.__file__).parents[1] / "assets" + + +def get_path_to_externals() -> Path: + import gdl + return Path(gdl.__file__).parents[1] / "external" diff --git a/gdl_apps/EmotionRecognition/training/train_emodeca.py b/gdl_apps/EmotionRecognition/training/train_emodeca.py index c4229cdd..6079ace6 100644 --- a/gdl_apps/EmotionRecognition/training/train_emodeca.py +++ b/gdl_apps/EmotionRecognition/training/train_emodeca.py @@ -421,8 +421,9 @@ def configure(emo_deca_default, emodeca_overrides, deca_default, deca_overrides, if 'swin_type' in cfg.model.keys(): if cfg.model.swin_cfg == 'todo': + from gdl.utils.other import get_path_to_externals swin_cfg = OmegaConf.load( - Path(__file__).parents[3] / "SwinTransformer" / "configs" / (cfg.model.swin_type + ".yaml")) + get_path_to_externals() / "SwinTransformer" / "configs" / (cfg.model.swin_type + ".yaml")) OmegaConf.set_struct(swin_cfg, True) cfg.model.swin_cfg = swin_cfg return cfg