  
      def align_eyes(self, face, image):
          """ Re-extract a face with the pupils forced to be absolutely horizontally aligned """
          umeyama_landmarks = face.aligned_landmarks
          leftEyeCenter = umeyama_landmarks[42:48].mean(axis=0)
          rightEyeCenter = umeyama_landmarks[36:42].mean(axis=0)
          eyesCenter = umeyama_landmarks[36:48].mean(axis=0)
          dY = rightEyeCenter[1] - leftEyeCenter[1]
          dX = rightEyeCenter[0] - leftEyeCenter[0]
          theta = np.pi - np.arctan2(dY, dX)
          rot_cos = np.cos(theta)
          rot_sin = np.sin(theta)
          rotation_matrix = np.array([[rot_cos, -rot_sin, 0.],
                                      [rot_sin, rot_cos, 0.],
                                      [0., 0., 1.]])
 
</s> remove     def align_eyes(self, face, image):
 </s> add     @staticmethod
    def align_eyes(face, image): </s> remove         with open(statefile, "rb") as inp:
            state = self.serializer.unmarshal(inp.read().decode("utf-8"))
            trainer = state.get("name", None)
 </s> add         state = self.serializer.load(statefile)
        trainer = state.get("name", None) </s> remove                                   "{}_state.{}".format(self.model_name, serializer.ext))
        with open(state_file, "rb") as inp:
            state = serializer.unmarshal(inp.read().decode("utf-8"))
            session_names = ["session_{}".format(key)
                             for key in state["sessions"].keys()]
 </s> add                                   "{}_state.{}".format(self.model_name, serializer.file_extension))
        state = serializer.load(state_file)
        session_names = ["session_{}".format(key)
                         for key in state["sessions"].keys()] </s> remove         serializer = Serializer.get_serializer("json")
 </s> add         serializer = get_serializer("json") </s> remove         try:
            with open(self.filename, "rb") as inp:
                state = self.serializer.unmarshal(inp.read().decode("utf-8"))
                self.name = state.get("name", self.name)
                self.sessions = state.get("sessions", dict())
                self.lowest_avg_loss = state.get("lowest_avg_loss", dict())
                self.iterations = state.get("iterations", 0)
                self.training_size = state.get("training_size", 256)
                self.inputs = state.get("inputs", dict())
                self.config = state.get("config", dict())
                logger.debug("Loaded state: %s", state)
                self.replace_config(config_changeable_items)
        except IOError as err:
            logger.warning("No existing state file found. Generating.")
            logger.debug("IOError: %s", str(err))
        except JSONDecodeError as err:
            logger.debug("JSONDecodeError: %s:", str(err))
 </s> add         if not os.path.exists(self.filename):
            logger.info("No existing state file found. Generating.")
            return
        state = self.serializer.load(self.filename)
        self.name = state.get("name", self.name)
        self.sessions = state.get("sessions", dict())
        self.lowest_avg_loss = state.get("lowest_avg_loss", dict())
        self.iterations = state.get("iterations", 0)
        self.training_size = state.get("training_size", 256)
        self.inputs = state.get("inputs", dict())
        self.config = state.get("config", dict())
        logger.debug("Loaded state: %s", state)
        self.replace_config(config_changeable_items)
        left_eye_center = umeyama_landmarks[42:48].mean(axis=0)
        right_eye_center = umeyama_landmarks[36:42].mean(axis=0)
        d_y = right_eye_center[1] - left_eye_center[1]
        d_x = right_eye_center[0] - left_eye_center[0]
        theta = np.pi - np.arctan2(d_y, d_x)
  
      def align_eyes(self, face, image):
          """ Re-extract a face with the pupils forced to be absolutely horizontally aligned """
          umeyama_landmarks = face.aligned_landmarks
        left_eye_center = umeyama_landmarks[42:48].mean(axis=0)
        right_eye_center = umeyama_landmarks[36:42].mean(axis=0)
        d_y = right_eye_center[1] - left_eye_center[1]
        d_x = right_eye_center[0] - left_eye_center[0]
        theta = np.pi - np.arctan2(d_y, d_x)
        left_eye_center = umeyama_landmarks[42:48].mean(axis=0)
        right_eye_center = umeyama_landmarks[36:42].mean(axis=0)
        d_y = right_eye_center[1] - left_eye_center[1]
        d_x = right_eye_center[0] - left_eye_center[0]
        theta = np.pi - np.arctan2(d_y, d_x)
        left_eye_center = umeyama_landmarks[42:48].mean(axis=0)
        right_eye_center = umeyama_landmarks[36:42].mean(axis=0)
        d_y = right_eye_center[1] - left_eye_center[1]
        d_x = right_eye_center[0] - left_eye_center[0]
        theta = np.pi - np.arctan2(d_y, d_x)
        left_eye_center = umeyama_landmarks[42:48].mean(axis=0)
        right_eye_center = umeyama_landmarks[36:42].mean(axis=0)
        d_y = right_eye_center[1] - left_eye_center[1]
        d_x = right_eye_center[0] - left_eye_center[0]
        theta = np.pi - np.arctan2(d_y, d_x)
        left_eye_center = umeyama_landmarks[42:48].mean(axis=0)
        right_eye_center = umeyama_landmarks[36:42].mean(axis=0)
        d_y = right_eye_center[1] - left_eye_center[1]
        d_x = right_eye_center[0] - left_eye_center[0]
        theta = np.pi - np.arctan2(d_y, d_x)
        left_eye_center = umeyama_landmarks[42:48].mean(axis=0)
        right_eye_center = umeyama_landmarks[36:42].mean(axis=0)
        d_y = right_eye_center[1] - left_eye_center[1]
        d_x = right_eye_center[0] - left_eye_center[0]
        theta = np.pi - np.arctan2(d_y, d_x)
          rot_cos = np.cos(theta)
          rot_sin = np.sin(theta)
          rotation_matrix = np.array([[rot_cos, -rot_sin, 0.],
                                      [rot_sin, rot_cos, 0.],
                                      [0., 0., 1.]])
keep keep keep keep replace replace replace replace replace replace keep keep keep keep keep
 Standardize serialization (#903)

* Standardize serialization

- Linting
- Standardize serializer use throughout code
- Extend serializer to load and save files
- Always load and save in utf-8
- Create documentation 
tools/lib_alignments/media.py