deepfakes/faceswap · error · FaceswapError

Error unserializing data for type {type(serialized_data)}: {

Error message

Error unserializing data for type {type(serialized_data)}: {str(err)}

What it means

Serializer.unmarshal wraps ANY exception from the format-specific _unmarshal call: the stored bytes could not be decoded back to objects. Typical causes are JSONDecodeError (corrupt/truncated file, NaN handling), pickle UnpicklingError (protocol or class mismatch), or ValueError from newline-json parsing.

Source

Thrown at lib/serializer.py:170

            Data in serializer format that is to be unmarshalled to its original object

        Returns
        -------
        data: varies
            The data in a python object format

        Example
        ------
        >>> serializer = get_serializer('json')
        >>> json_data = <json object>
        >>> data = serializer.unmarshal(json_data)
        """
        logger.debug("data type: %s", type(serialized_data))
        try:
            retval = self._unmarshal(serialized_data)
        except Exception as err:
            msg = f"Error unserializing data for type {type(serialized_data)}: {str(err)}"
            raise FaceswapError(msg) from err
        logger.debug("returned data type: %s", type(retval))
        return retval

    def _marshal(self, data):
        """ Override for serializer specific marshalling """
        raise NotImplementedError()

    def _unmarshal(self, data):
        """ Override for serializer specific unmarshalling """
        raise NotImplementedError()


class _YAMLSerializer(Serializer):
    """ YAML Serializer """
    def __init__(self):
        super().__init__()
        self._file_extension = "yml"

View on GitHub (pinned to f530cb7508)

Solutions

  1. Inspect str(err) in the message — it identifies the parse failure precisely.
  2. Restore the file from a backup or regenerate it (e.g. re-extract alignments) if corrupt.
  3. For JSON with NaN, re-save with a compliant writer (allow_nan=False) or sanitize the file.
  4. Keep pickle data within the same code version that produced it, or migrate schemas.

Example fix

import json

# before
data = serializer.load('/state/train_state.json')  # JSONDecodeError -> FaceswapError

# after: guard and surface a clear message
try:
    data = serializer.load('/state/train_state.json')
except FaceswapError:
    raise SystemExit('state file corrupt; restore backup or re-run extraction')
Defensive patterns

Strategy: try-catch

Validate before calling

# cheap sanity check for JSON files
import os
size = os.path.getsize(filename)
assert size > 2, 'file too small to contain valid data'

Try / catch

try:
    data = serializer.load(filename)
except FaceswapError as err:
    if 'Error unserializing' in str(err):
        backup = filename + '.corrupt'
        os.replace(filename, backup)
        raise SystemExit(f'state corrupt, moved to {backup}; regenerate it')
    else:
        raise

Prevention

When it happens

Trigger: Loading a state file truncated by a crash mid-write; JSON containing NaN/Infinity (strict JSON parsers reject them); pickled data referencing classes that moved/renamed between faceswap versions.

Common situations: Hard-killed training jobs leaving partial files; hand-edited JSON with invalid syntax; loading old pickle state after refactors.

Related errors


AI-assisted analysis of deepfakes/faceswap@f530cb7508 (2026-08-15). Data as JSON: /api/errors/fdb536a86ca2810c. Report an issue: GitHub.