Esempio n. 1
0
    def transform(self, X):
        """
        Convert  leye_x, leye_y, reye_x, reye_y attributes to `annotations = (leye, reye)`
        """

        annotated_samples = []
        for x in X:
            eyes = {
                "leye": (
                    float(find_attribute(x, "leye_y")),
                    float(find_attribute(x, "leye_x")),
                ),
                "reye": (
                    float(find_attribute(x, "reye_y")),
                    float(find_attribute(x, "reye_x")),
                ),
            }

            sample = DelayedSample.from_sample(x, annotations=eyes)
            [
                delattr(sample, a)
                for a in ["leye_x", "leye_y", "reye_x", "reye_y"]
            ]
            annotated_samples.append(sample)

        return annotated_samples
Esempio n. 2
0
    def transform(self, X):
        """
        Convert  leye_x, leye_y, reye_x, reye_y attributes to `annotations = (leye, reye)`
        """

        annotated_samples = []

        for x in X:
            annotations = {
                "leye": (
                    float(x.leye_y),
                    float(x.leye_x),
                ),
                "reye": (
                    float(x.reye_y),
                    float(x.reye_x),
                ),
                "nose": (
                    float(x.nose_y),
                    float(x.nose_x),
                ),
                "lmouth": (
                    float(x.lmouth_y),
                    float(x.lmouth_x),
                ),
                "rmouth": (
                    float(x.rmouth_y),
                    float(x.rmouth_x),
                ),
                "topleft": (
                    float(x.face_y),
                    float(x.face_x),
                ),
                "size": (
                    float(x.face_h),
                    float(x.face_w),
                ),
            }

            sample = DelayedSample.from_sample(x, annotations=annotations)
            # Cleaning up
            [
                delattr(sample, a) for a in [
                    "leye_x",
                    "leye_y",
                    "reye_x",
                    "reye_y",
                    "nose_y",
                    "nose_x",
                    "face_y",
                    "face_x",
                    "face_h",
                    "face_w",
                    "lmouth_y",
                    "lmouth_x",
                    "rmouth_y",
                    "rmouth_x",
                ]
            ]
            annotated_samples.append(sample)

        return annotated_samples
Esempio n. 3
0
    def transform(self, X):

        annotated_samples = []
        for x in X:
            annotations = dict()
            if (find_attribute(x, "leye_x") != ""
                    and find_attribute(x, "reye_x") != ""):
                # Normal profile
                annotations = {
                    "leye": (
                        float(find_attribute(x, "leye_y")),
                        float(find_attribute(x, "leye_x")),
                    ),
                    "reye": (
                        float(find_attribute(x, "reye_y")),
                        float(find_attribute(x, "reye_x")),
                    ),
                }
            elif (find_attribute(x, "leye_x") != ""
                  and find_attribute(x, "reye_x") == ""):
                # Left profile
                annotations = {
                    "leye": (
                        float(find_attribute(x, "leye_y")),
                        float(find_attribute(x, "leye_x")),
                    ),
                    "mouth": (
                        float(find_attribute(x, "mouthl_y")),
                        float(find_attribute(x, "mouthl_x")),
                    ),
                }
            elif (find_attribute(x, "leye_x") == ""
                  and find_attribute(x, "reye_x") != ""):
                # Right profile
                annotations = {
                    "reye": (
                        float(find_attribute(x, "reye_y")),
                        float(find_attribute(x, "reye_x")),
                    ),
                    "mouth": (
                        float(find_attribute(x, "mouthr_y")),
                        float(find_attribute(x, "mouthr_x")),
                    ),
                }
            else:
                raise ValueError("Annotations not available")

            sample = DelayedSample.from_sample(x, annotations=annotations)
            [
                delattr(sample, a) for a in [
                    "reye_x",
                    "reye_y",
                    "leye_x",
                    "leye_y",
                    "nose_x",
                    "nose_y",
                    "mouthr_x",
                    "mouthr_y",
                    "mouthl_x",
                    "mouthl_y",
                    "chin_x",
                    "chin_y",
                ]
            ]

            annotated_samples.append(sample)

        return annotated_samples