Skip to content
Snippets Groups Projects
Commit b3229215 authored by Anjith GEORGE's avatar Anjith GEORGE
Browse files

Added facexzoo models

parent 2be81a33
No related branches found
No related tags found
No related merge requests found
Pipeline #52777 failed
from bob.bio.face.embeddings.pytorch import AttentionNet
from bob.bio.face.utils import lookup_config_from_database
annotation_type, fixed_positions, memory_demanding = lookup_config_from_database(
locals().get("database")
)
def load(annotation_type, fixed_positions=None, memory_demanding=False):
return AttentionNet(annotation_type, fixed_positions, memory_demanding)
pipeline = load(annotation_type, fixed_positions, memory_demanding)
from bob.bio.face.embeddings.pytorch import EfficientNet
from bob.bio.face.utils import lookup_config_from_database
annotation_type, fixed_positions, memory_demanding = lookup_config_from_database(
locals().get("database")
)
def load(annotation_type, fixed_positions=None, memory_demanding=False):
return EfficientNet(annotation_type, fixed_positions, memory_demanding)
pipeline = load(annotation_type, fixed_positions, memory_demanding)
from bob.bio.face.embeddings.pytorch import MobileFaceNet
from bob.bio.face.utils import lookup_config_from_database
annotation_type, fixed_positions, memory_demanding = lookup_config_from_database(
locals().get("database")
)
def load(annotation_type, fixed_positions=None, memory_demanding=False):
return MobileFaceNet(annotation_type, fixed_positions, memory_demanding)
pipeline = load(annotation_type, fixed_positions, memory_demanding)
from bob.bio.face.embeddings.pytorch import ResNeSt
from bob.bio.face.utils import lookup_config_from_database
annotation_type, fixed_positions, memory_demanding = lookup_config_from_database(
locals().get("database")
)
def load(annotation_type, fixed_positions=None, memory_demanding=False):
return ResNeSt(annotation_type, fixed_positions, memory_demanding)
pipeline = load(annotation_type, fixed_positions, memory_demanding)
from bob.bio.face.embeddings.pytorch import ResNet
from bob.bio.face.utils import lookup_config_from_database
annotation_type, fixed_positions, memory_demanding = lookup_config_from_database(
locals().get("database")
)
def load(annotation_type, fixed_positions=None, memory_demanding=False):
return ResNet(annotation_type, fixed_positions, memory_demanding)
pipeline = load(annotation_type, fixed_positions, memory_demanding)
......@@ -5,7 +5,7 @@
import imp
import os
import torch
import numpy as np
from bob.bio.base.pipelines.vanilla_biometrics import Distance
from bob.bio.base.pipelines.vanilla_biometrics import VanillaBiometricsPipeline
......@@ -16,6 +16,7 @@ from sklearn.base import BaseEstimator
from sklearn.base import TransformerMixin
from sklearn.utils import check_array
from bob.learn.pytorch.architectures.facexzoo import FaceXZooModelFactory
class PyTorchModel(TransformerMixin, BaseEstimator):
"""
......@@ -276,6 +277,68 @@ class IResnet100(PyTorchModel):
self.model.eval()
self.place_model_on_device()
class FaceXZooModel(PyTorchModel):
"""
FaceXZoo models
"""
def __init__(
self,
preprocessor=lambda x: (x - 127.5) / 128.0,
memory_demanding=False,
device=None,
arch='AttentionNet',
**kwargs,
):
self.arch=arch
_model= FaceXZooModelFactory(self.arch)
# self.model = _model.get_model()
filename = _model.get_facexzoo_file()
checkpoint_name = _model.get_checkpoint_name()
config=None
path = os.path.dirname(filename)
checkpoint_path = os.path.join(path, self.arch+'.pt')
super(FaceXZooModel, self).__init__(
checkpoint_path,
config,
memory_demanding=memory_demanding,
preprocessor=preprocessor,
device=device,
**kwargs,
)
def _load_model(self):
_model= FaceXZooModelFactory(self.arch)
self.model = _model.get_model()
print('self.checkpoint_path',self.checkpoint_path)
print('self.arch',self.arch)
#print('self.model', self.model)
model_dict = self.model.state_dict()
pretrained_dict = torch.load(self.checkpoint_path, map_location=torch.device('cpu'))['state_dict']
pretrained_dict_keys=pretrained_dict.keys()
model_dict_keys=model_dict.keys()
new_pretrained_dict = {}
for k in model_dict:
new_pretrained_dict[k] = pretrained_dict['backbone.'+k]
model_dict.update(new_pretrained_dict)
self.model.load_state_dict(model_dict)
self.model.eval()
self.place_model_on_device()
def iresnet_template(embedding, annotation_type, fixed_positions=None):
# DEFINE CROPPING
......@@ -303,6 +366,137 @@ def iresnet_template(embedding, annotation_type, fixed_positions=None):
return VanillaBiometricsPipeline(transformer, algorithm)
def AttentionNet(annotation_type, fixed_positions=None, memory_demanding=False):
"""
Get the AttentionNet pipeline which will crop the face :math:`112 \times 112` and
use the :py:class:`AttentionNet` to extract the features
Parameters
----------
annotation_type: str
Type of the annotations (e.g. `eyes-center')
fixed_positions: dict
Set it if in your face images are registered to a fixed position in the image
memory_demanding: bool
"""
return iresnet_template(
embedding=FaceXZooModel(arch='AttentionNet', memory_demanding=memory_demanding),
annotation_type=annotation_type,
fixed_positions=fixed_positions,
)
def ResNeSt(annotation_type, fixed_positions=None, memory_demanding=False):
"""
Get the ResNeSt pipeline which will crop the face :math:`112 \times 112` and
use the :py:class:`ResNeSt` to extract the features
Parameters
----------
annotation_type: str
Type of the annotations (e.g. `eyes-center')
fixed_positions: dict
Set it if in your face images are registered to a fixed position in the image
memory_demanding: bool
"""
return iresnet_template(
embedding=FaceXZooModel(arch='ResNeSt', memory_demanding=memory_demanding),
annotation_type=annotation_type,
fixed_positions=fixed_positions,
)
def MobileFaceNet(annotation_type, fixed_positions=None, memory_demanding=False):
"""
Get the MobileFaceNet pipeline which will crop the face :math:`112 \times 112` and
use the :py:class:`MobileFaceNet` to extract the features
Parameters
----------
annotation_type: str
Type of the annotations (e.g. `eyes-center')
fixed_positions: dict
Set it if in your face images are registered to a fixed position in the image
memory_demanding: bool
"""
return iresnet_template(
embedding=FaceXZooModel(arch='MobileFaceNet', memory_demanding=memory_demanding),
annotation_type=annotation_type,
fixed_positions=fixed_positions,
)
def ResNet(annotation_type, fixed_positions=None, memory_demanding=False):
"""
Get the ResNet pipeline which will crop the face :math:`112 \times 112` and
use the :py:class:`ResNet` to extract the features
Parameters
----------
annotation_type: str
Type of the annotations (e.g. `eyes-center')
fixed_positions: dict
Set it if in your face images are registered to a fixed position in the image
memory_demanding: bool
"""
return iresnet_template(
embedding=FaceXZooModel(arch='ResNet', memory_demanding=memory_demanding),
annotation_type=annotation_type,
fixed_positions=fixed_positions,
)
def EfficientNet(annotation_type, fixed_positions=None, memory_demanding=False):
"""
Get the EfficientNet pipeline which will crop the face :math:`112 \times 112` and
use the :py:class:`EfficientNet` to extract the features
Parameters
----------
annotation_type: str
Type of the annotations (e.g. `eyes-center')
fixed_positions: dict
Set it if in your face images are registered to a fixed position in the image
memory_demanding: bool
"""
return iresnet_template(
embedding=FaceXZooModel(arch='EfficientNet', memory_demanding=memory_demanding),
annotation_type=annotation_type,
fixed_positions=fixed_positions,
)
def iresnet34(annotation_type, fixed_positions=None, memory_demanding=False):
"""
Get the Resnet34 pipeline which will crop the face :math:`112 \times 112` and
......
......@@ -143,6 +143,11 @@ setup(
"resnet50-msceleb-arcface-20210521 = bob.bio.face.config.baseline.resnet50_msceleb_arcface_20210521:pipeline",
"resnet50-vgg2-arcface-2021 = bob.bio.face.config.baseline.resnet50_vgg2_arcface_2021:pipeline",
"vgg16-oxford = bob.bio.face.config.baseline.vgg16_oxford:pipeline",
"attentionnet = bob.bio.face.config.baseline.AttentionNet:pipeline",
"resnest = bob.bio.face.config.baseline.ResNeSt:pipeline",
"mobilefacenet = bob.bio.face.config.baseline.MobileFaceNet:pipeline",
"resnet = bob.bio.face.config.baseline.ResNet:pipeline",
"efficientnet = bob.bio.face.config.baseline.EfficientNet:pipeline",
],
"bob.bio.config": [
# pipelines
......@@ -166,6 +171,11 @@ setup(
"resnet50-msceleb-arcface-20210521 = bob.bio.face.config.baseline.resnet50_msceleb_arcface_20210521:pipeline",
"resnet50-vgg2-arcface-2021 = bob.bio.face.config.baseline.resnet50_vgg2_arcface_2021",
"vgg16-oxford = bob.bio.face.config.baseline.vgg16_oxford",
"attentionnet = bob.bio.face.config.baseline.AttentionNet",
"resnest = bob.bio.face.config.baseline.ResNeSt",
"mobilefacenet = bob.bio.face.config.baseline.MobileFaceNet",
"resnet = bob.bio.face.config.baseline.ResNet",
"efficientnet = bob.bio.face.config.baseline.EfficientNet",
# databases
"arface = bob.bio.face.config.database.arface",
"atnt = bob.bio.face.config.database.atnt",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment