ultralytics/yolov5 · error · NotImplementedError

ERROR: YOLOv5 TF.js inference is not supported

Error message

ERROR: YOLOv5 TF.js inference is not supported

What it means

DetectMultiBackend raises NotImplementedError for TF.js model bundles. The branch recognizes the tfjs format (a directory or .pb-based graph produced by tensorflowjs) but deliberately has no inference implementation, so loading a TF.js-exported YOLOv5 model for inference is rejected. Export to TF.js is supported; running inference on it in this repo is not.

Source

Thrown at models/common.py:639

            if edgetpu:  # TF Edge TPU https://coral.ai/software/#edgetpu-runtime
                LOGGER.info(f"Loading {w} for TensorFlow Lite Edge TPU inference...")
                delegate = {"Linux": "libedgetpu.so.1", "Darwin": "libedgetpu.1.dylib", "Windows": "edgetpu.dll"}[
                    platform.system()
                ]
                interpreter = Interpreter(model_path=w, experimental_delegates=[load_delegate(delegate)])
            else:  # TFLite
                LOGGER.info(f"Loading {w} for TensorFlow Lite inference...")
                interpreter = Interpreter(model_path=w)  # load TFLite model
            interpreter.allocate_tensors()  # allocate
            input_details = interpreter.get_input_details()  # inputs
            output_details = interpreter.get_output_details()  # outputs
            # load metadata
            with contextlib.suppress(zipfile.BadZipFile), zipfile.ZipFile(w, "r") as model:
                meta_file = model.namelist()[0]
                meta = ast.literal_eval(model.read(meta_file).decode("utf-8"))
                stride, names = int(meta["stride"]), meta["names"]
        elif tfjs:  # TF.js
            raise NotImplementedError("ERROR: YOLOv5 TF.js inference is not supported")
        # PaddlePaddle
        elif paddle:
            LOGGER.info(f"Loading {w} for PaddlePaddle inference...")
            check_requirements("paddlepaddle-gpu" if cuda else "paddlepaddle>=3.0.0")
            import paddle.inference as pdi

            w = Path(w)
            if w.is_dir():
                model_file = next(w.rglob("*.json"), None)
                params_file = next(w.rglob("*.pdiparams"), None)
            elif w.suffix == ".pdiparams":
                model_file = w.with_name("model.json")
                params_file = w
            else:
                raise ValueError(f"Invalid model path {w}. Provide model directory or a .pdiparams file.")

            if not (model_file and params_file and model_file.is_file() and params_file.is_file()):
                raise FileNotFoundError(f"Model files not found in {w}. Both .json and .pdiparams files are required.")

View on GitHub (pinned to 20d1d78a08)

Solutions

  1. Run TF.js inference where it is supported: in the browser via the exported web_model, or convert with tensorflowjs_converter and load in Node/browser.
  2. For local sanity checks, export and validate a TFLite or saved_model instead: python export.py --weights yolov5s.pt --include tflite.
  3. Compare outputs against the .pt or ONNX model rather than the tfjs bundle.

Example fix

# before
model = DetectMultiBackend('yolov5_web_model/')  # NotImplementedError

# after
# validate with tflite locally; deploy tfjs bundle in browser only
model = DetectMultiBackend('yolov5s-fp16.tflite')
Defensive patterns

Strategy: type-guard

Validate before calling

def is_tfjs_artifact(path: str) -> bool:
    """Detect the tfjs export shape that DetectMultiBackend rejects."""
    from pathlib import Path
    p = Path(path)
    return p.is_dir() and (p / 'model.json').exists() or str(path).endswith('.pb') and 'web_model' in str(path)

Type guard

SUPPORTED_SUFFIXES = ('.pt', '.torchscript', '.onnx', '.engine', '.tflite', '.pb', '.pdiparams')

def is_inferable_backend(path: str) -> bool:
    """False for tfjs bundles, which have no local inference path."""
    from pathlib import Path
    p = Path(path)
    if p.is_dir():
        return not (p / 'model.json').exists()  # tfjs dir shape
    return p.suffix in SUPPORTED_SUFFIXES

Try / catch

try:
    model = DetectMultiBackend(w)
except NotImplementedError as e:
    if 'TF.js' in str(e):
        raise SystemExit('tfjs is browser-only; validate with tflite instead') from e

Prevention

When it happens

Trigger: Calling DetectMultiBackend('yolov5_web_model/') (the directory produced by export.py --include tfjs) or otherwise passing a tfjs-format path; converting weights with tensorflow_converter and pointing val.py/detect.py at the result.

Common situations: Users export tfjs for browser deployment and then try to validate accuracy locally with val.py; CI pipelines that reuse one export artifact for every backend test.

Related errors


AI-assisted analysis of ultralytics/yolov5@20d1d78a08 (2026-08-15). Data as JSON: /api/errors/f488ef747d8c2e40. Report an issue: GitHub.