mudler/LocalAI · error · RuntimeError
Antispoofer.predict called with no models loaded
Error message
Antispoofer.predict called with no models loaded
What it means
Raised by the insightface backend's Antispoofer.predict when inference is attempted while self._sessions is empty — no antispoofing ONNX models were loaded at construction time. It is a guard against a None/empty iteration that would otherwise return a zero-probability SpoofResult.
Source
Thrown at backend/python/insightface/engines.py:136
cx1 = max(0, int(cx - new_w / 2.0))
cy1 = max(0, int(cy - new_h / 2.0))
cx2 = min(src_w - 1, int(cx + new_w / 2.0))
cy2 = min(src_h - 1, int(cy + new_h / 2.0))
cropped = img[cy1 : cy2 + 1, cx1 : cx2 + 1]
if cropped.size == 0:
cropped = img
out_h, out_w = self.INPUT_SIZE
return cv2.resize(cropped, (out_w, out_h))
@staticmethod
def _softmax(x: np.ndarray) -> np.ndarray:
e = np.exp(x - np.max(x, axis=1, keepdims=True))
return e / e.sum(axis=1, keepdims=True)
def predict(self, img: np.ndarray, bbox: tuple[float, float, float, float]) -> SpoofResult:
if not self._sessions:
raise RuntimeError("Antispoofer.predict called with no models loaded")
accum = np.zeros((1, 3), dtype=np.float32)
for session, scale, input_name, output_name in self._sessions:
face = self._crop_face(img, bbox, scale).astype(np.float32)
tensor = np.transpose(face, (2, 0, 1))[np.newaxis, ...]
logits = session.run([output_name], {input_name: tensor})[0]
accum += self._softmax(logits)
accum /= float(len(self._sessions))
real_prob = float(accum[0, self.REAL_CLASS_IDX])
is_real = int(np.argmax(accum)) == self.REAL_CLASS_IDX and real_prob >= self.threshold
return SpoofResult(is_real=is_real, score=real_prob)
def _build_antispoofer(options: dict[str, str], model_dir: str | None) -> Antispoofer | None:
"""Instantiate an Antispoofer from option keys, or return None.
Recognised options:
antispoof_v2_onnx — path/filename of MiniFASNetV2 (scale 2.7)
antispoof_v1se_onnx — path/filename of MiniFASNetV1SE (scale 4.0)View on GitHub (pinned to 44413a9d06)
Solutions
- Install the antispoof model files (they ship with the insightface backend model packs; see the engine's model manifest).
- Check the Antispoofer construction logs for swallowed load errors and fix the underlying file/permission problem.
- If antispoofing is not desired, skip the predict() call (treat result as unknown) instead of invoking an unarmed spoffer.
- Reinstall the insightface pack: local-ai models install insightface-<pack>.
Defensive patterns
Strategy: type-guard
Validate before calling
spoof = _build_antispoofer(options, model_dir)
if spoof is not None and not spoof._sessions:
logger.warning("antispoof armed but no sessions; predict() will raise") Type guard
def antispoofer_armed(spoofer) -> bool:
return spoofer is not None and bool(getattr(spoofer, "_sessions", None)) Try / catch
try:
result = antispoofer.predict(img, bbox)
except RuntimeError as e:
if "no models loaded" in str(e):
logger.warning("antispoof unavailable; treating score as unknown")
result = None # caller marks liveness indeterminate
else:
raise Prevention
- Verify antispoof ONNX files exist right after installing the insightface pack.
- Fail engine construction loudly when antispoof models fail to load instead of leaving it unarmed.
- Gate predict() on a session-count check so unarmed spoofers report 'unknown' rather than raise.
When it happens
Trigger: Calling predict() on an Antispoofer instance whose _build_antispoofer step loaded zero ONNX sessions (model files missing at init) or after a failed model load was swallowed, then running face verification on an image with a detected face bbox.
Common situations: The MiniFASNet antispoof model files were not installed alongside the insightface pack, a permissions/corrupt-file issue at load time that left _sessions empty, or constructing the engine with antispoof intentionally disabled but still routing faces into predict.
Related errors
- no detector (taskname='detection') found in {pack_dir}
- onnx_direct engine requires both detector_onnx and recognize
- model snapshot does not exist: {model_ref}
- model snapshot must contain exactly one {suffix} file; found
- model_id is required to load a pipeline
AI-assisted analysis of mudler/LocalAI@44413a9d06 (2026-08-15).
Data as JSON: /api/errors/e52bd9a817c05331.
Report an issue: GitHub.