{"record":{"id":"78ed0beaa266e37f","repo":"lllyasviel/Fooocus","slug":"cannot-process-this-value-as-an-image","errorCode":null,"errorMessage":"Cannot process this value as an Image","messagePattern":"Cannot process this value as an Image","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"modules/gradio_hijack.py","lineNumber":332,"sourceCode":"    def postprocess(\n        self, y: np.ndarray | _Image.Image | str | Path | None\n    ) -> str | None:\n        \"\"\"\n        Parameters:\n            y: image as a numpy array, PIL Image, string/Path filepath, or string URL\n        Returns:\n            base64 url data\n        \"\"\"\n        if y is None:\n            return None\n        if isinstance(y, np.ndarray):\n            return processing_utils.encode_array_to_base64(y)\n        elif isinstance(y, _Image.Image):\n            return processing_utils.encode_pil_to_base64(y)\n        elif isinstance(y, (str, Path)):\n            return client_utils.encode_url_or_file_to_base64(y)\n        else:\n            raise ValueError(\"Cannot process this value as an Image\")\n\n    def set_interpret_parameters(self, segments: int = 16):\n        \"\"\"\n        Calculates interpretation score of image subsections by splitting the image into subsections, then using a \"leave one out\" method to calculate the score of each subsection by whiting out the subsection and measuring the delta of the output value.\n        Parameters:\n            segments: Number of interpretation segments to split image into.\n        \"\"\"\n        self.interpretation_segments = segments\n        return self\n\n    def _segment_by_slic(self, x):\n        \"\"\"\n        Helper method that segments an image into superpixels using slic.\n        Parameters:\n            x: base64 representation of an image\n        \"\"\"\n        x = processing_utils.decode_base64_to_image(x)\n        if self.shape is not None:","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/lllyasviel/Fooocus/blob/ae05379cc97bc4361ec8b4ec90193dab21be763f/modules/gradio_hijack.py#L314-L350","documentation":"get_config()/serialize of the vendored gradio Image converts an example value y into base64 for the frontend; it accepts np.ndarray, PIL.Image, and str/Path (file or URL) and raises ValueError('Cannot process this value as an Image') for anything else. This typically fires when preparing example outputs for display, not during prediction.","triggerScenarios":"Passing examples=[...] or returning values containing bytes, a torch.Tensor, a list of images, or None-with-wrong-wrapper to the component's serialization path (e.g. examples=[[42]] or examples=[[tensor]]).","commonSituations":"Returning a torch.Tensor from a prediction function that feeds an Image output; examples referencing file-like objects instead of paths; numpy scalars or float arrays of unexpected shape.","solutions":["Convert tensors: img = tensor.mul(255).clamp(0,255).byte().cpu().numpy() (HWC) or wrap with PIL.Image.fromarray before returning/exemplifying.","Give examples as filesystem paths or URLs (str/Path), not raw bytes.","Ensure list-of-images goes to gr.Gallery, not Image."],"exampleFix":"# before\nreturn torch_tensor  # into gr.Image output\n# after\nreturn Image.fromarray(torch_tensor.mul(255).clamp(0,255).byte().cpu().numpy())","handlingStrategy":"type-guard","validationCode":"import numpy as np\nfrom PIL import Image\nfrom pathlib import Path\ndef to_image_value(v):\n    if isinstance(v, Image.Image) or isinstance(v, (str, Path)) or isinstance(v, np.ndarray):\n        return v\n    if hasattr(v, 'cpu'):  # torch tensor\n        return Image.fromarray(v.mul(255).clamp(0, 255).byte().cpu().numpy())\n    raise TypeError(f'not a serializable image value: {type(v)}')","typeGuard":"def is_image_value(v) -> bool:\n    import numpy as np\n    from PIL import Image as PILImage\n    from pathlib import Path\n    return isinstance(v, (np.ndarray, PILImage.Image, str, Path))","tryCatchPattern":null,"preventionTips":["Convert torch tensors to PIL/numpy in the prediction function's return path, not in the UI layer.","Give gr.Image examples as path strings; use gr.Gallery for lists of images."],"tags":["gradio","ui","serialization","type-mismatch","examples"],"backgroundTag":null,"analyzedSha":"ae05379cc97bc4361ec8b4ec90193dab21be763f","analyzedAt":"2026-08-15T04:23:59.533Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}