Commit 920d6019 authored by Tiago de Freitas Pereira's avatar Tiago de Freitas Pereira
Browse files

Rethinking baselines

parent 1697a446
Pipeline #40224 failed with stage
in 12 minutes and 31 seconds
import bob.bio.face
from sklearn.pipeline import make_pipeline
from bob.bio.base.wrappers import wrap_sample_preprocessor
from bob.pipelines import wrap
from bob.bio.face.transformers import FaceNetSanderberg
# This is the size of the image that this model expects
CROPPED_IMAGE_HEIGHT = 160
CROPPED_IMAGE_WIDTH = 160
# eye positions for frontal images
RIGHT_EYE_POS = (46, 53)
LEFT_EYE_POS = (46, 107)
legacy_face_cropper = bob.bio.face.preprocessor.FaceCrop(
cropped_image_size=(CROPPED_IMAGE_HEIGHT, CROPPED_IMAGE_WIDTH),
cropped_positions={"leye": LEFT_EYE_POS, "reye": RIGHT_EYE_POS},
color_channel="rgb",
)
embedding = FaceNetSanderberg()
transformer = make_pipeline(
wrap_sample_preprocessor(
legacy_face_cropper,
transform_extra_arguments=(("annotations", "annotations"),),
),
wrap(["sample"], embedding),
)
from bob.extension.config import load
import pkg_resources
import numpy as np
from bob.pipelines import Sample, SampleSet
def get_fake_sample(face_size=(160, 160), eyes={"leye": (46, 107), "reye": (46, 53)}):
data = np.random.rand(3,400,400)
annotations={"leye": (115, 267), "reye": (115, 132)}
return Sample(data, key="1", annotations=annotations)
def test_facenet_pipeline():
config_name = pkg_resources.resource_filename('bob.bio.face', 'config/transformers/eyes_crop/facenet.py')
transformer = load([config_name]).transformer
import ipdb; ipdb.set_trace()
fake_sample = get_fake_sample()
transformed_sample = transformer.transform([fake_sample])[0]
assert transformed_sample.data.size == 160
pass
\ No newline at end of file
......@@ -165,17 +165,25 @@ class FaceNetSanderberg(TransformerMixin, BaseEstimator):
logger.info("Successfully loaded the model.")
self.loaded = True
def transform(self, img):
images = self._check_feature(img)
if not self.loaded:
self.load_model()
feed_dict = {
self.images_placeholder: images,
self.phase_train_placeholder: False,
}
features = self.session.run(self.embeddings, feed_dict=feed_dict)
return features.flatten()
def transform(self, X):
def _transform(X):
import ipdb; ipdb.set_trace()
images = self._check_feature(X)
if not self.loaded:
self.load_model()
feed_dict = {
self.images_placeholder: images,
self.phase_train_placeholder: False,
}
features = self.session.run(self.embeddings, feed_dict=feed_dict)
return features.flatten()
if isinstance(X, list):
return [_transform(i) for i in X]
else:
return _transform(X)
@staticmethod
def get_modelpath():
......@@ -214,3 +222,9 @@ class FaceNetSanderberg(TransformerMixin, BaseEstimator):
d.pop("phase_train_placeholder") if "phase_train_placeholder" in d else None
tf.compat.v1.reset_default_graph()
return d
def _more_tags(self):
return {"stateless": True, "requires_fit": False}
def fit(self, X, y=None):
return self
......@@ -160,3 +160,11 @@ class TensorflowCompatV1(TransformerMixin, BaseEstimator):
bob.io.base.create_directories_safe(model_path)
zip_file = os.path.join(model_path, zip_file)
bob.extension.download.download_and_unzip(urls, zip_file)
def fit(self, X, y=None):
return self
def _more_tags(self):
return {"stateless": True, "requires_fit": False}
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