INNER CODE UNIT · Python

savecache

DeepLabCut/DeepLabCut · deeplabcut/benchmark/__init__.py:106

def savecache(results: ResultCollection):
    with Path(CACHE).open("w") as fh:
        json.dump(results.todicts(), fh, indent=2)


def loadcache(cache=CACHE, on_missing: Literal["raise", "ignore"] = "ignore") -> ResultCollection:
    if not Path(cache).exists():
        if on_missing == "raise":
            raise FileNotFoundError(cache)
        return ResultCollection()
    with Path(cache).open() as fh:
        try:
            data = json.load(fh)
        except json.decoder.JSONDecodeError as e:
            if on_missing == "raise":
                raise e
            return ResultCollection()
    return ResultCollection.fromdicts(data)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…