diff --git a/bob/db/meds/database.py b/bob/db/meds/database.py index 44ce728ef5e0c5396256e23bde4b5fda007229dd..b976e637695278d9348693a8c8189f291f861e78 100644 --- a/bob/db/meds/database.py +++ b/bob/db/meds/database.py @@ -68,17 +68,7 @@ class Database: ) logger.debug(f"Reading '{subject_metadata_file}'.") - full_dataframe = pandas.read_csv(subject_metadata_file) - # Keep only these columns: - self.dataframe = full_dataframe[[ - "img_dname", # Directory name of the image - "img_name", # Image file name - "subject_id", # Unique int identifier for each subject - "subject_imgcount", # Image numerotation for each subject - "sex", # Gender of the subject - "rac", # Ethnicity of the subject - "label", # Pose label (Frontal, Profile, ...) - ]] + self.dataframe = pandas.read_csv(subject_metadata_file) logger.debug(f"Filtering protocol genders.") self.dataframe = self.dataframe[ @@ -248,8 +238,8 @@ class Database: return retval - def _annotations(self, image_name): - """Returns the coordinates of both eyes in the image of a sample + def _sample_annotations(self, image_name): + """Returns the coordinates of both eyes in the image of a sample. Note: eyes positions correspond to the point of view of the subject: @@ -270,11 +260,31 @@ class Database: { "leye":(y_pos,x_pos), "reye":(y_pos,x_pos) }. """ row = self.eyes_dataframe[self.eyes_dataframe.img_fname == image_name] - eyes = { + annotations = { "leye": (row.left_pupil_y.iloc[0], row.left_pupil_x.iloc[0]), "reye": (row.right_pupil_y.iloc[0], row.right_pupil_x.iloc[0]) } - return eyes + return annotations + + def _sample_gender(self, filename): + """Returns the gender of a given sample's subject.""" + return self.dataframe[self.dataframe.img_name == filename].sex.iloc[0] + + def _sample_ethnicity(self, filename): + """Returns the ethnicity of a given sample's subject.""" + return self.dataframe[self.dataframe.img_name == filename].rac.iloc[0] + + def _sample_height(self, filename): + """Returns the height of a subject in a given sample.""" + return self.dataframe[self.dataframe.img_name == filename].hgt.iloc[0] + + def _sample_weight(self, filename): + """Returns the weight of a subject in a given sample.""" + return self.dataframe[self.dataframe.img_name == filename].wgt.iloc[0] + + def _sample_pose(self, filename): + """Returns the facial pose of a subject in a sample.""" + return self.dataframe[self.dataframe.img_name == filename].label.iloc[0] def _subject_to_key(self, subject_id): """Transforms a subject ID to a unique int key @@ -357,7 +367,12 @@ class Database: ), key=path, subject=subject, - annotations=self._annotations(filename), + annotations=self._sample_annotations(filename), + gender=self._sample_gender(filename), + ethnicity=self._sample_ethnicity(filename), + height=self._sample_height(filename), + weight=self._sample_weight(filename), + pose=self._sample_pose(filename), ) ) return list(sets.values())