lllyasviel/Fooocus · error · ValueError
Unknown type: {self.type}. Please choose from: 'numpy', 'pil
Error message
Unknown type: {self.type}. Please choose from: 'numpy', 'pil', 'filepath'. What it means
postprocess() of the vendored gradio Image converts the model output back to a UI value according to self.type; only 'pil', 'numpy', and 'filepath' have branches, and anything else falls to else and raises ValueError. This is the runtime echo of the constructor's type check — it means self.type was changed after construction or bypassed it.
Source
Thrown at modules/gradio_hijack.py:253
def _format_image(
self, im: _Image.Image | None
) -> np.ndarray | _Image.Image | str | None:
"""Helper method to format an image based on self.type"""
if im is None:
return im
fmt = im.format
if self.type == "pil":
return im
elif self.type == "numpy":
return np.array(im)
elif self.type == "filepath":
path = self.pil_to_temp_file(
im, dir=self.DEFAULT_TEMP_DIR, format=fmt or "png"
)
self.temp_files.add(path)
return path
else:
raise ValueError(
"Unknown type: "
+ str(self.type)
+ ". Please choose from: 'numpy', 'pil', 'filepath'."
)
def preprocess(
self, x: str | dict[str, str]
) -> np.ndarray | _Image.Image | str | dict | None:
"""
Parameters:
x: base64 url data, or (if tool == "sketch") a dict of image and mask base64 url data
Returns:
image in requested format, or (if tool == "sketch") a dict of image and mask in requested format
"""
if x is None:
return x
mask = NoneView on GitHub (pinned to ae05379cc9)
Solutions
- Never assign to .type after construction — rebuild the component with the desired type.
- If you must support an extra format, subclass postprocess and add the branch before the else.
- Re-run the constructor validation invariant: keep self.type within {'numpy','pil','filepath'} at all times.
Example fix
# before img.type = 'tensor' # after img = Image(type='numpy') # rebuild with supported type
Defensive patterns
Strategy: type-guard
Validate before calling
assert img.type in ('numpy', 'pil', 'filepath'), f'Image.type corrupted: {img.type!r}' Type guard
def has_valid_image_type(component) -> bool:
return getattr(component, 'type', None) in ('numpy', 'pil', 'filepath') Prevention
- Never mutate .type post-construction; rebuild the component instead.
- If subclassing gr.Image, re-run the type validation in __init__.
When it happens
Trigger: Mutating img.type = 'tensor' (or 'cv2', 'str') on a live component between construction and the callback returning; subclassing and skipping __init__ validation; deserializing a saved component config with a foreign type.
Common situations: Custom tabs that dynamically reconfigure components; deepcopy/pickle round-trips of UI state that carry an old or edited type field.
Related errors
- Invalid value for parameter `type`: {type}. Please choose fr
- Invalid value for parameter `source`: {source}. Please choos
- Image streaming only available if source is 'webcam'.
- Cannot process this value as an Image
- Unsupported image type in input
AI-assisted analysis of lllyasviel/Fooocus@ae05379cc9 (2026-08-15).
Data as JSON: /api/errors/293753d1f488d609.
Report an issue: GitHub.