MCPcopy
hub / github.com/huggingface/diffusers / load_numpy

Function load_numpy

src/diffusers/utils/testing_utils.py:682–705  ·  view source on GitHub ↗
(arry: str | np.ndarray, local_path: str | None = None)

Source from the content-addressed store, hash-verified

680
681
682def load_numpy(arry: str | np.ndarray, local_path: str | None = None) -> np.ndarray:
683 if isinstance(arry, str):
684 if local_path is not None:
685 # local_path can be passed to correct images of tests
686 return Path(local_path, arry.split("/")[-5], arry.split("/")[-2], arry.split("/")[-1]).as_posix()
687 elif arry.startswith("http://") or arry.startswith("https://"):
688 response = requests.get(arry, timeout=DIFFUSERS_REQUEST_TIMEOUT)
689 response.raise_for_status()
690 arry = np.load(BytesIO(response.content))
691 elif os.path.isfile(arry):
692 arry = np.load(arry)
693 else:
694 raise ValueError(
695 f"Incorrect path or url, URLs must start with `http://` or `https://`, and {arry} is not a valid path"
696 )
697 elif isinstance(arry, np.ndarray):
698 pass
699 else:
700 raise ValueError(
701 "Incorrect format used for numpy ndarray. Should be an url linking to an image, a local path, or a"
702 " ndarray."
703 )
704
705 return arry
706
707
708def load_pt(url: str, map_location: str | None = None, weights_only: bool | None = True):

Callers 1

load_hf_numpyFunction · 0.70

Calls 3

splitMethod · 0.80
getMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…