Commit 77e0ba63 authored by Tiago de Freitas Pereira's avatar Tiago de Freitas Pereira
Browse files

Reorganizing the baseline code

Reorganizing the baseline code
parent 6d9351d7
Pipeline #40579 failed with stage
in 4 minutes and 35 seconds
from bob.bio.face.embeddings import ArcFace_InsightFaceTF
from bob.bio.face.config.baseline.helpers import embedding_transformer_112x112
from bob.bio.base.pipelines.vanilla_biometrics import Distance, VanillaBiometricsPipeline
from bob.bio.base.pipelines.vanilla_biometrics import (
Distance,
VanillaBiometricsPipeline,
)
if "database" in locals():
......@@ -12,12 +14,14 @@ else:
fixed_positions = None
transformer = embedding_transformer_112x112(ArcFace_InsightFaceTF(), annotation_type, fixed_positions)
def load(annotation_type, fixed_positions=None):
transformer = embedding_transformer_112x112(
ArcFace_InsightFaceTF(), annotation_type, fixed_positions
)
algorithm = Distance()
algorithm = Distance()
pipeline = VanillaBiometricsPipeline(
transformer,
algorithm
)
return VanillaBiometricsPipeline(transformer, algorithm)
pipeline = load(annotation_type, fixed_positions)
transformer = pipeline.transformer
\ No newline at end of file
......@@ -14,10 +14,15 @@ else:
fixed_positions = None
transformer = embedding_transformer_160x160(
FaceNetSanderberg(), annotation_type, fixed_positions
)
def load(annotation_type, fixed_positions=None):
transformer = embedding_transformer_160x160(
FaceNetSanderberg(), annotation_type, fixed_positions
)
algorithm = Distance()
return VanillaBiometricsPipeline(transformer, algorithm)
algorithm = Distance()
pipeline = VanillaBiometricsPipeline(transformer, algorithm)
pipeline = load(annotation_type, fixed_positions)
transformer = pipeline.transformer
......@@ -20,49 +20,53 @@ else:
fixed_positions = None
####### SOLVING THE FACE CROPPER TO BE USED ##########
def load(annotation_type, fixed_positions=None):
####### SOLVING THE FACE CROPPER TO BE USED ##########
# Cropping
face_cropper, transform_extra_arguments = crop_80x64(
annotation_type, fixed_positions, color_channel="gray"
)
# Cropping
face_cropper, transform_extra_arguments = crop_80x64(
annotation_type, fixed_positions, color_channel="gray"
)
preprocessor = bob.bio.face.preprocessor.INormLBP(
face_cropper=face_cropper, dtype=np.float64
)
preprocessor = bob.bio.face.preprocessor.INormLBP(
face_cropper=face_cropper, dtype=np.float64
)
#### FEATURE EXTRACTOR ######
#### FEATURE EXTRACTOR ######
# legacy objects needs to be wrapped with legacy transformers
from bob.bio.base.transformers import ExtractorTransformer
# legacy objects needs to be wrapped with legacy transformers
from bob.bio.base.transformers import ExtractorTransformer
gabor_graph = ExtractorTransformer(
bob.bio.face.extractor.GridGraph(
# Gabor parameters
gabor_sigma=math.sqrt(2.0) * math.pi,
# what kind of information to extract
normalize_gabor_jets=True,
# setup of the fixed grid
node_distance=(8, 8),
gabor_graph = ExtractorTransformer(
bob.bio.face.extractor.GridGraph(
# Gabor parameters
gabor_sigma=math.sqrt(2.0) * math.pi,
# what kind of information to extract
normalize_gabor_jets=True,
# setup of the fixed grid
node_distance=(8, 8),
)
)
)
transformer = make_pipeline(
wrap(
["sample"], preprocessor, transform_extra_arguments=transform_extra_arguments,
),
wrap(["sample"], gabor_graph),
)
transformer = make_pipeline(
wrap(
["sample"], preprocessor, transform_extra_arguments=transform_extra_arguments,
),
wrap(["sample"], gabor_graph),
)
gabor_jet = bob.bio.face.algorithm.GaborJet(
gabor_jet_similarity_type="PhaseDiffPlusCanberra",
multiple_feature_scoring="max_jet",
gabor_sigma=math.sqrt(2.0) * math.pi,
)
gabor_jet = bob.bio.face.algorithm.GaborJet(
gabor_jet_similarity_type="PhaseDiffPlusCanberra",
multiple_feature_scoring="max_jet",
gabor_sigma=math.sqrt(2.0) * math.pi,
)
tempdir = tempfile.TemporaryDirectory()
algorithm = BioAlgorithmLegacy(gabor_jet, base_dir=tempdir.name)
tempdir = tempfile.TemporaryDirectory()
algorithm = BioAlgorithmLegacy(gabor_jet, base_dir=tempdir.name)
return VanillaBiometricsPipeline(transformer, algorithm)
pipeline = VanillaBiometricsPipeline(transformer, algorithm)
pipeline = load(annotation_type, fixed_positions)
transformer = pipeline.transformer
\ No newline at end of file
from bob.bio.face.embeddings import InceptionResnetv1_CasiaWebFace
from bob.bio.face.config.baseline.helpers import embedding_transformer_160x160
from bob.bio.base.pipelines.vanilla_biometrics import Distance, VanillaBiometricsPipeline
from bob.bio.base.pipelines.vanilla_biometrics import (
Distance,
VanillaBiometricsPipeline,
)
if "database" in locals():
......@@ -11,12 +13,14 @@ else:
annotation_type = None
fixed_positions = None
def load(annotation_type, fixed_positions=None):
transformer = embedding_transformer_160x160(
InceptionResnetv1_CasiaWebFace(), annotation_type, fixed_positions
)
transformer = embedding_transformer_160x160(InceptionResnetv1_CasiaWebFace(), annotation_type, fixed_positions)
algorithm = Distance()
algorithm = Distance()
return VanillaBiometricsPipeline(transformer, algorithm)
pipeline = VanillaBiometricsPipeline(
transformer,
algorithm
)
pipeline = load(annotation_type, fixed_positions)
transformer = pipeline.transformer
\ No newline at end of file
from bob.bio.face.embeddings import InceptionResnetv1_MsCeleb
from bob.bio.face.config.baseline.helpers import embedding_transformer_160x160
from bob.bio.base.pipelines.vanilla_biometrics import Distance, VanillaBiometricsPipeline
from bob.bio.base.pipelines.vanilla_biometrics import (
Distance,
VanillaBiometricsPipeline,
)
if "database" in locals():
......@@ -12,11 +14,15 @@ else:
fixed_positions = None
transformer = embedding_transformer_160x160(InceptionResnetv1_MsCeleb(), annotation_type, fixed_positions)
def load(annotation_type, fixed_positions=None):
transformer = embedding_transformer_160x160(
InceptionResnetv1_MsCeleb(), annotation_type, fixed_positions
)
algorithm = Distance()
algorithm = Distance()
pipeline = VanillaBiometricsPipeline(
transformer,
algorithm
)
return VanillaBiometricsPipeline(transformer, algorithm)
pipeline = load(annotation_type, fixed_positions)
transformer = pipeline.transformer
\ No newline at end of file
from bob.bio.face.embeddings import InceptionResnetv2_CasiaWebFace
from bob.bio.face.config.baseline.helpers import embedding_transformer_160x160
from bob.bio.base.pipelines.vanilla_biometrics import Distance, VanillaBiometricsPipeline
from bob.bio.base.pipelines.vanilla_biometrics import (
Distance,
VanillaBiometricsPipeline,
)
if "database" in locals():
......@@ -12,11 +14,15 @@ else:
fixed_positions = None
transformer = embedding_transformer_160x160(InceptionResnetv2_CasiaWebFace(), annotation_type, fixed_positions)
def load(annotation_type, fixed_positions=None):
transformer = embedding_transformer_160x160(
InceptionResnetv2_CasiaWebFace(), annotation_type, fixed_positions
)
algorithm = Distance()
algorithm = Distance()
pipeline = VanillaBiometricsPipeline(
transformer,
algorithm
)
return VanillaBiometricsPipeline(transformer, algorithm)
pipeline = load(annotation_type, fixed_positions)
transformer = pipeline.transformer
\ No newline at end of file
from bob.bio.face.embeddings import InceptionResnetv2_MsCeleb
from bob.bio.face.config.baseline.helpers import embedding_transformer_160x160
from bob.bio.base.pipelines.vanilla_biometrics import Distance, VanillaBiometricsPipeline
from bob.bio.base.pipelines.vanilla_biometrics import (
Distance,
VanillaBiometricsPipeline,
)
if "database" in locals():
......@@ -12,11 +14,15 @@ else:
fixed_positions = None
transformer = embedding_transformer_160x160(InceptionResnetv2_MsCeleb(), annotation_type, fixed_positions)
def load(annotation_type, fixed_positions=None):
transformer = embedding_transformer_160x160(
InceptionResnetv2_MsCeleb(), annotation_type, fixed_positions
)
algorithm = Distance()
algorithm = Distance()
pipeline = VanillaBiometricsPipeline(
transformer,
algorithm
)
return VanillaBiometricsPipeline(transformer, algorithm)
pipeline = load(annotation_type, fixed_positions)
transformer = pipeline.transformer
\ No newline at end of file
......@@ -23,42 +23,46 @@ else:
####### SOLVING THE FACE CROPPER TO BE USED ##########
def load(annotation_type, fixed_positions=None):
# Cropping
face_cropper, transform_extra_arguments = crop_80x64(
annotation_type, fixed_positions, color_channel="gray"
)
# Cropping
face_cropper, transform_extra_arguments = crop_80x64(
annotation_type, fixed_positions, color_channel="gray"
)
preprocessor = bob.bio.face.preprocessor.TanTriggs(
face_cropper=face_cropper, dtype=np.float64
)
preprocessor = bob.bio.face.preprocessor.TanTriggs(
face_cropper=face_cropper, dtype=np.float64
)
#### FEATURE EXTRACTOR ######
#### FEATURE EXTRACTOR ######
tempdir = tempfile.TemporaryDirectory()
lda = bob.bio.base.algorithm.LDA(use_pinv=True, pca_subspace_dimension=0.90)
tempdir = tempfile.TemporaryDirectory()
lda = bob.bio.base.algorithm.LDA(use_pinv=True, pca_subspace_dimension=0.90)
lda_transformer = AlgorithmTransformer(
lda, projector_file=os.path.join(tempdir.name, "Projector.hdf5")
)
lda_transformer = AlgorithmTransformer(
lda, projector_file=os.path.join(tempdir.name, "Projector.hdf5")
)
transformer = make_pipeline(
wrap(
["sample"], preprocessor, transform_extra_arguments=transform_extra_arguments,
),
SampleLinearize(),
wrap(["sample"], lda_transformer),
)
transformer = make_pipeline(
wrap(
["sample"], preprocessor, transform_extra_arguments=transform_extra_arguments,
),
SampleLinearize(),
wrap(["sample"], lda_transformer),
)
### BIOMETRIC ALGORITHM
### BIOMETRIC ALGORITHM
algorithm = BioAlgorithmLegacy(
lda,
base_dir=tempdir.name,
projector_file=os.path.join(tempdir.name, "Projector.hdf5"),
)
algorithm = BioAlgorithmLegacy(
lda,
base_dir=tempdir.name,
projector_file=os.path.join(tempdir.name, "Projector.hdf5"),
)
return VanillaBiometricsPipeline(transformer, algorithm)
pipeline = VanillaBiometricsPipeline(transformer, algorithm)
pipeline = load(annotation_type, fixed_positions)
transformer = pipeline.transformer
\ No newline at end of file
......@@ -22,49 +22,52 @@ else:
fixed_positions = None
####### SOLVING THE FACE CROPPER TO BE USED ##########
def load(annotation_type, fixed_positions=None):
####### SOLVING THE FACE CROPPER TO BE USED ##########
# Cropping
face_cropper, transform_extra_arguments = crop_80x64(
annotation_type, fixed_positions, color_channel="gray"
)
# Cropping
face_cropper, transform_extra_arguments = crop_80x64(
annotation_type, fixed_positions, color_channel="gray"
)
preprocessor = bob.bio.face.preprocessor.TanTriggs(
face_cropper=face_cropper, dtype=np.float64
)
preprocessor = bob.bio.face.preprocessor.TanTriggs(
face_cropper=face_cropper, dtype=np.float64
)
#### FEATURE EXTRACTOR ######
#### FEATURE EXTRACTOR ######
lgbphs = bob.bio.face.extractor.LGBPHS(
# block setup
block_size = 8,
block_overlap = 0,
# Gabor parameters
gabor_sigma = math.sqrt(2.) * math.pi,
# LBP setup (we use the defaults)
lgbphs = bob.bio.face.extractor.LGBPHS(
# block setup
block_size = 8,
block_overlap = 0,
# Gabor parameters
gabor_sigma = math.sqrt(2.) * math.pi,
# LBP setup (we use the defaults)
# histogram setup
sparse_histogram = True
)
# histogram setup
sparse_histogram = True
)
transformer = make_pipeline(
wrap(
["sample"], preprocessor, transform_extra_arguments=transform_extra_arguments,
),
wrap(["sample"], lgbphs),
)
transformer = make_pipeline(
wrap(
["sample"], preprocessor, transform_extra_arguments=transform_extra_arguments,
),
wrap(["sample"], lgbphs),
)
### BIOMETRIC ALGORITHM
histogram = bob.bio.face.algorithm.Histogram(
distance_function = bob.math.histogram_intersection,
is_distance_function = False
)
### BIOMETRIC ALGORITHM
histogram = bob.bio.face.algorithm.Histogram(
distance_function = bob.math.histogram_intersection,
is_distance_function = False
)
tempdir = tempfile.TemporaryDirectory()
algorithm = BioAlgorithmLegacy(histogram, base_dir=tempdir.name)
tempdir = tempfile.TemporaryDirectory()
algorithm = BioAlgorithmLegacy(histogram, base_dir=tempdir.name)
return VanillaBiometricsPipeline(transformer, algorithm)
pipeline = VanillaBiometricsPipeline(transformer, algorithm)
pipeline = load(annotation_type, fixed_positions)
transformer = pipeline.transformer
\ No newline at end of file
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