          logger.verbose("Restored Logs")
  
      def get_session_names(self):
          """ Get the existing session names from state file """
          serializer = Serializer.get_serializer("json")
          state_file = os.path.join(self.model_dir,
                                    "{}_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)
 
</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         try:
            with open(state_file, "rb") as inp:
                state = self.serializer.unmarshal(inp.read().decode("utf-8"))
                self.state = state
                logger.debug("Loaded state: %s", state)
        except IOError as err:
            logger.warning("Unable to load state file. Graphing disabled: %s", str(err))
 </s> add         self.state = self.serializer.load(state_file)
        logger.debug("Loaded state: %s", self.state) </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) </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         serializer = JSONSerializer
 </s> add         serializer = get_serializer("json")
        serializer = get_serializer("json")
          logger.verbose("Restored Logs")
  
      def get_session_names(self):
          """ Get the existing session names from state file """
        serializer = get_serializer("json")
          state_file = os.path.join(self.model_dir,
                                    "{}_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)
keep keep keep keep 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 
lib/model/backup_restore.py