deepfakes/faceswap · error · FaceswapError
The TFLambdaOp '{name}' is not supported
Error message
The TFLambdaOp '{name}' is not supported What it means
FaceswapError raised while converting a legacy Keras 2 model config to Keras 3: a TFLambdaOp layer is encountered whose operation (the last '.'-separated segment of its name) is not one of multiply, truediv, add, subtract. Those four are the only lambda ops the converter can map to Keras 3 ScalarOp layers. Anything else (e.g. custom tf functions) has no automatic equivalent.
Source
Thrown at plugins/train/model/_base/update.py:153
def _convert_lambda_config(self, layer: dict[str, T.Any]):
"""Keras 2 TFLambdaOps are not compatible with Keras 3. Scalar operations can be
relatively easily substituted with a :class:`~lib.model.layers.ScalarOp` layer
Parameters
----------
layer
An existing Keras 2 TFLambdaOp layer
Raises
------
FaceswapError
If the TFLambdaOp is not currently supported
"""
name = layer["config"]["name"]
operation = name.rsplit(".", maxsplit=1)[-1]
if operation not in ("multiply", "truediv", "add", "subtract"):
raise FaceswapError(f"The TFLambdaOp '{name}' is not supported")
value = layer["inbound_nodes"][0][-1]["y"]
if isinstance(layer["config"]["dtype"], str):
dtype = layer["config"]["dtype"]
else:
dtype = layer["config"]["dtype"]["config"]["name"]
new_layer = ScalarOp(operation, value, name=name, dtype=dtype)
logger.debug("Converting legacy TFLambdaOp: %s", layer)
layer["class_name"] = "ScalarOp"
layer["config"] = new_layer.get_config()
for n in layer["inbound_nodes"]:
n[-1] = {}
layer["inbound_nodes"] = [layer["inbound_nodes"]]
logger.debug("Converted legacy TFLambdaOp to %s", layer)
def _process_deprecations(self, layer: dict[str, T.Any]) -> None: # noqa[C901]View on GitHub (pinned to f530cb7508)
Solutions
- Check the layer name reported in the error to identify the unsupported operation
- Re-save/rebuild the model in Faceswap 2 using only the supported arithmetic lambda ops, then port
- If the op is one you added yourself, implement an equivalent ScalarOp mapping upstream in update.py before porting
Example fix
# before: legacy config layer named # 'model/tf.math.reduce_mean_3' -> raises (reduce_mean unsupported) # after: rebuild in FS2 using supported op, e.g. # 'model/tf.math.multiply_1' -> converts to ScalarOp
Defensive patterns
Strategy: try-catch
Validate before calling
import json
cfg = json.loads(config_str)
for layer in cfg["config"]["layers"]:
if layer["class_name"] == "TFLambdaOp":
op = layer["config"]["name"].rsplit(".", 1)[-1]
if op not in ("multiply", "truediv", "add", "subtract"):
raise SystemExit(f"Unsupported lambda op {op!r}; rebuild model with supported ops") Try / catch
from lib.exceptions import FaceswapError
try:
updater.port_model()
except FaceswapError as err:
if "TFLambdaOp" in str(err):
log_unportable_model(old_file) # record and skip, do not crash the batch
else:
raise Prevention
- Only port models produced by unmodified Faceswap releases
- Avoid custom lambda layers when creating models intended to be portable
When it happens
Trigger: Porting a Faceswap 2 model that contains an exotic TFLambdaOp layer, e.g. from a fork or plugin that added custom lambda operations to the graph. operation = name.rsplit('.', 1)[-1] fails the whitelist check.
Common situations: Porting models produced by modified Faceswap forks, very old versions, or models whose config was hand-edited to insert custom lambdas.
Related errors
- '{self._old_model_file}' is not a valid Faceswap 2 model fil
- Unable to load the model from '{self.filename}'. This may be
- Error loading weights file {self._weights_file}.
- The state file '{state_file}' does not exist. This model can
- Clip network could not be found in '{state_file}'. Discovere
AI-assisted analysis of deepfakes/faceswap@f530cb7508 (2026-08-15).
Data as JSON: /api/errors/f87fa197408dc849.
Report an issue: GitHub.