{"record":{"id":"1c45d54a0a762128","repo":"mlflow/mlflow","slug":"unsupported-image-object-type-type-image-ima","errorCode":null,"errorMessage":"Unsupported image object type: {type(image)}. `image` must be one of numpy.ndarray, PIL.Image.Image, and mlflow.Image.","messagePattern":"Unsupported image object type: (.+?)\\. `image` must be one of numpy\\.ndarray, PIL\\.Image\\.Image, and mlflow\\.Image\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"mlflow/tracking/client.py","lineNumber":3261,"sourceCode":"        elif artifact_file is None and key is None:\n            raise TypeError(\n                \"Invalid arguments: Please specify exactly one of `artifact_file` or `key`. Use \"\n                \"`key` to log dynamic image charts or `artifact_file` for saving static images. \"\n            )\n\n        import numpy as np\n\n        # Convert image type to PIL if its a numpy array\n        if isinstance(image, np.ndarray):\n            image = convert_to_pil_image(image)\n        elif isinstance(image, Image):\n            image = image.to_pil()\n        else:\n            # Import PIL and check if the image is a PIL image\n            import PIL.Image\n\n            if not isinstance(image, PIL.Image.Image):\n                raise TypeError(\n                    f\"Unsupported image object type: {type(image)}. \"\n                    \"`image` must be one of numpy.ndarray, \"\n                    \"PIL.Image.Image, and mlflow.Image.\"\n                )\n\n        if artifact_file is not None:\n            with self._log_artifact_helper(run_id, artifact_file) as tmp_path:\n                image.save(tmp_path)\n\n        elif key is not None:\n            # Check image key for invalid characters\n            if not re.match(r\"^[a-zA-Z0-9_\\-./ ]+$\", key):\n                raise ValueError(\n                    \"The `key` parameter may only contain alphanumerics, underscores (_), \"\n                    \"dashes (-), periods (.), spaces ( ), and slashes (/).\"\n                    f\"The provided key `{key}` contains invalid characters.\"\n                )\n","sourceCodeStart":3243,"sourceCodeEnd":3279,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/tracking/client.py#L3243-L3279","documentation":"log_image() accepts images only as numpy.ndarray, PIL.Image.Image, or mlflow.Image (which is converted to PIL internally). Any other object (e.g. matplotlib Figure, file path string, torch Tensor) fails the isinstance checks and raises a TypeError naming the received type.","triggerScenarios":"Passing a matplotlib.figure.Figure, a file path string, a torch/tensorflow tensor, an OpenCV image without converting, or any object that is not ndarray/PIL.Image/mlflow.Image to the `image` parameter.","commonSituations":"Plotting with matplotlib and passing the Figure directly instead of converting to an array; passing a local path string expecting the client to read it; framework tensors that were never converted with np.asarray or .numpy().","solutions":["Convert the object before logging: plt Figure -> fig.canvas buffer -> np.asarray, or save to a file and log with artifact_file.","Convert tensors with np.asarray(tensor) or tensor.numpy() before passing.","Wrap file paths yourself: Image.open(path) (PIL) then pass the PIL image.","If using mlflow.Image, ensure the object is actually an mlflow.Image instance, not a similarly named class."],"exampleFix":"// before\nfig, ax = plt.subplots()\nclient.log_image(run_id, fig, artifact_file=\"plot.png\")  # Figure unsupported\n// after\nfig.savefig(\"plot.png\")\nfrom PIL import Image\nclient.log_image(run_id, Image.open(\"plot.png\"), artifact_file=\"plot.png\")","handlingStrategy":"type-guard","validationCode":"import numpy as np\nimport PIL.Image\nimport mlflow\n\ndef is_loggable_image(image):\n    return isinstance(image, (np.ndarray, PIL.Image.Image, mlflow.Image))","typeGuard":"def is_loggable_image(image) -> bool:\n    import numpy as np, PIL.Image, mlflow\n    return isinstance(image, (np.ndarray, PIL.Image.Image, mlflow.Image))","tryCatchPattern":"try:\n    client.log_image(run_id, img, artifact_file=\"image.png\")\nexcept TypeError as e:\n    if \"Unsupported image object type\" in str(e):\n        img = np.asarray(img)  # or Image.open(path) / img.to_pil()\n        client.log_image(run_id, img, artifact_file=\"image.png\")\n    else:\n        raise","preventionTips":["Convert matplotlib Figures to arrays/PIL before logging","Convert framework tensors with np.asarray or .numpy()","Never pass file path strings; open them with PIL first"],"tags":["python","type-error","image","mlflow"],"backgroundTag":"unsupported-type","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}