lllyasviel/ControlNet · error · Exception

Not a PFM file:

Error message

Not a PFM file: 

What it means

read_pfm reads a Portable Float Map file and validates the magic header: it must decode to 'PF' (color) or 'Pf' (greyscale). Anything else — including PNG/JPG/EXR files or text files — triggers this exception with the offending path appended.

Source

Thrown at annotator/midas/utils.py:32

    Returns:
        tuple: (data, scale)
    """
    with open(path, "rb") as file:

        color = None
        width = None
        height = None
        scale = None
        endian = None

        header = file.readline().rstrip()
        if header.decode("ascii") == "PF":
            color = True
        elif header.decode("ascii") == "Pf":
            color = False
        else:
            raise Exception("Not a PFM file: " + path)

        dim_match = re.match(r"^(\d+)\s(\d+)\s$", file.readline().decode("ascii"))
        if dim_match:
            width, height = list(map(int, dim_match.groups()))
        else:
            raise Exception("Malformed PFM header.")

        scale = float(file.readline().decode("ascii").rstrip())
        if scale < 0:
            # little-endian
            endian = "<"
            scale = -scale
        else:
            # big-endian
            endian = ">"

        data = np.fromfile(file, endian + "f")
        shape = (height, width, 3) if color else (height, width)

View on GitHub (pinned to ed85cd1e25)

Solutions

  1. Verify the file is genuinely PFM: open it and check the first line is 'PF' or 'Pf'
  2. Check the path and confirm the file was downloaded/copied intact (not an error page or 0 bytes)
  3. Convert your depth file to PFM first (e.g. with imageio or OpenEXR→PFM conversion)

Example fix

# before
img = read_pfn('/data/depth/0001.png')  # wrong format
# after
import imageio
imageio.imwrite('/data/depth/0001.pfm', depth)
img = read_pfm('/data/depth/0001.pfm')
Defensive patterns

Strategy: type-guard

Validate before calling

def is_pfm(path):
    with open(path, 'rb') as f:
        return f.read(2) in (b'PF', b'Pf')
assert is_pfm(path), 'not a PFM file'

Type guard

def is_pfm(path: str) -> bool:
    try:
        with open(path, 'rb') as f:
            return f.readline().strip() in (b'PF', b'Pf')
    except OSError:
        return False

Try / catch

try:
    img = read_pfm(path)
except Exception as e:
    if 'Not a PFM' in str(e):
        img = fallback_loader(path)  # e.g. convert via imageio first
    else:
        raise

Prevention

When it happens

Trigger: Calling annotator.midas.utils.read_pfm with a path to a file that is not a PFM: wrong extension, an HTML error page saved as .pfm, a binary depth file in another format, or a corrupted/truncated download.

Common situations: Depth-map datasets with mixed formats; URLs downloaded incorrectly (HTML instead of binary); preprocessing scripts pointing at wrong directories.

Related errors


AI-assisted analysis of lllyasviel/ControlNet@ed85cd1e25 (2026-08-27). Data as JSON: /api/errors/a26567759e7feccd. Report an issue: GitHub.