deepfakes/faceswap · error · FaceswapError
Not enough RAM available to sort faces. Try reducing the siz
Error message
Not enough RAM available to sort faces. Try reducing the size of your dataset. Free RAM: {int(free_ram)}MB. Required RAM: {int(vector_required)}MB What it means
In identity-based face sorting, faceswap estimates RAM needed for linkage clustering vs. vector clustering. If even the cheaper vector method's requirement exceeds free system RAM, this FaceswapError aborts the sort rather than swapping the machine to death.
Source
Thrown at lib/infer/identity.py:574
divider = 1024 * 1024 # bytes to MB
free_ram = psutil.virtual_memory().available / divider
linkage_required = (((self._num_predictions ** 2) * np_float) / 1.8) / divider
vector_required = ((self._num_predictions * dims) * np_float) / divider
logger.debug("free_ram: %sMB, linkage_required: %sMB, vector_required: %sMB",
int(free_ram), int(linkage_required), int(vector_required))
if linkage_required < free_ram:
logger.verbose("Using linkage method") # type:ignore[attr-defined]
retval = False
elif vector_required < free_ram:
logger.warning("Not enough RAM to perform linkage clustering. Using vector "
"clustering. This will be significantly slower. Free RAM: %sMB. "
"Required for linkage method: %sMB",
int(free_ram), int(linkage_required))
retval = True
else:
raise FaceswapError("Not enough RAM available to sort faces. Try reducing "
f"the size of your dataset. Free RAM: {int(free_ram)}MB. "
f"Required RAM: {int(vector_required)}MB")
logger.debug(retval)
return retval
def _do_linkage(self,
predictions: np.ndarray,
method: T.Literal["single", "centroid", "median", "ward"]) -> np.ndarray:
"""Use FastCluster to perform vector or standard linkage
Parameters
----------
predictions
A stacked matrix of identity predictions of the shape (`N`, `D`) where `N` is the
number of observations and `D` are the number of dimensions.
method
The clustering method to use.
View on GitHub (pinned to f530cb7508)
Solutions
- Reduce the dataset size: split faces into subsets and sort each separately.
- Free RAM: close other applications, drop caches, increase container/pod memory limit.
- Move to a machine with more RAM for the final sort.
- Retry after freeing memory — free_ram is measured at runtime.
Example fix
# before
$ python tools.py sort -i /faces -t identity -o /sorted
# FaceswapError: Not enough RAM...
# after (split then sort)
$ split -n l/4 /faces /faces_part_
$ for d in /faces_part_*; do python tools.py sort -i $d -t identity -o ${d}_sorted; done Defensive patterns
Strategy: validation
Validate before calling
import psutil, math
free_ram_mib = psutil.virtual_memory().available >> 20
est_required_mib = (num_faces ** 2) * 8 >> 20 # vector method ~ N^2 float64
if est_required_mib > free_mib:
raise SystemExit('dataset too large for in-RAM sort; split it first') Try / catch
try:
sort_by_identity(faces)
except FaceswapError as err:
if 'Not enough RAM' in str(err):
for chunk in split(faces, n=4):
sort_by_identity(chunk)
else:
raise Prevention
- Estimate N^2 memory cost before sorting large face sets.
- Free page cache and close apps before identity sorting.
- Give containers a memory limit comfortably above the N^2 estimate.
When it happens
Trigger: Running sort by identity on a very large face set (hundreds of thousands of embeddings) on a machine with insufficient free RAM; free RAM already consumed by caches or other processes.
Common situations: Sorting massive extracted datasets on 8-16GB machines; running sort right after extraction while caches are full; container memory limits lower than host RAM.
Related errors
- Too many identities: {num_identities}. Max: {len(identities)
- Faceswap ran out of RAM running convert. Conversion is very
AI-assisted analysis of deepfakes/faceswap@f530cb7508 (2026-08-15).
Data as JSON: /api/errors/2aac6df0237e33ba.
Report an issue: GitHub.