{"record":{"id":"a26567759e7feccd","repo":"lllyasviel/ControlNet","slug":"not-a-pfm-file","errorCode":null,"errorMessage":"Not a PFM file: ","messagePattern":"Not a PFM file: ","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"annotator/midas/utils.py","lineNumber":32,"sourceCode":"\n    Returns:\n        tuple: (data, scale)\n    \"\"\"\n    with open(path, \"rb\") as file:\n\n        color = None\n        width = None\n        height = None\n        scale = None\n        endian = None\n\n        header = file.readline().rstrip()\n        if header.decode(\"ascii\") == \"PF\":\n            color = True\n        elif header.decode(\"ascii\") == \"Pf\":\n            color = False\n        else:\n            raise Exception(\"Not a PFM file: \" + path)\n\n        dim_match = re.match(r\"^(\\d+)\\s(\\d+)\\s$\", file.readline().decode(\"ascii\"))\n        if dim_match:\n            width, height = list(map(int, dim_match.groups()))\n        else:\n            raise Exception(\"Malformed PFM header.\")\n\n        scale = float(file.readline().decode(\"ascii\").rstrip())\n        if scale < 0:\n            # little-endian\n            endian = \"<\"\n            scale = -scale\n        else:\n            # big-endian\n            endian = \">\"\n\n        data = np.fromfile(file, endian + \"f\")\n        shape = (height, width, 3) if color else (height, width)","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/lllyasviel/ControlNet/blob/ed85cd1e25a5ed592f7d8178495b4483de0331bf/annotator/midas/utils.py#L14-L50","documentation":"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.","triggerScenarios":"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.","commonSituations":"Depth-map datasets with mixed formats; URLs downloaded incorrectly (HTML instead of binary); preprocessing scripts pointing at wrong directories.","solutions":["Verify the file is genuinely PFM: open it and check the first line is 'PF' or 'Pf'","Check the path and confirm the file was downloaded/copied intact (not an error page or 0 bytes)","Convert your depth file to PFM first (e.g. with imageio or OpenEXR→PFM conversion)"],"exampleFix":"# before\nimg = read_pfn('/data/depth/0001.png')  # wrong format\n# after\nimport imageio\nimageio.imwrite('/data/depth/0001.pfm', depth)\nimg = read_pfm('/data/depth/0001.pfm')","handlingStrategy":"type-guard","validationCode":"def is_pfm(path):\n    with open(path, 'rb') as f:\n        return f.read(2) in (b'PF', b'Pf')\nassert is_pfm(path), 'not a PFM file'","typeGuard":"def is_pfm(path: str) -> bool:\n    try:\n        with open(path, 'rb') as f:\n            return f.readline().strip() in (b'PF', b'Pf')\n    except OSError:\n        return False","tryCatchPattern":"try:\n    img = read_pfm(path)\nexcept Exception as e:\n    if 'Not a PFM' in str(e):\n        img = fallback_loader(path)  # e.g. convert via imageio first\n    else:\n        raise","preventionTips":["Check magic bytes before parsing","Verify file sizes after download; reject tiny/HTML-looking files"],"tags":["midas","pfm","file-format","depth-map"],"backgroundTag":"invalid-file-format","analyzedSha":"ed85cd1e25a5ed592f7d8178495b4483de0331bf","analyzedAt":"2026-08-27T12:58:54.167Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}