MCPcopy Create free account
hub / github.com/Chen-Yang-Liu/Text2Earth / load_numpy

Function load_numpy

src/diffusers/utils/testing_utils.py:401–424  ·  view source on GitHub ↗
(arry: Union[str, np.ndarray], local_path: Optional[str] = None)

Source from the content-addressed store, hash-verified

399
400
401def load_numpy(arry: Union[str, np.ndarray], local_path: Optional[str] = None) -> np.ndarray:
402 if isinstance(arry, str):
403 if local_path is not None:
404 # local_path can be passed to correct images of tests
405 return Path(local_path, arry.split("/")[-5], arry.split("/")[-2], arry.split("/")[-1]).as_posix()
406 elif arry.startswith("http://") or arry.startswith("https://"):
407 response = requests.get(arry)
408 response.raise_for_status()
409 arry = np.load(BytesIO(response.content))
410 elif os.path.isfile(arry):
411 arry = np.load(arry)
412 else:
413 raise ValueError(
414 f"Incorrect path or url, URLs must start with `http://` or `https://`, and {arry} is not a valid path"
415 )
416 elif isinstance(arry, np.ndarray):
417 pass
418 else:
419 raise ValueError(
420 "Incorrect format used for numpy ndarray. Should be an url linking to an image, a local path, or a"
421 " ndarray."
422 )
423
424 return arry
425
426
427def load_pt(url: str):

Calls

no outgoing calls

Tested by

no test coverage detected