Skip to content

Commit

Permalink
Add submodules for SWIN and EmoNet
Browse files Browse the repository at this point in the history
  • Loading branch information
radekd91 committed Jan 17, 2022
1 parent b695dcb commit 47addff
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 6 deletions.
8 changes: 8 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions external/SwinTransformer
Submodule SwinTransformer added at ed92e9
1 change: 1 addition & 0 deletions external/emonet
Submodule emonet added at 48425d
3 changes: 2 additions & 1 deletion gdl/datasets/FaceVideoDataModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Expand Down
4 changes: 2 additions & 2 deletions gdl/layers/losses/EmonetLoader.py
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
4 changes: 2 additions & 2 deletions gdl/models/Swin.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
5 changes: 5 additions & 0 deletions gdl/utils/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 2 additions & 1 deletion gdl_apps/EmotionRecognition/training/train_emodeca.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 47addff

Please sign in to comment.