diff --git a/bob/bio/face/config/baseline/gabor_graph.py b/bob/bio/face/config/baseline/gabor_graph.py index 847ae7a93890176e33ac6814aa39c2bf9a80b629..1f1a786060b6041c2549ac55436e6e623be495bd 100644 --- a/bob/bio/face/config/baseline/gabor_graph.py +++ b/bob/bio/face/config/baseline/gabor_graph.py @@ -70,16 +70,9 @@ def get_pipeline(face_cropper, transform_extra_arguments): ) # Set default temporary directory - default_temp = ( - os.path.join("/idiap", "temp", os.environ["USER"]) - if "USER" in os.environ - else "~/temp" + tempdir = bob.bio.base.pipelines.vanilla_biometrics.legacy.get_temp_directory( + "gabor_graph" ) - 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) return VanillaBiometricsPipeline(transformer, algorithm) diff --git a/bob/bio/face/config/baseline/lda.py b/bob/bio/face/config/baseline/lda.py index 4c45fcc3815d716ca55a1dae74a9bfacb4f99357..1343f51a431ee7b97d0ca704c9ec910f57c1230d 100644 --- a/bob/bio/face/config/baseline/lda.py +++ b/bob/bio/face/config/baseline/lda.py @@ -38,18 +38,10 @@ def load(annotation_type, fixed_positions=None): face_cropper=face_cropper, dtype=np.float64 ) - #### FEATURE EXTRACTOR ###### # Set default temporary directory - user_env_var = os.getenv("USER", None) - 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 + tempdir = bob.bio.base.pipelines.vanilla_biometrics.legacy.get_temp_directory("lda") 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): lda, projector_file=os.path.join(tempdir, "Projector.hdf5") ) - transformer = make_pipeline( wrap( - ["sample"], preprocessor, transform_extra_arguments=transform_extra_arguments, + ["sample"], + preprocessor, + transform_extra_arguments=transform_extra_arguments, ), SampleLinearize(), wrap(["sample"], lda_transformer), ) - ### BIOMETRIC ALGORITHM algorithm = BioAlgorithmLegacy( - lda, - base_dir=tempdir, - projector_file=os.path.join(tempdir, "Projector.hdf5"), + lda, base_dir=tempdir, projector_file=os.path.join(tempdir, "Projector.hdf5"), ) return VanillaBiometricsPipeline(transformer, algorithm) + pipeline = load(annotation_type, fixed_positions) transformer = pipeline.transformer diff --git a/bob/bio/face/config/baseline/lgbphs.py b/bob/bio/face/config/baseline/lgbphs.py index 8b2ee18103d15d43ef515970888337d11c3242c6..eebcbba56258d6a85e792c4fb4e860be748e0269 100644 --- a/bob/bio/face/config/baseline/lgbphs.py +++ b/bob/bio/face/config/baseline/lgbphs.py @@ -9,7 +9,6 @@ import numpy as np import bob.bio.face from sklearn.pipeline import make_pipeline from bob.pipelines import wrap -import tempfile import bob.math @@ -21,6 +20,7 @@ else: annotation_type = None fixed_positions = None + def get_cropper(annotation_type, fixed_positions=None): # Cropping face_cropper, transform_extra_arguments = crop_80x64( @@ -28,6 +28,7 @@ def get_cropper(annotation_type, fixed_positions=None): ) return face_cropper, transform_extra_arguments + def get_pipeline(face_cropper, transform_extra_arguments): preprocessor = bob.bio.face.preprocessor.TanTriggs( face_cropper=face_cropper, dtype=np.float64 @@ -37,40 +38,44 @@ def get_pipeline(face_cropper, transform_extra_arguments): lgbphs = bob.bio.face.extractor.LGBPHS( # block setup - block_size = 8, - block_overlap = 0, + block_size=8, + block_overlap=0, # Gabor parameters - gabor_sigma = math.sqrt(2.) * math.pi, + gabor_sigma=math.sqrt(2.0) * math.pi, # LBP setup (we use the defaults) - # histogram setup - sparse_histogram = True + sparse_histogram=True, ) transformer = make_pipeline( wrap( - ["sample"], preprocessor, transform_extra_arguments=transform_extra_arguments, + ["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 + distance_function=bob.math.histogram_intersection, is_distance_function=False ) - - tempdir = tempfile.TemporaryDirectory() - algorithm = BioAlgorithmLegacy(histogram, base_dir=tempdir.name) + tempdir = bob.bio.base.pipelines.vanilla_biometrics.legacy.get_temp_directory( + "LGBPHS" + ) + algorithm = BioAlgorithmLegacy(histogram, base_dir=tempdir) return VanillaBiometricsPipeline(transformer, algorithm) + def load(annotation_type, fixed_positions=None): ####### 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) - + + pipeline = load(annotation_type, fixed_positions) -transformer = pipeline.transformer \ No newline at end of file +transformer = pipeline.transformer