{"record":{"id":"ed0551bf784c7d9d","repo":"mlflow/mlflow","slug":"tensorflow-must-be-installed-if-you-want-to-load","errorCode":null,"errorMessage":"`tensorflow` must be installed if you want to load an exported Keras 3 model, please install `tensorflow` by `pip install tensorflow`.","messagePattern":"`tensorflow` must be installed if you want to load an exported Keras 3 model, please install `tensorflow` by `pip install tensorflow`\\.","errorType":"exception","errorClass":"MlflowException","httpStatus":null,"severity":"error","filePath":"mlflow/keras/load.py","lineNumber":60,"sourceCode":"            raise MlflowException(\n                f\"`data` must be one of: {[x.__name__ for x in supported_input_types]}, but \"\n                f\"received type: {type(data)}.\",\n                INVALID_PARAMETER_VALUE,\n            )\n        # Return numpy array for serving purposes.\n        return keras.ops.convert_to_numpy(model_call(data))\n\n\ndef _load_keras_model(path, model_conf, custom_objects=None, **load_model_kwargs):\n    save_exported_model = model_conf.flavors[\"keras\"].get(\"save_exported_model\")\n    model_path = os.path.join(path, model_conf.flavors[\"keras\"].get(\"data\", _MODEL_SAVE_PATH))\n    if os.path.isdir(model_path):\n        model_path = os.path.join(model_path, _MODEL_SAVE_PATH)\n    if save_exported_model:\n        try:\n            import tensorflow as tf\n        except ImportError:\n            raise MlflowException(\n                \"`tensorflow` must be installed if you want to load an exported Keras 3 model, \"\n                \"please install `tensorflow` by `pip install tensorflow`.\"\n            )\n        return tf.saved_model.load(model_path)\n    else:\n        model_path += \".keras\"\n        return keras.saving.load_model(\n            model_path,\n            custom_objects=custom_objects,\n            **load_model_kwargs,\n        )\n\n\ndef load_model(model_uri, dst_path=None, custom_objects=None, load_model_kwargs=None):\n    \"\"\"\n    Load Keras model from MLflow.\n\n    This method loads a saved Keras model from MLflow, and returns a Keras model instance.","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/keras/load.py#L42-L78","documentation":"When a Keras 3 model was saved with save_exported_model=True, it was exported as a TensorFlow SavedModel directory. Loading such a model via mlflow.keras.load_model or the pyfunc loader requires the `tensorflow` package to deserialize tf.saved_model.load; if tensorflow is not importable in the current environment, an MlflowException is raised with install instructions.","triggerScenarios":"Calling mlflow.keras.load_model(model_uri) (or serving via _load_pyfunc) on a logged Keras 3 model whose MLMODEL flavor metadata contains save_exported_model=True, in an environment where `import tensorflow` fails (tensorflow not installed or broken install).","commonSituations":"Deploying to a slim serving image that only has keras/torch deps and not full tensorflow; skinny client installs; loading a model logged on a machine with TF into a TF-free environment.","solutions":["Install TensorFlow in the current environment: pip install tensorflow","Or pip install 'mlflow[keras]' / the extra that pulls tensorflow","If you do not need the exported SavedModel, re-log the model with save_exported_model=False and load the .keras artifact instead"],"exampleFix":"// before\npip install mlflow\nmodel = mlflow.keras.load_model(\"runs:/abc/model\")\n// after\npip install mlflow tensorflow\nmodel = mlflow.keras.load_model(\"runs:/abc/model\")","handlingStrategy":"validation","validationCode":"import importlib.util\ndef ensure_tensorflow():\n    if importlib.util.find_spec(\"tensorflow\") is None:\n        raise RuntimeError(\"pip install tensorflow before loading this exported Keras 3 model\")","typeGuard":"def tensorflow_available() -> bool:\n    import importlib.util\n    return importlib.util.find_spec(\"tensorflow\") is not None","tryCatchPattern":"from mlflow.exceptions import MlflowException\ntry:\n    model = mlflow.keras.load_model(model_uri)\nexcept MlflowException as e:\n    import subprocess; subprocess.run([\"pip\", \"install\", \"tensorflow\"], check=True)\n    model = mlflow.keras.load_model(model_uri)","preventionTips":["Pin tensorflow in serving/deployment images when models use save_exported_model=True","Check MLMmodel flavor metadata for save_exported_model before choosing the runtime","Use 'pip install mlflow[keras]' to get matching deps"],"tags":["keras","tensorflow","missing-dependency","environment"],"backgroundTag":"missing-dependency","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}