Skip to content
Snippets Groups Projects
Commit 20cce939 authored by Tiago de Freitas Pereira's avatar Tiago de Freitas Pereira
Browse files

Merge branch 'fix-legacy' into 'master'

Fixing the temp directory path for legacy algorithms IF checkpointing is off

Closes #39

See merge request !94
parents 1d4aca34 79e11f30
No related branches found
No related tags found
1 merge request!94Fixing the temp directory path for legacy algorithms IF checkpointing is off
Pipeline #47413 passed
...@@ -70,16 +70,9 @@ def get_pipeline(face_cropper, transform_extra_arguments): ...@@ -70,16 +70,9 @@ def get_pipeline(face_cropper, transform_extra_arguments):
) )
# Set default temporary directory # Set default temporary directory
default_temp = ( tempdir = bob.bio.base.pipelines.vanilla_biometrics.legacy.get_temp_directory(
os.path.join("/idiap", "temp", os.environ["USER"]) "gabor_graph"
if "USER" in os.environ
else "~/temp"
) )
if os.path.exists(default_temp):
tempdir = os.path.join(default_temp, "bob_bio_base_tmp")
else:
# if /idiap/temp/<USER> does not exist, use /tmp/tmpxxxxxxxx
tempdir = tempfile.TemporaryDirectory().name
algorithm = BioAlgorithmLegacy(gabor_jet, base_dir=tempdir) algorithm = BioAlgorithmLegacy(gabor_jet, base_dir=tempdir)
return VanillaBiometricsPipeline(transformer, algorithm) return VanillaBiometricsPipeline(transformer, algorithm)
......
...@@ -38,18 +38,10 @@ def load(annotation_type, fixed_positions=None): ...@@ -38,18 +38,10 @@ def load(annotation_type, fixed_positions=None):
face_cropper=face_cropper, dtype=np.float64 face_cropper=face_cropper, dtype=np.float64
) )
#### FEATURE EXTRACTOR ###### #### FEATURE EXTRACTOR ######
# Set default temporary directory # Set default temporary directory
user_env_var = os.getenv("USER", None) tempdir = bob.bio.base.pipelines.vanilla_biometrics.legacy.get_temp_directory("lda")
if user_env_var:
default_temp = os.path.join("/idiap","temp",user_env_var)
if user_env_var and os.path.exists(default_temp):
tempdir = os.path.join(default_temp, "bob_bio_base_tmp", "lda")
else:
# if /idiap/temp/<USER> does not exist, use /tmp/tmpxxxxxxxx
tempdir = tempfile.TemporaryDirectory().name
lda = bob.bio.base.algorithm.LDA(use_pinv=True, pca_subspace_dimension=0.90) lda = bob.bio.base.algorithm.LDA(use_pinv=True, pca_subspace_dimension=0.90)
...@@ -57,26 +49,25 @@ def load(annotation_type, fixed_positions=None): ...@@ -57,26 +49,25 @@ def load(annotation_type, fixed_positions=None):
lda, projector_file=os.path.join(tempdir, "Projector.hdf5") lda, projector_file=os.path.join(tempdir, "Projector.hdf5")
) )
transformer = make_pipeline( transformer = make_pipeline(
wrap( wrap(
["sample"], preprocessor, transform_extra_arguments=transform_extra_arguments, ["sample"],
preprocessor,
transform_extra_arguments=transform_extra_arguments,
), ),
SampleLinearize(), SampleLinearize(),
wrap(["sample"], lda_transformer), wrap(["sample"], lda_transformer),
) )
### BIOMETRIC ALGORITHM ### BIOMETRIC ALGORITHM
algorithm = BioAlgorithmLegacy( algorithm = BioAlgorithmLegacy(
lda, lda, base_dir=tempdir, projector_file=os.path.join(tempdir, "Projector.hdf5"),
base_dir=tempdir,
projector_file=os.path.join(tempdir, "Projector.hdf5"),
) )
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
...@@ -9,7 +9,6 @@ import numpy as np ...@@ -9,7 +9,6 @@ import numpy as np
import bob.bio.face import bob.bio.face
from sklearn.pipeline import make_pipeline from sklearn.pipeline import make_pipeline
from bob.pipelines import wrap from bob.pipelines import wrap
import tempfile
import bob.math import bob.math
...@@ -21,6 +20,7 @@ else: ...@@ -21,6 +20,7 @@ else:
annotation_type = None annotation_type = None
fixed_positions = None fixed_positions = None
def get_cropper(annotation_type, fixed_positions=None): def get_cropper(annotation_type, fixed_positions=None):
# Cropping # Cropping
face_cropper, transform_extra_arguments = crop_80x64( face_cropper, transform_extra_arguments = crop_80x64(
...@@ -28,6 +28,7 @@ def get_cropper(annotation_type, fixed_positions=None): ...@@ -28,6 +28,7 @@ def get_cropper(annotation_type, fixed_positions=None):
) )
return face_cropper, transform_extra_arguments return face_cropper, transform_extra_arguments
def get_pipeline(face_cropper, transform_extra_arguments): def get_pipeline(face_cropper, transform_extra_arguments):
preprocessor = bob.bio.face.preprocessor.TanTriggs( preprocessor = bob.bio.face.preprocessor.TanTriggs(
face_cropper=face_cropper, dtype=np.float64 face_cropper=face_cropper, dtype=np.float64
...@@ -37,40 +38,44 @@ def get_pipeline(face_cropper, transform_extra_arguments): ...@@ -37,40 +38,44 @@ def get_pipeline(face_cropper, transform_extra_arguments):
lgbphs = bob.bio.face.extractor.LGBPHS( lgbphs = bob.bio.face.extractor.LGBPHS(
# block setup # block setup
block_size = 8, block_size=8,
block_overlap = 0, block_overlap=0,
# Gabor parameters # Gabor parameters
gabor_sigma = math.sqrt(2.) * math.pi, gabor_sigma=math.sqrt(2.0) * math.pi,
# LBP setup (we use the defaults) # LBP setup (we use the defaults)
# histogram setup # histogram setup
sparse_histogram = True sparse_histogram=True,
) )
transformer = make_pipeline( transformer = make_pipeline(
wrap( wrap(
["sample"], preprocessor, transform_extra_arguments=transform_extra_arguments, ["sample"],
preprocessor,
transform_extra_arguments=transform_extra_arguments,
), ),
wrap(["sample"], lgbphs), wrap(["sample"], lgbphs),
) )
### BIOMETRIC ALGORITHM ### BIOMETRIC ALGORITHM
histogram = bob.bio.face.algorithm.Histogram( histogram = bob.bio.face.algorithm.Histogram(
distance_function = bob.math.histogram_intersection, distance_function=bob.math.histogram_intersection, is_distance_function=False
is_distance_function = False
) )
tempdir = bob.bio.base.pipelines.vanilla_biometrics.legacy.get_temp_directory(
tempdir = tempfile.TemporaryDirectory() "LGBPHS"
algorithm = BioAlgorithmLegacy(histogram, base_dir=tempdir.name) )
algorithm = BioAlgorithmLegacy(histogram, base_dir=tempdir)
return VanillaBiometricsPipeline(transformer, algorithm) return VanillaBiometricsPipeline(transformer, algorithm)
def load(annotation_type, fixed_positions=None): def load(annotation_type, fixed_positions=None):
####### SOLVING THE FACE CROPPER TO BE USED ########## ####### SOLVING THE FACE CROPPER TO BE USED ##########
face_cropper, transform_extra_arguments = get_cropper(annotation_type, fixed_positions) face_cropper, transform_extra_arguments = get_cropper(
annotation_type, fixed_positions
)
return get_pipeline(face_cropper, transform_extra_arguments) return get_pipeline(face_cropper, transform_extra_arguments)
pipeline = load(annotation_type, fixed_positions) pipeline = load(annotation_type, fixed_positions)
transformer = pipeline.transformer transformer = pipeline.transformer
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment