diff --git a/gdl/layers/losses/EmoNetLoss.py b/gdl/layers/losses/EmoNetLoss.py index bd81029d..0455c563 100644 --- a/gdl/layers/losses/EmoNetLoss.py +++ b/gdl/layers/losses/EmoNetLoss.py @@ -5,8 +5,14 @@ from gdl.layers.losses.EmonetLoader import get_emonet from pathlib import Path import torch.nn.functional as F -from gdl.models.EmoNetModule import EmoNetModule -from gdl.models.EmoSwinModule import EmoSwinModule +try: + from gdl.models.EmoNetModule import EmoNetModule +except ImportError as e: + print(f"Could not import EmoNetModule. EmoNet models will not be available.") +try: + from gdl.models.EmoSwinModule import EmoSwinModule +except ImportError as e: + print(f"Could not import EmoSwinModule. SWIN models will not be available") from gdl.models.EmoCnnModule import EmoCnnModule from gdl.models.IO import get_checkpoint_with_kwargs from gdl.utils.other import class_from_str diff --git a/gdl/models/DecaEncoder.py b/gdl/models/DecaEncoder.py index 6d8537d5..764dc1b3 100644 --- a/gdl/models/DecaEncoder.py +++ b/gdl/models/DecaEncoder.py @@ -6,7 +6,10 @@ import torch.nn.functional as F import gdl.models.ResNet as resnet -from .Swin import create_swin_backbone, swin_cfg_from_name +try: + from .Swin import create_swin_backbone, swin_cfg_from_name +except ImportError as e: + print("SWIN not found, will not be able to use SWIN models") class BaseEncoder(nn.Module): def __init__(self, outsize, last_op=None): diff --git a/gdl_apps/EMOCA/demos/test_emoca_on_video.py b/gdl_apps/EMOCA/demos/test_emoca_on_video.py index 96a21b92..6b5da5dc 100644 --- a/gdl_apps/EMOCA/demos/test_emoca_on_video.py +++ b/gdl_apps/EMOCA/demos/test_emoca_on_video.py @@ -59,29 +59,29 @@ def main(): ## 3) Get the data loadeer with the detected faces dl = dm.test_dataloader() - # ## 4) Run the model on the data - # for j, batch in enumerate (auto.tqdm( dl)): + ## 4) Run the model on the data + for j, batch in enumerate (auto.tqdm( dl)): - # current_bs = batch["image"].shape[0] - # img = batch - # vals, visdict = test(emoca, img) - # for i in range(current_bs): - # # name = f"{(j*batch_size + i):05d}" - # name = batch["image_name"][i] + current_bs = batch["image"].shape[0] + img = batch + vals, visdict = test(emoca, img) + for i in range(current_bs): + # name = f"{(j*batch_size + i):05d}" + name = batch["image_name"][i] - # sample_output_folder = Path(outfolder) /name - # sample_output_folder.mkdir(parents=True, exist_ok=True) + sample_output_folder = Path(outfolder) /name + sample_output_folder.mkdir(parents=True, exist_ok=True) - # if args.save_mesh: - # save_obj(emoca, str(sample_output_folder / "mesh_coarse.obj"), vals, i) - # if args.save_images: - # save_images(outfolder, name, visdict, i) - # if args.save_codes: - # save_codes(Path(outfolder), name, vals, i) + if args.save_mesh: + save_obj(emoca, str(sample_output_folder / "mesh_coarse.obj"), vals, i) + if args.save_images: + save_images(outfolder, name, visdict, i) + if args.save_codes: + save_codes(Path(outfolder), name, vals, i) - # ## 5) Create the reconstruction video (reconstructions overlayed on the original video) - # dm.create_reconstruction_video(0, rec_method=model_name, image_type=image_type, overwrite=True) - # print("Done") + ## 5) Create the reconstruction video (reconstructions overlayed on the original video) + dm.create_reconstruction_video(0, rec_method=model_name, image_type=image_type, overwrite=True) + print("Done") if __name__ == '__main__': diff --git a/gdl_apps/EMOCA/deprecated/expression_disentanglement_experiment.py b/gdl_apps/EMOCA/deprecated/expression_disentanglement_experiment.py index faa185f2..e5f83a87 100644 --- a/gdl_apps/EMOCA/deprecated/expression_disentanglement_experiment.py +++ b/gdl_apps/EMOCA/deprecated/expression_disentanglement_experiment.py @@ -7,7 +7,10 @@ from gdl.models.DECA import DECA, ExpDECA, DecaModule from gdl.models.IO import locate_checkpoint -from gdl.models.EmoNetModule import EmoNetModule +try: + from gdl.models.EmoNetModule import EmoNetModule +except ImportError as e: + print("Skipping EmoNetModule because EmoNet it is not installed") from gdl.utils.other import class_from_str import datetime from pytorch_lightning import Trainer diff --git a/gdl_apps/EmotionRecognition/evaluation/compute_confusion_matrix.py b/gdl_apps/EmotionRecognition/evaluation/compute_confusion_matrix.py index abfcce53..00b04421 100644 --- a/gdl_apps/EmotionRecognition/evaluation/compute_confusion_matrix.py +++ b/gdl_apps/EmotionRecognition/evaluation/compute_confusion_matrix.py @@ -7,7 +7,10 @@ from gdl.models.IO import locate_checkpoint, get_checkpoint_with_kwargs from gdl.models.EmoDECA import EmoDECA -from gdl.models.EmoNetModule import EmoNetModule +try: + from gdl.models.EmoNetModule import EmoNetModule +except ImportError as e: + print("Skipping EmoNetModule because EmoNet it is not installed") from gdl.utils.other import class_from_str import datetime from pytorch_lightning import Trainer diff --git a/gdl_apps/EmotionRecognition/training/train_emodeca.py b/gdl_apps/EmotionRecognition/training/train_emodeca.py index 982c63af..c4229cdd 100644 --- a/gdl_apps/EmotionRecognition/training/train_emodeca.py +++ b/gdl_apps/EmotionRecognition/training/train_emodeca.py @@ -16,9 +16,15 @@ from gdl.models.IO import locate_checkpoint, get_checkpoint_with_kwargs from gdl.models.EmoDECA import EmoDECA -from gdl.models.EmoSwinModule import EmoSwinModule +try: + from gdl.models.EmoSwinModule import EmoSwinModule +except ImportError as e: + print(f"Could not import EmoSwinModule. SWIN models will not be available") from gdl.models.EmoCnnModule import EmoCnnModule -from gdl.models.EmoNetModule import EmoNetModule +try: + from gdl.models.EmoNetModule import EmoNetModule +except ImportError as e: + print(f"Could not import EmoNet. EmoNet models will not be available") from gdl.models.EmoMLP import EmoMLP from gdl.utils.other import class_from_str diff --git a/gdl_apps/EmotionRecognition/utils/io.py b/gdl_apps/EmotionRecognition/utils/io.py index 0b70b9f9..786dc9ba 100644 --- a/gdl_apps/EmotionRecognition/utils/io.py +++ b/gdl_apps/EmotionRecognition/utils/io.py @@ -1,7 +1,13 @@ from gdl.models.EmoDECA import EmoDECA from gdl.models.EmoCnnModule import EmoCnnModule -from gdl.models.EmoSwinModule import EmoSwinModule -from gdl.models.EmoNetModule import EmoNetModule +try: + from gdl.models.EmoSwinModule import EmoSwinModule +except ImportError as e: + print(f"Could not import EmoSwinModule. SWIN models will not be available") +try: + from gdl.models.EmoNetModule import EmoNetModule +except ImportError as e: + print(f"Could not import EmoNetModule. EmoNet models will not be available") from gdl.models.IO import locate_checkpoint from gdl.utils.other import class_from_str from pathlib import Path