Commit f44427da authored by Tiago de Freitas Pereira's avatar Tiago de Freitas Pereira Committed by Amir MOHAMMADI
Browse files

[nose] Fixed imports to no import tensorflow all the time

parent 839f96ca
from bob.bio.face.embeddings import ArcFaceInsightFace from bob.bio.face.embeddings.mxnet_models import ArcFaceInsightFace
from bob.bio.face.config.baseline.helpers import embedding_transformer_112x112 from bob.bio.face.config.baseline.helpers import embedding_transformer_112x112
from bob.bio.base.pipelines.vanilla_biometrics import ( from bob.bio.base.pipelines.vanilla_biometrics import (
Distance, Distance,
...@@ -23,5 +23,6 @@ def load(annotation_type, fixed_positions=None): ...@@ -23,5 +23,6 @@ def load(annotation_type, fixed_positions=None):
return VanillaBiometricsPipeline(transformer, algorithm) return VanillaBiometricsPipeline(transformer, algorithm)
pipeline = load(annotation_type, fixed_positions) pipeline = load(annotation_type, fixed_positions)
transformer = pipeline.transformer transformer = pipeline.transformer
\ No newline at end of file
from bob.bio.face.embeddings import FaceNetSanderberg_20170512_110547 from bob.bio.face.embeddings.tf2_inception_resnet import (
FaceNetSanderberg_20170512_110547,
)
from bob.bio.face.config.baseline.helpers import embedding_transformer_160x160 from bob.bio.face.config.baseline.helpers import embedding_transformer_160x160
from bob.bio.base.pipelines.vanilla_biometrics import ( from bob.bio.base.pipelines.vanilla_biometrics import (
Distance, Distance,
......
from bob.bio.face.embeddings import InceptionResnetv1_Casia_CenterLoss_2018 from bob.bio.face.embeddings.tf2_inception_resnet import (
InceptionResnetv1_Casia_CenterLoss_2018,
)
from bob.bio.face.config.baseline.helpers import embedding_transformer_160x160 from bob.bio.face.config.baseline.helpers import embedding_transformer_160x160
from bob.bio.base.pipelines.vanilla_biometrics import ( from bob.bio.base.pipelines.vanilla_biometrics import (
Distance, Distance,
...@@ -13,6 +15,7 @@ else: ...@@ -13,6 +15,7 @@ else:
annotation_type = None annotation_type = None
fixed_positions = None fixed_positions = None
def load(annotation_type, fixed_positions=None): def load(annotation_type, fixed_positions=None):
transformer = embedding_transformer_160x160( transformer = embedding_transformer_160x160(
InceptionResnetv1_Casia_CenterLoss_2018(), annotation_type, fixed_positions InceptionResnetv1_Casia_CenterLoss_2018(), annotation_type, fixed_positions
...@@ -22,5 +25,6 @@ def load(annotation_type, fixed_positions=None): ...@@ -22,5 +25,6 @@ def load(annotation_type, fixed_positions=None):
return VanillaBiometricsPipeline(transformer, algorithm) return VanillaBiometricsPipeline(transformer, algorithm)
pipeline = load(annotation_type, fixed_positions) pipeline = load(annotation_type, fixed_positions)
transformer = pipeline.transformer transformer = pipeline.transformer
\ No newline at end of file
from bob.bio.face.embeddings import InceptionResnetv1_MsCeleb_CenterLoss_2018 from bob.bio.face.embeddings.tf2_inception_resnet import (
InceptionResnetv1_MsCeleb_CenterLoss_2018,
)
from bob.bio.face.config.baseline.helpers import embedding_transformer_160x160 from bob.bio.face.config.baseline.helpers import embedding_transformer_160x160
from bob.bio.base.pipelines.vanilla_biometrics import ( from bob.bio.base.pipelines.vanilla_biometrics import (
Distance, Distance,
...@@ -25,4 +27,4 @@ def load(annotation_type, fixed_positions=None): ...@@ -25,4 +27,4 @@ def load(annotation_type, fixed_positions=None):
pipeline = load(annotation_type, fixed_positions) pipeline = load(annotation_type, fixed_positions)
transformer = pipeline.transformer transformer = pipeline.transformer
\ No newline at end of file
from bob.bio.face.embeddings import InceptionResnetv2_Casia_CenterLoss_2018 from bob.bio.face.embeddings.tf2_inception_resnet import (
InceptionResnetv2_Casia_CenterLoss_2018,
)
from bob.bio.face.config.baseline.helpers import embedding_transformer_160x160 from bob.bio.face.config.baseline.helpers import embedding_transformer_160x160
from bob.bio.base.pipelines.vanilla_biometrics import ( from bob.bio.base.pipelines.vanilla_biometrics import (
Distance, Distance,
...@@ -25,4 +27,4 @@ def load(annotation_type, fixed_positions=None): ...@@ -25,4 +27,4 @@ def load(annotation_type, fixed_positions=None):
pipeline = load(annotation_type, fixed_positions) pipeline = load(annotation_type, fixed_positions)
transformer = pipeline.transformer transformer = pipeline.transformer
\ No newline at end of file
from bob.bio.face.embeddings import InceptionResnetv2_MsCeleb_CenterLoss_2018 from bob.bio.face.embeddings.tf2_inception_resnet import (
InceptionResnetv2_MsCeleb_CenterLoss_2018,
)
from bob.bio.face.config.baseline.helpers import embedding_transformer_160x160 from bob.bio.face.config.baseline.helpers import embedding_transformer_160x160
from bob.bio.base.pipelines.vanilla_biometrics import ( from bob.bio.base.pipelines.vanilla_biometrics import (
Distance, Distance,
...@@ -25,4 +27,4 @@ def load(annotation_type, fixed_positions=None): ...@@ -25,4 +27,4 @@ def load(annotation_type, fixed_positions=None):
pipeline = load(annotation_type, fixed_positions) pipeline = load(annotation_type, fixed_positions)
transformer = pipeline.transformer transformer = pipeline.transformer
\ No newline at end of file
import os import os
import bob.extension.download import bob.extension.download
def download_model(model_path, urls, zip_file="model.tar.gz"): def download_model(model_path, urls, zip_file="model.tar.gz"):
""" """
Download and unzip a model from some URL. Download and unzip a model from some URL.
...@@ -25,17 +26,6 @@ def download_model(model_path, urls, zip_file="model.tar.gz"): ...@@ -25,17 +26,6 @@ def download_model(model_path, urls, zip_file="model.tar.gz"):
bob.extension.download.download_and_unzip(urls, zip_file) bob.extension.download.download_and_unzip(urls, zip_file)
from .tf2_inception_resnet import (
InceptionResnet,
InceptionResnetv2_MsCeleb_CenterLoss_2018,
InceptionResnetv2_Casia_CenterLoss_2018,
InceptionResnetv1_MsCeleb_CenterLoss_2018,
InceptionResnetv1_Casia_CenterLoss_2018,
FaceNetSanderberg_20170512_110547
)
from .mxnet_models import ArcFaceInsightFace
# gets sphinx autodoc done right - don't remove it # gets sphinx autodoc done right - don't remove it
def __appropriate__(*args): def __appropriate__(*args):
"""Says object was actually declared here, and not in the import module. """Says object was actually declared here, and not in the import module.
...@@ -52,13 +42,5 @@ def __appropriate__(*args): ...@@ -52,13 +42,5 @@ def __appropriate__(*args):
obj.__module__ = __name__ obj.__module__ = __name__
__appropriate__( __appropriate__()
InceptionResnet,
InceptionResnetv2_MsCeleb_CenterLoss_2018,
InceptionResnetv1_MsCeleb_CenterLoss_2018,
InceptionResnetv2_Casia_CenterLoss_2018,
InceptionResnetv1_Casia_CenterLoss_2018,
FaceNetSanderberg_20170512_110547,
ArcFaceInsightFace
)
__all__ = [_ for _ in dir() if not _.startswith("_")] __all__ = [_ for _ in dir() if not _.startswith("_")]
...@@ -77,6 +77,9 @@ class InceptionResnet(TransformerMixin, BaseEstimator): ...@@ -77,6 +77,9 @@ class InceptionResnet(TransformerMixin, BaseEstimator):
def _more_tags(self): def _more_tags(self):
return {"stateless": True, "requires_fit": False} return {"stateless": True, "requires_fit": False}
def __del__(self):
self.model = None
class InceptionResnetv2_MsCeleb_CenterLoss_2018(InceptionResnet): class InceptionResnetv2_MsCeleb_CenterLoss_2018(InceptionResnet):
""" """
...@@ -100,7 +103,7 @@ class InceptionResnetv2_MsCeleb_CenterLoss_2018(InceptionResnet): ...@@ -100,7 +103,7 @@ class InceptionResnetv2_MsCeleb_CenterLoss_2018(InceptionResnet):
urls = [ urls = [
"https://www.idiap.ch/software/bob/data/bob/bob.bio.face/master/tf2/inceptionresnetv2_msceleb_centerloss_2018.tar.gz", "https://www.idiap.ch/software/bob/data/bob/bob.bio.face/master/tf2/inceptionresnetv2_msceleb_centerloss_2018.tar.gz",
"http://www.idiap.ch/software/bob/data/bob/bob.bio.face/master/tf2/inceptionresnetv2_msceleb_centerloss_2018.tar.gz" "http://www.idiap.ch/software/bob/data/bob/bob.bio.face/master/tf2/inceptionresnetv2_msceleb_centerloss_2018.tar.gz",
] ]
download_model( download_model(
...@@ -133,7 +136,7 @@ class InceptionResnetv2_Casia_CenterLoss_2018(InceptionResnet): ...@@ -133,7 +136,7 @@ class InceptionResnetv2_Casia_CenterLoss_2018(InceptionResnet):
urls = [ urls = [
"https://www.idiap.ch/software/bob/data/bob/bob.bio.face/master/tf2/inceptionresnetv2_casia_centerloss_2018.tar.gz", "https://www.idiap.ch/software/bob/data/bob/bob.bio.face/master/tf2/inceptionresnetv2_casia_centerloss_2018.tar.gz",
"http://www.idiap.ch/software/bob/data/bob/bob.bio.face/master/tf2/inceptionresnetv2_casia_centerloss_2018.tar.gz" "http://www.idiap.ch/software/bob/data/bob/bob.bio.face/master/tf2/inceptionresnetv2_casia_centerloss_2018.tar.gz",
] ]
download_model( download_model(
...@@ -166,7 +169,7 @@ class InceptionResnetv1_Casia_CenterLoss_2018(InceptionResnet): ...@@ -166,7 +169,7 @@ class InceptionResnetv1_Casia_CenterLoss_2018(InceptionResnet):
urls = [ urls = [
"https://www.idiap.ch/software/bob/data/bob/bob.bio.face/master/tf2/inceptionresnetv1_casia_centerloss_2018.tar.gz", "https://www.idiap.ch/software/bob/data/bob/bob.bio.face/master/tf2/inceptionresnetv1_casia_centerloss_2018.tar.gz",
"http://www.idiap.ch/software/bob/data/bob/bob.bio.face/master/tf2/inceptionresnetv1_casia_centerloss_2018.tar.gz" "http://www.idiap.ch/software/bob/data/bob/bob.bio.face/master/tf2/inceptionresnetv1_casia_centerloss_2018.tar.gz",
] ]
download_model( download_model(
...@@ -200,7 +203,7 @@ class InceptionResnetv1_MsCeleb_CenterLoss_2018(InceptionResnet): ...@@ -200,7 +203,7 @@ class InceptionResnetv1_MsCeleb_CenterLoss_2018(InceptionResnet):
urls = [ urls = [
"https://www.idiap.ch/software/bob/data/bob/bob.bio.face/master/tf2/inceptionresnetv1_msceleb_centerloss_2018.tar.gz", "https://www.idiap.ch/software/bob/data/bob/bob.bio.face/master/tf2/inceptionresnetv1_msceleb_centerloss_2018.tar.gz",
"http://www.idiap.ch/software/bob/data/bob/bob.bio.face/master/tf2/inceptionresnetv1_msceleb_centerloss_2018.tar.gz" "http://www.idiap.ch/software/bob/data/bob/bob.bio.face/master/tf2/inceptionresnetv1_msceleb_centerloss_2018.tar.gz",
] ]
download_model( download_model(
......
...@@ -8,7 +8,9 @@ from bob.bio.base.test.utils import is_library_available ...@@ -8,7 +8,9 @@ from bob.bio.base.test.utils import is_library_available
@is_library_available("tensorflow") @is_library_available("tensorflow")
def test_idiap_inceptionv2_msceleb(): def test_idiap_inceptionv2_msceleb():
from bob.bio.face.embeddings import InceptionResnetv2_MsCeleb_CenterLoss_2018 from bob.bio.face.embeddings.tf2_inception_resnet import (
InceptionResnetv2_MsCeleb_CenterLoss_2018,
)
reference = bob.io.base.load( reference = bob.io.base.load(
pkg_resources.resource_filename( pkg_resources.resource_filename(
...@@ -50,7 +52,9 @@ def test_idiap_inceptionv2_casia(): ...@@ -50,7 +52,9 @@ def test_idiap_inceptionv2_casia():
@is_library_available("tensorflow") @is_library_available("tensorflow")
def test_idiap_inceptionv1_msceleb(): def test_idiap_inceptionv1_msceleb():
from bob.bio.face.embeddings import InceptionResnetv1_MsCeleb_CenterLoss_2018 from bob.bio.face.embeddings.tf2_inception_resnet import (
InceptionResnetv1_MsCeleb_CenterLoss_2018,
)
np.random.seed(10) np.random.seed(10)
transformer = InceptionResnetv1_MsCeleb_CenterLoss_2018() transformer = InceptionResnetv1_MsCeleb_CenterLoss_2018()
...@@ -68,7 +72,9 @@ def test_idiap_inceptionv1_msceleb(): ...@@ -68,7 +72,9 @@ def test_idiap_inceptionv1_msceleb():
@is_library_available("tensorflow") @is_library_available("tensorflow")
def test_idiap_inceptionv1_casia(): def test_idiap_inceptionv1_casia():
from bob.bio.face.embeddings import InceptionResnetv1_Casia_CenterLoss_2018 from bob.bio.face.embeddings.tf2_inception_resnet import (
InceptionResnetv1_Casia_CenterLoss_2018,
)
np.random.seed(10) np.random.seed(10)
transformer = InceptionResnetv1_Casia_CenterLoss_2018() transformer = InceptionResnetv1_Casia_CenterLoss_2018()
...@@ -86,7 +92,9 @@ def test_idiap_inceptionv1_casia(): ...@@ -86,7 +92,9 @@ def test_idiap_inceptionv1_casia():
@is_library_available("tensorflow") @is_library_available("tensorflow")
def test_facenet_sanderberg(): def test_facenet_sanderberg():
from bob.bio.face.embeddings import FaceNetSanderberg_20170512_110547 from bob.bio.face.embeddings.tf2_inception_resnet import (
FaceNetSanderberg_20170512_110547,
)
np.random.seed(10) np.random.seed(10)
transformer = FaceNetSanderberg_20170512_110547() transformer = FaceNetSanderberg_20170512_110547()
...@@ -103,7 +111,7 @@ def test_facenet_sanderberg(): ...@@ -103,7 +111,7 @@ def test_facenet_sanderberg():
@is_library_available("mxnet") @is_library_available("mxnet")
def test_arcface_insight_face(): def test_arcface_insight_face():
from bob.bio.face.embeddings import ArcFaceInsightFace from bob.bio.face.embeddings.mxnet_models import ArcFaceInsightFace
transformer = ArcFaceInsightFace() transformer = ArcFaceInsightFace()
data = np.random.rand(3, 112, 112) * 255 data = np.random.rand(3, 112, 112) * 255
......
import bob.bio.base.test.utils import bob.bio.base.test.utils
import bob.bio.face import bob.bio.face
# TODO: Disabling this test until we have bob.bio.base#146
"""
def test_display_annotations(): def test_display_annotations():
from bob.bio.face.script.display_face_annotations import main from bob.bio.face.script.display_face_annotations import main
...@@ -8,3 +10,4 @@ def test_display_annotations(): ...@@ -8,3 +10,4 @@ def test_display_annotations():
with bob.bio.base.test.utils.Quiet(): with bob.bio.base.test.utils.Quiet():
parameters = ['-d', 'dummy', '-a', '/very/unlikely/directory', '--self-test'] parameters = ['-d', 'dummy', '-a', '/very/unlikely/directory', '--self-test']
main(parameters) main(parameters)
"""
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment