{"record":{"id":"c2b0da5b9ba2a85f","repo":"lllyasviel/Fooocus","slug":"unknown-data-type-image-dtype","errorCode":null,"errorMessage":"Unknown data type: {image.dtype}","messagePattern":"Unknown data type: (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ldm_patched/contrib/external_canny.py","lineNumber":142,"sourceCode":"       color_conversions.html>`__.\n\n    Example:\n        >>> input = torch.rand(2, 3, 4, 5)\n        >>> gray = rgb_to_grayscale(input) # 2x1x4x5\n    \"\"\"\n\n    if len(image.shape) < 3 or image.shape[-3] != 3:\n        raise ValueError(f\"Input size must have a shape of (*, 3, H, W). Got {image.shape}\")\n\n    if rgb_weights is None:\n        # 8 bit images\n        if image.dtype == torch.uint8:\n            rgb_weights = torch.tensor([76, 150, 29], device=image.device, dtype=torch.uint8)\n        # floating point images\n        elif image.dtype in (torch.float16, torch.float32, torch.float64):\n            rgb_weights = torch.tensor([0.299, 0.587, 0.114], device=image.device, dtype=image.dtype)\n        else:\n            raise TypeError(f\"Unknown data type: {image.dtype}\")\n    else:\n        # is tensor that we make sure is in the same device/dtype\n        rgb_weights = rgb_weights.to(image)\n\n    # unpack the color image channels with RGB order\n    r: Tensor = image[..., 0:1, :, :]\n    g: Tensor = image[..., 1:2, :, :]\n    b: Tensor = image[..., 2:3, :, :]\n\n    w_r, w_g, w_b = rgb_weights.unbind()\n    return w_r * r + w_g * g + w_b * b\n\ndef canny(\n    input,\n    low_threshold = 0.1,\n    high_threshold = 0.2,\n    kernel_size  = 5,\n    sigma = 1,","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/lllyasviel/Fooocus/blob/ae05379cc97bc4361ec8b4ec90193dab21be763f/ldm_patched/contrib/external_canny.py#L124-L160","documentation":"Inside rgb_to_grayscale (vendored Kornia), when no explicit rgb_weights are given, the tensor dtype must be uint8 (8-bit path) or float16/32/64 (floating path). Any other dtype — typically torch.int, torch.long, torch.bfloat16, or bool — hits TypeError('Unknown data type'). The luminance weights tensor must match the image dtype for the weighted channel sum.","triggerScenarios":"Passing an image tensor of dtype torch.long/int32 (e.g. raw indices), torch.bool, or torch.bfloat16 into the Canny preprocessor chain without casting.","commonSituations":"Tensors created with torch.randint or from numpy int arrays; bfloat16 images from mixed-precision pipelines (some newer torch versions add bfloat16 paths that this vendored copy lacks); masks converted from bool surviving into the color path.","solutions":["Cast before calling: img = img.to(torch.float32) (values in [0,1]) or img.to(torch.uint8).","For numpy input, use img.astype(np.float32) or np.uint8 before torch.from_numpy.","If you need bfloat16 support, pass explicit rgb_weights = rgb_weights.to(image.dtype) matching your dtype, or patch the elif to include torch.bfloat16.","Normalize floats to [0,1] so the 0.299/0.587/0.114 weights produce sane luma."],"exampleFix":"# before\nimg = torch.from_numpy(np.array(pil_img))  # may be int64/other\ngrey = rgb_to_grayscale(img)  # TypeError\n\n# after\nimg = torch.from_numpy(np.array(pil_img)).to(torch.float32).div_(255.)\ngrey = rgb_to_grayscale(img)","handlingStrategy":"type-guard","validationCode":"SUPPORTED = (torch.uint8, torch.float16, torch.float32, torch.float64)\nif image.dtype not in SUPPORTED:\n    image = image.to(torch.float32)\nassert image.dtype in SUPPORTED","typeGuard":"def has_supported_img_dtype(t: torch.Tensor) -> bool:\n    return t.dtype in (torch.uint8, torch.float16, torch.float32, torch.float64)","tryCatchPattern":"try:\n    gray = rgb_to_grayscale(img)\nexcept TypeError as e:\n    if 'Unknown data type' in str(e):\n        gray = rgb_to_grayscale(img.to(torch.float32))\n    else:\n        raise","preventionTips":["Cast images to float32 in [0,1] (or uint8) at pipeline entry.","Never feed torch.long/bool/bfloat16 tensors into vendored Kornia color functions.","If using bfloat16 pipelines, convert to float32 before preprocessing nodes."],"tags":["kornia","dtype","canny","typeerror"],"backgroundTag":null,"analyzedSha":"ae05379cc97bc4361ec8b4ec90193dab21be763f","analyzedAt":"2026-08-15T04:23:59.533Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}